diff options
Diffstat (limited to 'tests/suite.hs')
-rw-r--r-- | tests/suite.hs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/suite.hs b/tests/suite.hs index 6fdd816..838a5f3 100644 --- a/tests/suite.hs +++ b/tests/suite.hs | |||
@@ -5,6 +5,7 @@ import Test.HUnit | |||
5 | 5 | ||
6 | import Codec.Encryption.OpenPGP.ASCIIArmor (encode, decode, multipartMerge) | 6 | import Codec.Encryption.OpenPGP.ASCIIArmor (encode, decode, multipartMerge) |
7 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types | 7 | import Codec.Encryption.OpenPGP.ASCIIArmor.Types |
8 | import Codec.Encryption.OpenPGP.ASCIIArmor.Utils | ||
8 | 9 | ||
9 | import Data.ByteString (ByteString) | 10 | import Data.ByteString (ByteString) |
10 | import qualified Data.ByteString as B | 11 | import qualified Data.ByteString as B |
@@ -35,11 +36,39 @@ testArmorMultipartDecode fp target = do | |||
35 | where | 36 | where |
36 | getPayload (Armor _ _ pl) = pl | 37 | getPayload (Armor _ _ pl) = pl |
37 | 38 | ||
39 | testClearsignedDecodeBody :: FilePath -> FilePath -> Assertion | ||
40 | testClearsignedDecodeBody fp target = do | ||
41 | bs <- B.readFile $ "tests/data/" ++ fp | ||
42 | tbs <- B.readFile $ "tests/data/" ++ target | ||
43 | case decode bs of | ||
44 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp | ||
45 | Right [a] -> assertEqual ("for " ++ fp) (convertEndings tbs) (getBody a) | ||
46 | where | ||
47 | getBody (ClearSigned _ txt _) = txt | ||
48 | convertEndings = crlfUnlines . BC8.lines | ||
49 | |||
50 | testClearsignedDecodeSig :: FilePath -> FilePath -> Assertion | ||
51 | testClearsignedDecodeSig fp target = do | ||
52 | bs <- B.readFile $ "tests/data/" ++ fp | ||
53 | tbs <- B.readFile $ "tests/data/" ++ target | ||
54 | case decode bs of | ||
55 | Left e -> assertFailure $ "Decode failed (" ++ e ++ ") on " ++ fp | ||
56 | Right [a] -> assertEqual ("for " ++ fp) tbs (getSig a) | ||
57 | where | ||
58 | getSig (ClearSigned _ _ (Armor _ _ sig)) = sig | ||
59 | |||
38 | testArmorEncode :: [FilePath] -> FilePath -> Assertion | 60 | testArmorEncode :: [FilePath] -> FilePath -> Assertion |
39 | testArmorEncode fps target = do | 61 | testArmorEncode fps target = do |
40 | bss <- mapM (\fp -> B.readFile $ "tests/data/" ++ fp) fps | 62 | bss <- mapM (\fp -> B.readFile $ "tests/data/" ++ fp) fps |
41 | tbs <- B.readFile $ "tests/data/" ++ target | 63 | tbs <- B.readFile $ "tests/data/" ++ target |
42 | assertEqual ("literaldata") (encode (map (\bs -> Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs) bss)) tbs | 64 | assertEqual ("literaldata") tbs (encode (map (\bs -> Armor ArmorMessage [("Version","OpenPrivacy 0.99")] bs) bss)) |
65 | |||
66 | testClearsignedEncode :: FilePath -> FilePath -> FilePath -> Assertion | ||
67 | testClearsignedEncode ftxt fsig ftarget = do | ||
68 | txt <- B.readFile $ "tests/data/" ++ ftxt | ||
69 | sig <- B.readFile $ "tests/data/" ++ fsig | ||
70 | target <- B.readFile $ "tests/data/" ++ ftarget | ||
71 | assertEqual ("clearsigned encode") target (encode [ClearSigned [("Hash","SHA1")] txt (Armor ArmorSignature [("Version","OpenPrivacy 0.99")] sig)]) | ||
43 | 72 | ||
44 | tests = [ | 73 | tests = [ |
45 | testGroup "CRC24" [ | 74 | testGroup "CRC24" [ |
@@ -51,9 +80,13 @@ tests = [ | |||
51 | testCase "Decode sample armor" (testArmorDecode "msg1.asc" ["msg1.gpg"]) | 80 | testCase "Decode sample armor" (testArmorDecode "msg1.asc" ["msg1.gpg"]) |
52 | , testCase "Decode sample armor with cruft" (testArmorDecode "msg1a.asc" ["msg1.gpg"]) | 81 | , testCase "Decode sample armor with cruft" (testArmorDecode "msg1a.asc" ["msg1.gpg"]) |
53 | , testCase "Decode multiple sample armors" (testArmorDecode "msg1b.asc" ["msg1.gpg","msg1.gpg","msg1.gpg"]) | 82 | , testCase "Decode multiple sample armors" (testArmorDecode "msg1b.asc" ["msg1.gpg","msg1.gpg","msg1.gpg"]) |
83 | , testCase "Decode detached signature" (testArmorDecode "msg4.asc" ["msg4.sig"]) | ||
54 | , testCase "Decode multi-part armor" (testArmorMultipartDecode "msg2.asc" "msg2.pgp") | 84 | , testCase "Decode multi-part armor" (testArmorMultipartDecode "msg2.asc" "msg2.pgp") |
85 | , testCase "Decode body of clear-signed" (testClearsignedDecodeBody "msg3.asc" "msg3") | ||
86 | , testCase "Decode sig of clear-signed" (testClearsignedDecodeSig "msg3.asc" "msg3.sig") | ||
55 | , testCase "Encode sample armor" (testArmorEncode ["msg1.gpg"] "msg1.asc") | 87 | , testCase "Encode sample armor" (testArmorEncode ["msg1.gpg"] "msg1.asc") |
56 | , testCase "Encode multiple sample armors" (testArmorEncode ["msg1.gpg","msg1.gpg","msg1.gpg"] "msg1c.asc") | 88 | , testCase "Encode multiple sample armors" (testArmorEncode ["msg1.gpg","msg1.gpg","msg1.gpg"] "msg1c.asc") |
89 | , testCase "Encode clear-signed sig" (testClearsignedEncode "msg3" "msg3.sig" "msg3.asc") | ||
57 | ] | 90 | ] |
58 | ] | 91 | ] |
59 | 92 | ||