diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-05 06:06:22 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-11-05 06:06:22 +0100 |
| commit | e6d000430619613a07974f601e7c132cd12556e9 (patch) | |
| tree | 5c4758e9216bad221ce1bb21e64963d494b1f830 /lambda-calcul | |
| parent | 4240c90039e78bde98fcc3e0e27bad5d2c771bae (diff) | |
| download | lambda-nantes-e6d000430619613a07974f601e7c132cd12556e9.tar.gz | |
handle post challenge error cases
Diffstat (limited to 'lambda-calcul')
| -rw-r--r-- | lambda-calcul/haskell/test/Minilang/ServerSpec.hs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lambda-calcul/haskell/test/Minilang/ServerSpec.hs b/lambda-calcul/haskell/test/Minilang/ServerSpec.hs index 544d0b7..d2a95d1 100644 --- a/lambda-calcul/haskell/test/Minilang/ServerSpec.hs +++ b/lambda-calcul/haskell/test/Minilang/ServerSpec.hs @@ -21,10 +21,11 @@ import System.Random (StdGen, mkStdGen64) import Test.Hspec (Spec, it) import Test.Hspec.Wai (WaiSession, get, matchBody, request, shouldRespondWith, with) import Test.Hspec.Wai.Matcher (MatchBody (..)) +import Data.Bifunctor (first) spec :: Spec spec = with (app testSeed) $ do - let token = Base64.encode (fst $ newToken testSeed) + let (token, gen) = first Base64.encode (newToken testSeed) alice = encode $ User "alice" it "GET / returns 'index.html'" $ do @@ -81,6 +82,26 @@ spec = with (app testSeed) $ do postJSON ("/api/challenge?token=" <> LBS.toStrict token) response `shouldRespondWith` 200 + it "POST /api/challenge returns 400 given challenge response is incorrect" $ do + let response = "\"y\"" + void $ postJSON "/api/register" alice + + postJSON ("/api/challenge?token=" <> LBS.toStrict token) response + `shouldRespondWith` 400 + + it "POST /api/challenge returns 400 given user is not registered" $ do + let response = "\"x\"" + + postJSON ("/api/challenge?token=" <> LBS.toStrict token) response + `shouldRespondWith` 400 + + it "POST /api/challenge returns 400 given wrong token" $ do + let response = "\"x\"" + otherToken = Base64.encode $ fst $ newToken gen + + postJSON ("/api/challenge?token=" <> LBS.toStrict otherToken) response + `shouldRespondWith` 400 + postJSON :: BS.ByteString -> ByteString -> WaiSession () SResponse postJSON url = request "POST" url [("Content-Type", "application/json")] |
