about summary refs log blame commit diff
path: root/website/sandbox/learnpianochords/src/server/Spec.hs
blob: 1f9b9bb4bf9c0595927411585da77e3b76c7b6b5 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                                  



                                                                                




                              



                                                                                





                                                                                

                                                                      




                                                                              

                                                                      
{-# 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