diff --git a/src/PostgREST/Middleware.hs b/src/PostgREST/Middleware.hs index e302388ce2..9dc3123a85 100644 --- a/src/PostgREST/Middleware.hs +++ b/src/PostgREST/Middleware.hs @@ -89,6 +89,13 @@ runPgLocals conf claims app req jsonDbS actualPgVersion = do _ -> mempty usesLegacyGucs = configDbUseLegacyGucs conf && actualPgVersion < pgVersion140 + unquoted :: JSON.Value -> Text + unquoted (JSON.String t) = t + unquoted (JSON.Number n) = + toS $ formatScientific Fixed (if isInteger n then Just 0 else Nothing) n + unquoted (JSON.Bool b) = show b + unquoted v = T.decodeUtf8 . LBS.toStrict $ JSON.encode v + -- | Log in apache format. Only requests that have a status greater than minStatus are logged. -- | There's no way to filter logs in the apache format on wai-extra: https://hackage.haskell.org/package/wai-extra-3.0.29.2/docs/Network-Wai-Middleware-RequestLogger.html#t:OutputFormat. -- | So here we copy wai-logger apacheLogStr function: https://github.com/kazu-yamamoto/logger/blob/a4f51b909a099c51af7a3f75cf16e19a06f9e257/wai-logger/Network/Wai/Logger/Apache.hs#L45 @@ -153,13 +160,6 @@ corsPolicy req = case lookup "origin" headers of Just hdrs -> map (CI.mk . BS.strip) $ BS.split ',' hdrs Nothing -> [] -unquoted :: JSON.Value -> Text -unquoted (JSON.String t) = t -unquoted (JSON.Number n) = - toS $ formatScientific Fixed (if isInteger n then Just 0 else Nothing) n -unquoted (JSON.Bool b) = show b -unquoted v = T.decodeUtf8 . LBS.toStrict $ JSON.encode v - -- | Set a transaction to eventually roll back if requested and set respective -- headers on the response. optionalRollback diff --git a/test/io-tests/fixtures.yaml b/test/io-tests/fixtures.yaml index 7db1771f58..d13010aea1 100644 --- a/test/io-tests/fixtures.yaml +++ b/test/io-tests/fixtures.yaml @@ -144,6 +144,7 @@ roleclaims: data: postgrest: a_role: postgrest_test_author + other: claims expected_status: 200 - key: '.customObject.manyRoles[1]' data: @@ -151,21 +152,25 @@ roleclaims: manyRoles: - other - postgrest_test_author + other: {} expected_status: 200 - key: '."https://www.example.com/roles"[0].value' data: 'https://www.example.com/roles': - value: postgrest_test_author + other: 666 expected_status: 200 - key: '.myDomain[3]' data: myDomain: - other - postgrest_test_author + other: 1.23 expected_status: 401 - key: '.myRole' data: role: postgrest_test_author + other: true expected_status: 401 invalidroleclaimkeys: