fix: Return 405 Method Not Allowed for unsupported verbs
Signed-off-by: Wolfgang Walther <walther@technowledgy.de>
This commit is contained in:
committed by
Wolfgang Walther
parent
8980b09419
commit
58f76f3d6d
@@ -0,0 +1,44 @@
|
||||
module Feature.Query.ErrorSpec 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)
|
||||
|
||||
spec :: SpecWith ((), Application)
|
||||
spec = do
|
||||
describe "Non existent api schema" $ do
|
||||
it "succeeds when requesting root path" $
|
||||
get "/" `shouldRespondWith` 200
|
||||
|
||||
it "gives 404 when requesting a nonexistent table in this nonexistent schema" $
|
||||
get "/nonexistent_table" `shouldRespondWith` 404
|
||||
|
||||
describe "Unsupported HTTP methods" $ do
|
||||
it "should return 405 for CONNECT method" $
|
||||
request methodConnect "/"
|
||||
[]
|
||||
""
|
||||
`shouldRespondWith`
|
||||
[json|{"message":"Unsupported HTTP verb: CONNECT"}|]
|
||||
{ matchStatus = 405 }
|
||||
|
||||
it "should return 405 for TRACE method" $
|
||||
request methodTrace "/"
|
||||
[]
|
||||
""
|
||||
`shouldRespondWith`
|
||||
[json|{"message":"Unsupported HTTP verb: TRACE"}|]
|
||||
{ matchStatus = 405 }
|
||||
|
||||
it "should return 405 for OTHER method" $
|
||||
request "OTHER" "/"
|
||||
[]
|
||||
""
|
||||
`shouldRespondWith`
|
||||
[json|{"message":"Unsupported HTTP verb: OTHER"}|]
|
||||
{ matchStatus = 405 }
|
||||
@@ -1,17 +0,0 @@
|
||||
module Feature.Query.NonexistentSchemaSpec where
|
||||
|
||||
import Network.Wai (Application)
|
||||
|
||||
import Test.Hspec
|
||||
import Test.Hspec.Wai
|
||||
|
||||
import Protolude hiding (get)
|
||||
|
||||
spec :: SpecWith ((), Application)
|
||||
spec =
|
||||
describe "Non existent api schema" $ do
|
||||
it "succeeds when requesting root path" $
|
||||
get "/" `shouldRespondWith` 200
|
||||
|
||||
it "gives 404 when requesting a nonexistent table in this nonexistent schema" $
|
||||
get "/nonexistent_table" `shouldRespondWith` 404
|
||||
+2
-2
@@ -39,11 +39,11 @@ import qualified Feature.Query.AndOrParamsSpec
|
||||
import qualified Feature.Query.DeleteSpec
|
||||
import qualified Feature.Query.EmbedDisambiguationSpec
|
||||
import qualified Feature.Query.EmbedInnerJoinSpec
|
||||
import qualified Feature.Query.ErrorSpec
|
||||
import qualified Feature.Query.HtmlRawOutputSpec
|
||||
import qualified Feature.Query.InsertSpec
|
||||
import qualified Feature.Query.JsonOperatorSpec
|
||||
import qualified Feature.Query.MultipleSchemaSpec
|
||||
import qualified Feature.Query.NonexistentSchemaSpec
|
||||
import qualified Feature.Query.QueryLimitedSpec
|
||||
import qualified Feature.Query.QuerySpec
|
||||
import qualified Feature.Query.RangeSpec
|
||||
@@ -198,7 +198,7 @@ main = do
|
||||
|
||||
-- this test runs with a nonexistent db-schema
|
||||
parallel $ before nonexistentSchemaApp $
|
||||
describe "Feature.Query.NonexistentSchemaSpec" Feature.Query.NonexistentSchemaSpec.spec
|
||||
describe "Feature.Query.ErrorSpec" Feature.Query.ErrorSpec.spec
|
||||
|
||||
-- this test runs with an extra search path
|
||||
parallel $ before extraSearchPathApp $
|
||||
|
||||
Reference in New Issue
Block a user