feat: add handling=strict/lenient for Prefer header
This commit is contained in:
committed by
Steve Chavez
parent
2825ac059e
commit
3c1cdd434a
+4
-4
@@ -1182,9 +1182,9 @@ def test_server_timing_jwt_should_not_decrease_when_caching_disabled(defaultenv)
|
||||
first_dur = float(first_dur_text[8:]) # skip "jwt;dur="
|
||||
second_dur = float(second_dur_text[8:])
|
||||
|
||||
# their difference should be less than 100
|
||||
# their difference should be less than 150
|
||||
# implying that token is not cached
|
||||
assert (first_dur - second_dur) < 100.0
|
||||
assert (first_dur - second_dur) < 150.0
|
||||
|
||||
|
||||
def test_jwt_cache_with_no_exp_claim(defaultenv):
|
||||
@@ -1211,6 +1211,6 @@ def test_jwt_cache_with_no_exp_claim(defaultenv):
|
||||
first_dur = float(first_dur_text[8:]) # skip "jwt;dur="
|
||||
second_dur = float(second_dur_text[8:])
|
||||
|
||||
# their difference should be less than 100
|
||||
# implying that token is not cached
|
||||
# their difference should be atleast 300, implying
|
||||
# that JWT Caching is working as expected
|
||||
assert (first_dur - second_dur) > 300.0
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
module Feature.Query.PreferencesSpec where
|
||||
|
||||
import Network.Wai (Application)
|
||||
|
||||
import Network.HTTP.Types
|
||||
import Test.Hspec
|
||||
import Test.Hspec.Wai
|
||||
import Test.Hspec.Wai.JSON
|
||||
|
||||
import Protolude hiding (get)
|
||||
import SpecHelper
|
||||
|
||||
spec :: SpecWith ((), Application)
|
||||
spec =
|
||||
describe "check prefer: handling=strict and handling=lenient" $ do
|
||||
|
||||
context "check behaviour of Prefer: handling=strict" $ do
|
||||
it "throws error when handling=strict and invalid prefs are given" $
|
||||
request methodGet "/items" [("Prefer", "handling=strict, anything")] ""
|
||||
`shouldRespondWith`
|
||||
[json|{"details":"Invalid preferences: anything","message":"Invalid preferences given with handling=strict","code":"PGRST122","hint":null}|]
|
||||
{ matchStatus = 400 }
|
||||
|
||||
it "throw error when handling=strict and invalid prefs are given with multiples in separate prefers" $
|
||||
request methodGet "/items" [("Prefer", "handling=strict"),("Prefer","something, else")] ""
|
||||
`shouldRespondWith`
|
||||
[json|{"details":"Invalid preferences: something, else","message":"Invalid preferences given with handling=strict","code":"PGRST122","hint":null}|]
|
||||
{ matchStatus = 400 }
|
||||
|
||||
it "throws error with post request" $
|
||||
request methodPost "/organizations?select=*"
|
||||
[("Prefer","return=representation, handling=strict, anything")]
|
||||
[json|{"id":7,"name":"John","referee":null,"auditor":null,"manager_id":6}|]
|
||||
`shouldRespondWith`
|
||||
[json|{"details":"Invalid preferences: anything","message":"Invalid preferences given with handling=strict","code":"PGRST122","hint":null}|]
|
||||
{ matchStatus = 400 }
|
||||
|
||||
it "throws error with rpc" $
|
||||
request methodPost "/rpc/overloaded_unnamed_param"
|
||||
[("Content-Type", "application/json"), ("Prefer", "handling=strict, anything")]
|
||||
[json|{}|]
|
||||
`shouldRespondWith`
|
||||
[json|{"details":"Invalid preferences: anything","message":"Invalid preferences given with handling=strict","code":"PGRST122","hint":null}|]
|
||||
{ matchStatus = 400 }
|
||||
|
||||
context "check behaviour of Prefer: handling=lenient" $ do
|
||||
it "does not throw error when handling=lenient and invalid prefs" $
|
||||
request methodGet "/items" [("Prefer", "handling=lenient, anything")] ""
|
||||
`shouldRespondWith` 200
|
||||
|
||||
it "does not throw error when handling=lenient and invalid prefs in multiples prefers" $
|
||||
request methodGet "/items" [("Prefer", "handling=lenient"), ("Prefer", "anything")] ""
|
||||
`shouldRespondWith` 200
|
||||
|
||||
it "does not throw error with post request" $
|
||||
request methodPost "/organizations?select=*"
|
||||
[("Prefer","return=representation, handling=lenient, anything")]
|
||||
[json|{"id":7,"name":"John","referee":null,"auditor":null,"manager_id":6}|]
|
||||
`shouldRespondWith`
|
||||
[json|[{"id":7,"name":"John","referee":null,"auditor":null,"manager_id":6}]|]
|
||||
{ matchStatus = 201
|
||||
, matchHeaders = [ matchContentTypeJson ]
|
||||
}
|
||||
|
||||
it "does not throw error with rpc" $
|
||||
request methodPost "/rpc/overloaded_unnamed_param"
|
||||
[("Content-Type", "application/json"), ("Prefer", "handling=lenient, anything")]
|
||||
[json|{}|]
|
||||
`shouldRespondWith`
|
||||
[json| 1 |]
|
||||
{ matchStatus = 200
|
||||
, matchHeaders = [matchContentTypeJson]
|
||||
}
|
||||
@@ -49,6 +49,7 @@ import qualified Feature.Query.NullsStripSpec
|
||||
import qualified Feature.Query.PgSafeUpdateSpec
|
||||
import qualified Feature.Query.PlanSpec
|
||||
import qualified Feature.Query.PostGISSpec
|
||||
import qualified Feature.Query.PreferencesSpec
|
||||
import qualified Feature.Query.QueryLimitedSpec
|
||||
import qualified Feature.Query.QuerySpec
|
||||
import qualified Feature.Query.RangeSpec
|
||||
@@ -138,6 +139,7 @@ main = do
|
||||
, ("Feature.OptionsSpec" , Feature.OptionsSpec.spec actualPgVersion)
|
||||
, ("Feature.Query.PgSafeUpdateSpec.disabledSpec" , Feature.Query.PgSafeUpdateSpec.disabledSpec)
|
||||
, ("Feature.Query.PlanSpec.disabledSpec" , Feature.Query.PlanSpec.disabledSpec)
|
||||
, ("Feature.Query.PreferencesSpec" , Feature.Query.PreferencesSpec.spec)
|
||||
, ("Feature.Query.QuerySpec" , Feature.Query.QuerySpec.spec actualPgVersion)
|
||||
, ("Feature.Query.RawOutputTypesSpec" , Feature.Query.RawOutputTypesSpec.spec)
|
||||
, ("Feature.Query.RpcSpec" , Feature.Query.RpcSpec.spec actualPgVersion)
|
||||
|
||||
Reference in New Issue
Block a user