about summary refs log tree commit diff
path: root/website/sandbox/learnpianochords/src/server/Spec.hs
blob: 1f9b9bb4bf9c0595927411585da77e3b76c7b6b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{-# LANGUAGE OverloadedStrings #-}
--------------------------------------------------------------------------------
module Spec where
--------------------------------------------------------------------------------
import Test.Hspec
import Web.JWT
import Utils

import qualified GoogleSignIn
import qualified Fixtures as F
--------------------------------------------------------------------------------

main :: IO ()
main = hspec $ do
  describe "GoogleSignIn" $ do
    describe "jwtIsValid" $ do
      it "returns false when the signature is invalid" $ do
        let mJWT = F.defaultJWTFields { F.overwriteSigner = hmacSecret "wrong" }
                   |> F.googleJWT
        case mJWT of
          Nothing  -> True `shouldBe` False
          Just jwt -> GoogleSignIn.jwtIsValid jwt `shouldReturn` False

      it "returns false when the aud field doesn't match my client ID" $ do
        let mJWT = F.defaultJWTFields { F.overwriteAud = stringOrURI "wrong" }
                  |> F.googleJWT
        case mJWT of
          Nothing  -> True `shouldBe` False
          Just jwt -> GoogleSignIn.jwtIsValid jwt `shouldReturn` False