@@ -11,26 +11,23 @@ import Utils.String
1111
1212export
1313test_base64_encoding_decoding : EitherT String IO ()
14- test_base64_encoding_decoding =
15- let user = " aladdin"
16- passwd = " opensesame"
17- (_ , basicauth) = applyBasicAuth user passwd
18- basicauth' = base64DecodeString $ last $ split ((== ) ' ' ) basicauth
19- in case basicauth' of
20- Nothing =>
21- idris_crash " couldn't base64 decode string."
22- Just basicauth'' =>
23- case utf8_pack basicauth' ' of
24- Nothing =>
25- idris_crash "couldn' t utf8 pack decoded string. "
26- Just basicauth''' =>
27- let userpasswd = split ((==) ':') basicauth'''
28- user' = head userpasswd
29- passwd' = last userpasswd
30- in case basicauth == " Basic YWxhZGRpbjpvcGVuc2VzYW1l " &&
31- user == user' &&
32- passwd == passwd' of
33- True =>
34- pure ()
35- False =>
36- throwE " base64 encode/ decode error : expected \{user} and \{user'}, \{passwd} and \{passwd'} to be equivalent."
14+ test_base64_encoding_decoding = do
15+ let user = " aladdin"
16+ let passwd = " opensesame"
17+ let (_ , basicauth) = applyBasicAuth user passwd
18+
19+ basicauth' <- maybe (throwE " Couldn't base64 decode string." ) pure $
20+ base64DecodeString $ last $ split ((== ) ' ' ) basicauth
21+
22+ basicauth'' <- maybe (throwE "Couldn' t utf8 pack decoded string. " ) pure $
23+ utf8_pack basicauth'
24+
25+ let userpasswd = split ((==) ':') basicauth''
26+ let user' = head userpasswd
27+ let passwd' = last userpasswd
28+
29+ if basicauth == " Basic YWxhZGRpbjpvcGVuc2VzYW1l " &&
30+ user == user' &&
31+ passwd == passwd'
32+ then pure ()
33+ else throwE $ " Base64 encode/ decode error : expected {user} and {user'}, {passwd} and {passwd'} to be equivalent."
0 commit comments