1 {-# LANGUAGE OverloadedStrings #-}
2 module HUnit.Credential where
4 import Test.Tasty.HUnit
5 import qualified Control.Monad.Trans.State.Strict as S
6 import qualified System.Random as Random
11 hunit :: Reifies v Version => Proxy v -> TestTree
12 hunit _v = testGroup "Credential"
13 [ testGroup "randomCredential"
15 S.evalState randomCredential (Random.mkStdGen 0) @?=
16 Credential "xLcs7ev6Jy6FHHE"
18 , testGroup "randomUUID"
20 S.evalState randomUUID (Random.mkStdGen 0) @?=
23 , testGroup "readCredential" $
25 testCase (show inp) $ readCredential inp @?= exp in
26 [ "" ==> Left ErrorToken_Length
27 , "xLcs7ev6Jy6FH_E" ==> Left (ErrorToken_BadChar '_')
28 , "xLcs7ev6Jy6FHIE" ==> Left (ErrorToken_BadChar 'I')
29 , "xLcs7ev6Jy6FH0E" ==> Left (ErrorToken_BadChar '0')
30 , "xLcs7ev6Jy6FHOE" ==> Left (ErrorToken_BadChar 'O')
31 , "xLcs7ev6Jy6FHlE" ==> Left (ErrorToken_BadChar 'l')
32 , "xLcs7ev6Jy6FH6" ==> Left ErrorToken_Length
33 , "xLcs7ev6Jy6FHHy1" ==> Left ErrorToken_Length
34 , "xLcs7ev6Jy6FHHF" ==> Left ErrorToken_Checksum
35 , "xLcs7ev6Jy6FHHE" ==> Right (Credential "xLcs7ev6Jy6FHHE")
37 , testGroup "credentialSecretKey" $
38 [ testSecretKey beleniosFFC
39 (UUID "xLcs7ev6Jy6FHH")
40 (Credential "xLcs7ev6Jy6FHHE")
41 24202898752499029126606335829564687069186982035759723128887013101942425902424
46 ReifyCrypto crypto => Key crypto =>
47 crypto -> UUID -> Credential -> Natural -> TestTree
48 testSecretKey crypto uuid cred exp =
49 reifyCrypto crypto $ \(_c::Proxy c) ->
50 testCase (show (uuid,cred)) $
51 credentialSecretKey @_ @c uuid cred @?= E exp