summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell
diff options
context:
space:
mode:
Diffstat (limited to 'lambda-calcul/haskell')
-rw-r--r--lambda-calcul/haskell/test/Minilang/ServerSpec.hs23
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")]