refactor: move logStdout/corsPolicy to Middleware

* remove configQuiet from Config

configQuiet was not an end user setting.
The logging setup is now an internal parameter.

* move proxy uri validation to Private dir
This commit is contained in:
steve-chavez
2020-07-13 11:30:16 -05:00
committed by Steve Chavez
parent 0ff05edd16
commit e272ea47be
10 changed files with 197 additions and 177 deletions
+3 -3
View File
@@ -15,7 +15,7 @@ import Test.Hspec
import PostgREST.App (postgrest)
import PostgREST.Config (AppConfig (..))
import PostgREST.DbStructure (getDbStructure, getPgVersion)
import PostgREST.Types (pgVersion95, pgVersion96)
import PostgREST.Types (LogSetup (..), pgVersion95, pgVersion96)
import Protolude hiding (toList, toS)
import Protolude.Conv (toS)
import SpecHelper
@@ -65,12 +65,12 @@ main = do
let
-- For tests that run with the same refDbStructure
app cfg = return ((), postgrest (cfg testDbConn) refDbStructure pool getTime $ pure ())
app cfg = return ((), postgrest LogQuiet (cfg testDbConn) refDbStructure pool getTime $ pure ())
-- For tests that run with a different DbStructure(depends on configSchemas)
appDbs cfg = do
dbs <- (newIORef . Just) =<< setupDbStructure pool (configSchemas $ cfg testDbConn) actualPgVersion
return ((), postgrest (cfg testDbConn) dbs pool getTime $ pure ())
return ((), postgrest LogQuiet (cfg testDbConn) dbs pool getTime $ pure ())
let withApp = app testCfg
maxRowsApp = app testMaxRowsCfg
+27 -31
View File
@@ -64,36 +64,32 @@ getEnvVarWithDefault var def = toS <$>
getEnv (toS var) `E.catchIOError` const (return $ toS def)
_baseCfg :: AppConfig
_baseCfg = -- Connection Settings
let secret = Just $ encodeUtf8 "reallyreallyreallyreallyverysafe" in
AppConfig mempty "postgrest_test_anonymous" Nothing (fromList ["test"]) "localhost" 3000
-- No user configured Unix Socket
Nothing
-- No user configured Unix Socket file mode (defaults to 660)
(Right 432)
-- db-channel
"pgrst"
-- db-channel-enabled
False
-- Jwt settings
secret False Nothing
-- Connection Modifiers
10 10 Nothing (Just "test.switch_role")
-- Debug Settings
True
[ ("app.settings.app_host", "localhost")
, ("app.settings.external_api_secret", "0123456789abcdef")
]
-- Default role claim key
(Right [JSPKey "role"])
-- Empty db-extra-search-path
[]
-- No root spec override
Nothing
-- Raw output media types
[]
-- Config JWK
(parseSecret <$> secret)
_baseCfg = let secret = Just $ encodeUtf8 "reallyreallyreallyreallyverysafe" in
AppConfig {
configDbUri = mempty
, configAnonRole = "postgrest_test_anonymous"
, configOpenAPIProxyUri = Nothing
, configSchemas = fromList ["test"]
, configHost = "localhost"
, configPort = 3000
, configSocket = Nothing
, configSocketMode = Right 432
, configDbChannel = mempty
, configDbChannelEnabled = False
, configJwtSecret = secret
, configJwtSecretIsBase64 = False
, configJwtAudience = Nothing
, configPoolSize = 10
, configPoolTimeout = 10
, configMaxRows = Nothing
, configPreReq = Just "test.switch_role"
, configSettings = [ ("app.settings.app_host", "localhost") , ("app.settings.external_api_secret", "0123456789abcdef") ]
, configRoleClaimKey = Right [JSPKey "role"]
, configExtraSearchPath = []
, configRootSpec = Nothing
, configRawMediaTypes = []
, configJWKS = parseSecret <$> secret
}
testCfg :: Text -> AppConfig
testCfg testDbConn = _baseCfg { configDbUri = testDbConn }
@@ -156,7 +152,7 @@ testCfgHtmlRawOutput :: Text -> AppConfig
testCfgHtmlRawOutput testDbConn = (testCfg testDbConn) { configRawMediaTypes = ["text/html"] }
testCfgResponseHeaders :: Text -> AppConfig
testCfgResponseHeaders testDbConn = (testCfg testDbConn) { configReqCheck = Just "custom_headers" }
testCfgResponseHeaders testDbConn = (testCfg testDbConn) { configPreReq = Just "custom_headers" }
testMultipleSchemaCfg :: Text -> AppConfig
testMultipleSchemaCfg testDbConn = (testCfg testDbConn) { configSchemas = fromList ["v1", "v2"] }