Permalink
Browse files

Initial test suite

Data and some code from hOpenPGP, © Clit Adams, MIT license
  • Loading branch information...
1 parent 286db8a commit 1d27d944ddaba1113fe7ec69701e7122eaa18618 @singpolyma committed Apr 24, 2012
Showing with 153 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +10 −4 Makefile
  3. BIN tests/data/000001-006.public_key
  4. +1 −0 tests/data/000002-013.user_id
  5. BIN tests/data/000003-002.sig
  6. BIN tests/data/000004-012.ring_trust
  7. BIN tests/data/000005-002.sig
  8. BIN tests/data/000006-012.ring_trust
  9. BIN tests/data/000007-002.sig
  10. BIN tests/data/000008-012.ring_trust
  11. BIN tests/data/000009-002.sig
  12. BIN tests/data/000010-012.ring_trust
  13. BIN tests/data/000011-002.sig
  14. BIN tests/data/000012-012.ring_trust
  15. BIN tests/data/000013-014.public_subkey
  16. BIN tests/data/000014-002.sig
  17. BIN tests/data/000015-012.ring_trust
  18. BIN tests/data/000016-006.public_key
  19. BIN tests/data/000017-002.sig
  20. BIN tests/data/000018-012.ring_trust
  21. +1 −0 tests/data/000019-013.user_id
  22. BIN tests/data/000020-002.sig
  23. BIN tests/data/000021-012.ring_trust
  24. BIN tests/data/000022-002.sig
  25. BIN tests/data/000023-012.ring_trust
  26. BIN tests/data/000024-014.public_subkey
  27. BIN tests/data/000025-002.sig
  28. BIN tests/data/000026-012.ring_trust
  29. BIN tests/data/000027-006.public_key
  30. BIN tests/data/000028-002.sig
  31. BIN tests/data/000029-012.ring_trust
  32. +1 −0 tests/data/000030-013.user_id
  33. BIN tests/data/000031-002.sig
  34. BIN tests/data/000032-012.ring_trust
  35. BIN tests/data/000033-002.sig
  36. BIN tests/data/000034-012.ring_trust
  37. BIN tests/data/000035-006.public_key
  38. +1 −0 tests/data/000036-013.user_id
  39. BIN tests/data/000037-002.sig
  40. BIN tests/data/000038-012.ring_trust
  41. BIN tests/data/000039-002.sig
  42. BIN tests/data/000040-012.ring_trust
  43. BIN tests/data/000041-017.attribute
  44. BIN tests/data/000042-002.sig
  45. BIN tests/data/000043-012.ring_trust
  46. BIN tests/data/000044-014.public_subkey
  47. BIN tests/data/000045-002.sig
  48. BIN tests/data/000046-012.ring_trust
  49. BIN tests/data/000047-005.secret_key
  50. +1 −0 tests/data/000048-013.user_id
  51. BIN tests/data/000049-002.sig
  52. BIN tests/data/000050-012.ring_trust
  53. BIN tests/data/000051-007.secret_subkey
  54. BIN tests/data/000052-002.sig
  55. BIN tests/data/000053-012.ring_trust
  56. BIN tests/data/000054-005.secret_key
  57. BIN tests/data/000055-002.sig
  58. BIN tests/data/000056-012.ring_trust
  59. +1 −0 tests/data/000057-013.user_id
  60. BIN tests/data/000058-002.sig
  61. BIN tests/data/000059-012.ring_trust
  62. BIN tests/data/000060-007.secret_subkey
  63. BIN tests/data/000061-002.sig
  64. BIN tests/data/000062-012.ring_trust
  65. BIN tests/data/000063-005.secret_key
  66. BIN tests/data/000064-002.sig
  67. BIN tests/data/000065-012.ring_trust
  68. +1 −0 tests/data/000066-013.user_id
  69. BIN tests/data/000067-002.sig
  70. BIN tests/data/000068-012.ring_trust
  71. BIN tests/data/000069-005.secret_key
  72. +1 −0 tests/data/000070-013.user_id
  73. BIN tests/data/000071-002.sig
  74. BIN tests/data/000072-012.ring_trust
  75. BIN tests/data/000073-017.attribute
  76. BIN tests/data/000074-002.sig
  77. BIN tests/data/000075-012.ring_trust
  78. BIN tests/data/000076-007.secret_subkey
  79. BIN tests/data/000077-002.sig
  80. BIN tests/data/000078-012.ring_trust
  81. BIN tests/data/compressedsig-bzip2.gpg
  82. BIN tests/data/compressedsig-zlib.gpg
  83. BIN tests/data/compressedsig.gpg
  84. +1 −0 tests/data/encryption-sym-aes256.gpg
  85. BIN tests/data/encryption-sym-cast5.gpg
  86. BIN tests/data/encryption.gpg
  87. +7 −0 tests/data/msg1.asc
  88. BIN tests/data/onepass_sig
  89. BIN tests/data/pubring.gpg
  90. BIN tests/data/secring.gpg
  91. BIN tests/data/uncompressed-ops-dsa-sha384.txt.gpg
  92. BIN tests/data/uncompressed-ops-dsa.gpg
  93. BIN tests/data/uncompressed-ops-rsa.gpg
  94. +126 −0 tests/suite.hs
View
@@ -4,6 +4,7 @@
verify
sign
keygen
+tests/suite
dist/*
report.html
dist-ghc/*
View
@@ -2,15 +2,18 @@ GHCFLAGS=-Wall -XNoCPP -fno-warn-name-shadowing -XHaskell98
HLINTFLAGS=-XHaskell98 -XNoCPP -i 'Use camelCase' -i 'Use String' -i 'Use head' -i 'Use string literal' -i 'Use list comprehension' --utf8
VERSION=0.3
-.PHONY: all clean doc install debian
+.PHONY: all clean doc install debian test
-all: sign verify keygen report.html doc dist/build/libHSopenpgp-$(VERSION).a dist/openpgp-$(VERSION).tar.gz
+all: sign verify keygen test report.html doc dist/build/libHSopenpgp-$(VERSION).a dist/openpgp-$(VERSION).tar.gz
install: dist/build/libHSopenpgp-$(VERSION).a
cabal install
debian: debian/control
+test: tests/suite
+ tests/suite
+
sign: examples/sign.hs Data/*.hs Data/OpenPGP/*.hs
ghc --make $(GHCFLAGS) -o $@ $^
@@ -20,7 +23,10 @@ verify: examples/verify.hs Data/*.hs Data/OpenPGP/*.hs
keygen: examples/keygen.hs Data/*.hs Data/OpenPGP/*.hs
ghc --make $(GHCFLAGS) -o $@ $^
-report.html: examples/*.hs Data/*.hs Data/OpenPGP/*.hs
+tests/suite: tests/suite.hs
+ ghc --make $(GHCFLAGS) -o $@ $^
+
+report.html: examples/*.hs Data/*.hs Data/OpenPGP/*.hs tests/*.hs
-hlint $(HLINTFLAGS) --report Data examples
doc: dist/doc/html/openpgp/index.html README
@@ -39,7 +45,7 @@ dist/setup-config: openpgp.cabal
clean:
find -name '*.o' -o -name '*.hi' | xargs $(RM)
- $(RM) sign verify keygen
+ $(RM) sign verify keygen tests/suite
$(RM) -r dist dist-ghc
debian/control: openpgp.cabal
Binary file not shown.
@@ -0,0 +1 @@
+�$Test Key (RSA) <testkey@example.org>
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
+�$Test Key (DSA) <testkey@example.com>
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
+�+Test Key (DSA sign-only) <test@example.net>
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
+�.Test Key (RSA sign-only) <testkey@example.net>
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
+�$Test Key (RSA) <testkey@example.org>
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
+�$Test Key (DSA) <testkey@example.com>
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
+�+Test Key (DSA sign-only) <test@example.net>
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
+�.Test Key (RSA sign-only) <testkey@example.net>
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
+� ��'6*�W`�V�LE���Q�jNp(Y3��N*�?���!�M��*�*ۈ;�hL�2�+��!x�̄�&&\J{q���<16.�-�D ޿���
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,7 @@
+-----BEGIN PGP MESSAGE-----
+Version: OpenPrivacy 0.99
+
+yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS
+vBSFjNSiVHsuAA==
+=njUN
+-----END PGP MESSAGE-----
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
@@ -0,0 +1,126 @@
+import Test.Framework (defaultMain, testGroup, Test)
+import Test.Framework.Providers.HUnit
+import Test.Framework.Providers.QuickCheck2
+import Test.QuickCheck ()
+import Test.HUnit hiding (Test)
+
+import Data.Word
+import Data.Binary
+import qualified Data.OpenPGP as OpenPGP
+import qualified Data.ByteString.Lazy as LZ
+
+testSerialization :: FilePath -> Assertion
+testSerialization fp = do
+ bs <- LZ.readFile $ "tests/data/" ++ fp
+ nullShield "First" (decode bs) (\firstpass ->
+ nullShield "Second" (decode $ encode firstpass) (\secondpass ->
+ assertEqual ("for " ++ fp) firstpass secondpass
+ )
+ )
+ where
+ nullShield pass (OpenPGP.Message []) _ =
+ assertFailure $ pass ++ " pass of " ++ fp ++ " decoded to nothing."
+ nullShield _ m f = f m
+
+prop_s2k_count :: Word8 -> Bool
+prop_s2k_count c =
+ c == OpenPGP.encode_s2k_count (OpenPGP.decode_s2k_count c)
+
+tests :: [Test]
+tests =
+ [
+ testGroup "Serialization group" [
+ testCase "000001-006.public_key" (testSerialization "000001-006.public_key"),
+ testCase "000002-013.user_id" (testSerialization "000002-013.user_id"),
+ --testCase "000003-002.sig" (testSerialization "000003-002.sig"),
+ --testCase "000004-012.ring_trust" (testSerialization "000004-012.ring_trust"),
+ --testCase "000005-002.sig" (testSerialization "000005-002.sig"),
+ --testCase "000006-012.ring_trust" (testSerialization "000006-012.ring_trust"),
+ --testCase "000007-002.sig" (testSerialization "000007-002.sig"),
+ --testCase "000008-012.ring_trust" (testSerialization "000008-012.ring_trust"),
+ -- Issue #11 -- testCase "000009-002.sig" (testSerialization "000009-002.sig"),
+ --testCase "000010-012.ring_trust" (testSerialization "000010-012.ring_trust"),
+ -- Issue #11 -- testCase "000011-002.sig" (testSerialization "000011-002.sig"),
+ --testCase "000012-012.ring_trust" (testSerialization "000012-012.ring_trust"),
+ --testCase "000013-014.public_subkey" (testSerialization "000013-014.public_subkey"),
+ --testCase "000014-002.sig" (testSerialization "000014-002.sig"),
+ --testCase "000015-012.ring_trust" (testSerialization "000015-012.ring_trust"),
+ testCase "000016-006.public_key" (testSerialization "000016-006.public_key"),
+ --testCase "000017-002.sig" (testSerialization "000017-002.sig"),
+ --testCase "000018-012.ring_trust" (testSerialization "000018-012.ring_trust"),
+ testCase "000019-013.user_id" (testSerialization "000019-013.user_id"),
+ --testCase "000020-002.sig" (testSerialization "000020-002.sig"),
+ --testCase "000021-012.ring_trust" (testSerialization "000021-012.ring_trust"),
+ -- Issue #11 -- testCase "000022-002.sig" (testSerialization "000022-002.sig"),
+ --testCase "000023-012.ring_trust" (testSerialization "000023-012.ring_trust"),
+ --testCase "000024-014.public_subkey" (testSerialization "000024-014.public_subkey"),
+ --testCase "000025-002.sig" (testSerialization "000025-002.sig"),
+ --testCase "000026-012.ring_trust" (testSerialization "000026-012.ring_trust"),
+ testCase "000027-006.public_key" (testSerialization "000027-006.public_key"),
+ --testCase "000028-002.sig" (testSerialization "000028-002.sig"),
+ --testCase "000029-012.ring_trust" (testSerialization "000029-012.ring_trust"),
+ testCase "000030-013.user_id" (testSerialization "000030-013.user_id"),
+ --testCase "000031-002.sig" (testSerialization "000031-002.sig"),
+ --testCase "000032-012.ring_trust" (testSerialization "000032-012.ring_trust"),
+ -- Issue #11 -- testCase "000033-002.sig" (testSerialization "000033-002.sig"),
+ --testCase "000034-012.ring_trust" (testSerialization "000034-012.ring_trust"),
+ testCase "000035-006.public_key" (testSerialization "000035-006.public_key"),
+ testCase "000036-013.user_id" (testSerialization "000036-013.user_id"),
+ --testCase "000037-002.sig" (testSerialization "000037-002.sig"),
+ --testCase "000038-012.ring_trust" (testSerialization "000038-012.ring_trust"),
+ -- Issue #11 -- testCase "000039-002.sig" (testSerialization "000039-002.sig"),
+ --testCase "000040-012.ring_trust" (testSerialization "000040-012.ring_trust"),
+ --testCase "000041-017.attribute" (testSerialization "000041-017.attribute"),
+ --testCase "000042-002.sig" (testSerialization "000042-002.sig"),
+ --testCase "000043-012.ring_trust" (testSerialization "000043-012.ring_trust"),
+ --testCase "000044-014.public_subkey" (testSerialization "000044-014.public_subkey"),
+ --testCase "000045-002.sig" (testSerialization "000045-002.sig"),
+ --testCase "000046-012.ring_trust" (testSerialization "000046-012.ring_trust"),
+ testCase "000047-005.secret_key" (testSerialization "000047-005.secret_key"),
+ testCase "000048-013.user_id" (testSerialization "000048-013.user_id"),
+ --testCase "000049-002.sig" (testSerialization "000049-002.sig"),
+ --testCase "000050-012.ring_trust" (testSerialization "000050-012.ring_trust"),
+ --testCase "000051-007.secret_subkey" (testSerialization "000051-007.secret_subkey"),
+ --testCase "000052-002.sig" (testSerialization "000052-002.sig"),
+ --testCase "000053-012.ring_trust" (testSerialization "000053-012.ring_trust"),
+ testCase "000054-005.secret_key" (testSerialization "000054-005.secret_key"),
+ --testCase "000055-002.sig" (testSerialization "000055-002.sig"),
+ --testCase "000056-012.ring_trust" (testSerialization "000056-012.ring_trust"),
+ testCase "000057-013.user_id" (testSerialization "000057-013.user_id"),
+ --testCase "000058-002.sig" (testSerialization "000058-002.sig"),
+ --testCase "000059-012.ring_trust" (testSerialization "000059-012.ring_trust"),
+ --testCase "000060-007.secret_subkey" (testSerialization "000060-007.secret_subkey"),
+ --testCase "000061-002.sig" (testSerialization "000061-002.sig"),
+ --testCase "000062-012.ring_trust" (testSerialization "000062-012.ring_trust"),
+ testCase "000063-005.secret_key" (testSerialization "000063-005.secret_key"),
+ --testCase "000064-002.sig" (testSerialization "000064-002.sig"),
+ --testCase "000065-012.ring_trust" (testSerialization "000065-012.ring_trust"),
+ testCase "000066-013.user_id" (testSerialization "000066-013.user_id"),
+ --testCase "000067-002.sig" (testSerialization "000067-002.sig"),
+ --testCase "000068-012.ring_trust" (testSerialization "000068-012.ring_trust"),
+ testCase "000069-005.secret_key" (testSerialization "000069-005.secret_key"),
+ --testCase "000070-013.user_id" (testSerialization "000070-013.user_id"),
+ --testCase "000071-002.sig" (testSerialization "000071-002.sig"),
+ --testCase "000072-012.ring_trust" (testSerialization "000072-012.ring_trust"),
+ --testCase "000073-017.attribute" (testSerialization "000073-017.attribute"),
+ --testCase "000074-002.sig" (testSerialization "000074-002.sig"),
+ --testCase "000075-012.ring_trust" (testSerialization "000075-012.ring_trust"),
+ --testCase "000076-007.secret_subkey" (testSerialization "000076-007.secret_subkey"),
+ --testCase "000077-002.sig" (testSerialization "000077-002.sig"),
+ --testCase "000078-012.ring_trust" (testSerialization "000078-012.ring_trust"),
+ --testCase "pubring.gpg" (testSerialization "pubring.gpg"),
+ --testCase "secring.gpg" (testSerialization "secring.gpg"),
+ -- Issue #11 -- testCase "compressedsig.gpg" (testSerialization "compressedsig.gpg"),
+ -- Issue #11 -- testCase "compressedsig-zlib.gpg" (testSerialization "compressedsig-zlib.gpg"),
+ -- Issue #11 -- testCase "compressedsig-bzip2.gpg" (testSerialization "compressedsig-bzip2.gpg"),
+ testCase "onepass_sig" (testSerialization "onepass_sig")
+ -- Issue #11 -- testCase "uncompressed-ops-dsa.gpg" (testSerialization "uncompressed-ops-dsa.gpg"),
+ -- Issue #11 -- testCase "uncompressed-ops-rsa.gpg" (testSerialization "uncompressed-ops-rsa.gpg"),
+ ],
+ testGroup "S2K count" [
+ testProperty "S2K count encode reverses decode" prop_s2k_count
+ ]
+ ]
+
+main :: IO ()
+main = defaultMain tests

0 comments on commit 1d27d94

Please sign in to comment.