diff options
Diffstat (limited to 'tests/suite.hs')
-rw-r--r-- | tests/suite.hs | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/tests/suite.hs b/tests/suite.hs index ffe8b50..ffcbc17 100644 --- a/tests/suite.hs +++ b/tests/suite.hs | |||
@@ -3,7 +3,7 @@ import Test.Framework.Providers.HUnit | |||
3 | 3 | ||
4 | import Test.HUnit | 4 | import Test.HUnit |
5 | 5 | ||
6 | import Codec.Encryption.OpenPGP.ASCIIArmor (encode, decode, multipartMerge) | 6 | import Codec.Encryption.OpenPGP.ASCIIArmor (decode, decodeLazy, encode, encodeLazy, multipartMerge) |
7 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types | 7 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types |
8 | import Codec.Encryption.OpenPGP.ASCIIArmor.Utils | 8 | import Codec.Encryption.OpenPGP.ASCIIArmor.Utils |
9 | 9 | ||
@@ -20,9 +20,9 @@ testCRC24 bs crc = assertEqual "crc24" crc (crc24 bs) | |||
20 | 20 | ||
21 | testArmorDecode :: FilePath -> [FilePath] -> Assertion | 21 | testArmorDecode :: FilePath -> [FilePath] -> Assertion |
22 | testArmorDecode fp targets = do | 22 | testArmorDecode fp targets = do |
23 | bs <- B.readFile $ "tests/data/" ++ fp | 23 | bs <- BL.readFile $ "tests/data/" ++ fp |
24 | tbss <- mapM (\target -> BL.readFile $ "tests/data/" ++ target) targets | 24 | tbss <- mapM (\target -> BL.readFile $ "tests/data/" ++ target) targets |
25 | case decode bs of | 25 | case decodeLazy bs of |
26 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp | 26 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp |
27 | Right as -> assertEqual ("for " ++ fp) tbss (map getPayload as) | 27 | Right as -> assertEqual ("for " ++ fp) tbss (map getPayload as) |
28 | where | 28 | where |
@@ -30,9 +30,9 @@ testArmorDecode fp targets = do | |||
30 | 30 | ||
31 | testArmorMultipartDecode :: FilePath -> FilePath -> Assertion | 31 | testArmorMultipartDecode :: FilePath -> FilePath -> Assertion |
32 | testArmorMultipartDecode fp target = do | 32 | testArmorMultipartDecode fp target = do |
33 | bs <- B.readFile $ "tests/data/" ++ fp | 33 | bs <- BL.readFile $ "tests/data/" ++ fp |
34 | tbs <- BL.readFile $ "tests/data/" ++ target | 34 | tbs <- BL.readFile $ "tests/data/" ++ target |
35 | case decode bs of | 35 | case decodeLazy bs of |
36 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp | 36 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp |
37 | Right as -> assertEqual ("for " ++ fp) tbs (getPayload (multipartMerge as)) | 37 | Right as -> assertEqual ("for " ++ fp) tbs (getPayload (multipartMerge as)) |
38 | where | 38 | where |
@@ -40,9 +40,9 @@ testArmorMultipartDecode fp target = do | |||
40 | 40 | ||
41 | testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion | 41 | testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion |
42 | testClearsignedDecodeBody fp target = do | 42 | testClearsignedDecodeBody fp target = do |
43 | bs <- B.readFile $ "tests/data/" ++ fp | 43 | bs <- BL.readFile $ "tests/data/" ++ fp |
44 | tbs <- BL.readFile $ "tests/data/" ++ target | 44 | tbs <- BL.readFile $ "tests/data/" ++ target |
45 | case decode bs of | 45 | case decodeLazy bs of |
46 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp | 46 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp |
47 | Right [a] -> assertEqual ("for " ++ fp) (convertEndings tbs) (getBody a) | 47 | Right [a] -> assertEqual ("for " ++ fp) (convertEndings tbs) (getBody a) |
48 | where | 48 | where |
@@ -51,9 +51,9 @@ testClearsignedDecodeBody fp target = do | |||
51 | 51 | ||
52 | testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion | 52 | testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion |
53 | testClearsignedDecodeSig fp target = do | 53 | testClearsignedDecodeSig fp target = do |
54 | bs <- B.readFile $ "tests/data/" ++ fp | 54 | bs <- BL.readFile $ "tests/data/" ++ fp |
55 | tbs <- BL.readFile $ "tests/data/" ++ target | 55 | tbs <- BL.readFile $ "tests/data/" ++ target |
56 | case decode bs of | 56 | case decodeLazy bs of |
57 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp | 57 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp |
58 | Right [a] -> assertEqual ("for " ++ fp) tbs (getSig a) | 58 | Right [a] -> assertEqual ("for " ++ fp) tbs (getSig a) |
59 | where | 59 | where |
@@ -62,15 +62,26 @@ testClearsignedDecodeSig fp target = do | |||
62 | testArmorEncode :: [FilePath] -> FilePath -> Assertion | 62 | testArmorEncode :: [FilePath] -> FilePath -> Assertion |
63 | testArmorEncode fps target = do | 63 | testArmorEncode fps target = do |
64 | bss <- mapM (\fp -> BL.readFile $ "tests/data/" ++ fp) fps | 64 | bss <- mapM (\fp -> BL.readFile $ "tests/data/" ++ fp) fps |
65 | tbs <- B.readFile $ "tests/data/" ++ target | 65 | tbs <- BL.readFile $ "tests/data/" ++ target |
66 | assertEqual ("literaldata") tbs (encode (map (\bs -> Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs) bss)) | 66 | assertEqual ("literaldata") tbs (encodeLazy (map (\bs -> Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs) bss)) |
67 | 67 | ||
68 | testClearsignedEncode :: FilePath -> FilePath -> FilePath -> Assertion | 68 | testClearsignedEncode :: FilePath -> FilePath -> FilePath -> Assertion |
69 | testClearsignedEncode ftxt fsig ftarget = do | 69 | testClearsignedEncode ftxt fsig ftarget = do |
70 | txt <- BL.readFile $ "tests/data/" ++ ftxt | 70 | txt <- BL.readFile $ "tests/data/" ++ ftxt |
71 | sig <- BL.readFile $ "tests/data/" ++ fsig | 71 | sig <- BL.readFile $ "tests/data/" ++ fsig |
72 | target <- B.readFile $ "tests/data/" ++ ftarget | 72 | target <- BL.readFile $ "tests/data/" ++ ftarget |
73 | assertEqual ("clearsigned encode") target (encode [ClearSigned [("Hash","SHA1")] txt (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] sig)]) | 73 | assertEqual ("clearsigned encode") target (encodeLazy [ClearSigned [("Hash","SHA1")] txt (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] sig)]) |
74 | |||
75 | testStrictDecode :: FilePath -> Assertion | ||
76 | testStrictDecode fp = do | ||
77 | bs <- BL.readFile $ "tests/data/" ++ fp | ||
78 | assertEqual ("strict decode") (decodeLazy bs :: Either String [Armor]) (decode (B.concat . BL.toChunks $ bs) :: Either String [Armor]) | ||
79 | |||
80 | testStrictEncode :: FilePath -> Assertion | ||
81 | testStrictEncode fp = do | ||
82 | bs <- BL.readFile $ "tests/data/" ++ fp | ||
83 | let fakearmors = [Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs, ClearSigned [("Hash","SHA1")] bs (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] bs)] | ||
84 | assertEqual ("strict encode") (encodeLazy fakearmors) (BL.fromChunks [(encode fakearmors)]) | ||
74 | 85 | ||
75 | tests = [ | 86 | tests = [ |
76 | testGroup "CRC24" [ | 87 | testGroup "CRC24" [ |
@@ -89,6 +100,8 @@ tests = [ | |||
89 | , testCase "Encode sample armor" (testArmorEncode ["msg1.gpg"] "msg1.asc") | 100 | , testCase "Encode sample armor" (testArmorEncode ["msg1.gpg"] "msg1.asc") |
90 | , testCase "Encode multiple sample armors" (testArmorEncode ["msg1.gpg","msg1.gpg","msg1.gpg"] "msg1c.asc") | 101 | , testCase "Encode multiple sample armors" (testArmorEncode ["msg1.gpg","msg1.gpg","msg1.gpg"] "msg1c.asc") |
91 | , testCase "Encode clear-signed sig" (testClearsignedEncode "msg3" "msg3.sig" "msg3.asc") | 102 | , testCase "Encode clear-signed sig" (testClearsignedEncode "msg3" "msg3.sig" "msg3.asc") |
103 | , testCase "Decode from strict ByteString" (testStrictDecode "msg1.asc") | ||
104 | , testCase "Encode to strict ByteString" (testStrictEncode "msg1.gpg") | ||
92 | ] | 105 | ] |
93 | ] | 106 | ] |
94 | 107 | ||