Previously, information about each test-suite was repeated in 3 separate places: - as a label and as implicit knowledge in the test-suite itself, - as a comment in Main.hs, and - as a configuration in SpecHelper.hs. With this change, there will be a single source of truth in the test suite itself. This will allow a single test-suite to easily test multiple different configurations.
37 lines
1.0 KiB
Haskell
37 lines
1.0 KiB
Haskell
module Feature.Auth.NoJwtSecretSpec where
|
|
|
|
import Network.HTTP.Types
|
|
import Test.Hspec
|
|
import Test.Hspec.Wai
|
|
import Test.Hspec.Wai.JSON
|
|
|
|
import PostgREST.Config (AppConfig (..))
|
|
|
|
import Protolude hiding (get)
|
|
import SpecHelper
|
|
|
|
spec :: SpecWithConfig
|
|
spec withConfig = withConfig (
|
|
baseCfg {
|
|
configJwtSecret = Nothing
|
|
, configJWKS = Nothing
|
|
}
|
|
) $ describe "server started without JWT secret" $ do
|
|
|
|
it "responds with error on attempted auth" $ do
|
|
-- token body: { "role": "postgrest_test_author" }
|
|
let auth = authHeaderJWT "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoicG9zdGdyZXN0X3Rlc3RfYXV0aG9yIn0.Xod-F15qsGL0WhdOCr2j3DdKuTw9QJERVgoFD3vGaWA"
|
|
request methodGet "/authors_only"
|
|
[auth]
|
|
""
|
|
`shouldRespondWith`
|
|
[json|
|
|
{"hint": null,
|
|
"details": null,
|
|
"code": "PGRST300",
|
|
"message": "Server lacks JWT secret"}|]
|
|
{ matchStatus = 500 }
|
|
|
|
it "behaves normally when user does not attempt auth" $
|
|
get "/items" `shouldRespondWith` 200
|