Skip to content

Commit

Permalink
Initial test suite
Browse files Browse the repository at this point in the history
Data and some code from hOpenPGP, © Clit Adams, MIT license
  • Loading branch information
singpolyma committed Apr 24, 2012
1 parent 286db8a commit 1d27d94
Show file tree
Hide file tree
Showing 94 changed files with 153 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,6 +4,7 @@
verify
sign
keygen
tests/suite
dist/*
report.html
dist-ghc/*
Expand Down
14 changes: 10 additions & 4 deletions Makefile
Expand Up @@ -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 $@ $^

Expand All @@ -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
Expand All @@ -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
Expand Down
Binary file added tests/data/000001-006.public_key
Binary file not shown.
1 change: 1 addition & 0 deletions tests/data/000002-013.user_id
@@ -0,0 +1 @@
�$Test Key (RSA) <testkey@example.org>
Binary file added tests/data/000003-002.sig
Binary file not shown.
Binary file added tests/data/000004-012.ring_trust
Binary file not shown.
Binary file added tests/data/000005-002.sig
Binary file not shown.
Binary file added tests/data/000006-012.ring_trust
Binary file not shown.
Binary file added tests/data/000007-002.sig
Binary file not shown.
Binary file added tests/data/000008-012.ring_trust
Binary file not shown.
Binary file added tests/data/000009-002.sig
Binary file not shown.
Binary file added tests/data/000010-012.ring_trust
Binary file not shown.
Binary file added tests/data/000011-002.sig
Binary file not shown.
Binary file added tests/data/000012-012.ring_trust
Binary file not shown.
Binary file added tests/data/000013-014.public_subkey
Binary file not shown.
Binary file added tests/data/000014-002.sig
Binary file not shown.
Binary file added tests/data/000015-012.ring_trust
Binary file not shown.
Binary file added tests/data/000016-006.public_key
Binary file not shown.
Binary file added tests/data/000017-002.sig
Binary file not shown.
Binary file added tests/data/000018-012.ring_trust
Binary file not shown.
1 change: 1 addition & 0 deletions tests/data/000019-013.user_id
@@ -0,0 +1 @@
�$Test Key (DSA) <testkey@example.com>
Binary file added tests/data/000020-002.sig
Binary file not shown.
Binary file added tests/data/000021-012.ring_trust
Binary file not shown.
Binary file added tests/data/000022-002.sig
Binary file not shown.
Binary file added tests/data/000023-012.ring_trust
Binary file not shown.
Binary file added tests/data/000024-014.public_subkey
Binary file not shown.
Binary file added tests/data/000025-002.sig
Binary file not shown.
Binary file added tests/data/000026-012.ring_trust
Binary file not shown.
Binary file added tests/data/000027-006.public_key
Binary file not shown.
Binary file added tests/data/000028-002.sig
Binary file not shown.
Binary file added tests/data/000029-012.ring_trust
Binary file not shown.
1 change: 1 addition & 0 deletions tests/data/000030-013.user_id
@@ -0,0 +1 @@
�+Test Key (DSA sign-only) <test@example.net>
Binary file added tests/data/000031-002.sig
Binary file not shown.
Binary file added tests/data/000032-012.ring_trust
Binary file not shown.
Binary file added tests/data/000033-002.sig
Binary file not shown.
Binary file added tests/data/000034-012.ring_trust
Binary file not shown.
Binary file added tests/data/000035-006.public_key
Binary file not shown.
1 change: 1 addition & 0 deletions tests/data/000036-013.user_id
@@ -0,0 +1 @@
�.Test Key (RSA sign-only) <testkey@example.net>
Binary file added tests/data/000037-002.sig
Binary file not shown.
Binary file added tests/data/000038-012.ring_trust
Binary file not shown.
Binary file added tests/data/000039-002.sig
Binary file not shown.
Binary file added tests/data/000040-012.ring_trust
Binary file not shown.
Binary file added tests/data/000041-017.attribute
Binary file not shown.
Binary file added tests/data/000042-002.sig
Binary file not shown.
Binary file added tests/data/000043-012.ring_trust
Binary file not shown.
Binary file added tests/data/000044-014.public_subkey
Binary file not shown.
Binary file added tests/data/000045-002.sig
Binary file not shown.
Binary file added tests/data/000046-012.ring_trust
Binary file not shown.
Binary file added tests/data/000047-005.secret_key
Binary file not shown.
1 change: 1 addition & 0 deletions tests/data/000048-013.user_id
@@ -0,0 +1 @@
�$Test Key (RSA) <testkey@example.org>
Binary file added tests/data/000049-002.sig
Binary file not shown.
Binary file added tests/data/000050-012.ring_trust
Binary file not shown.
Binary file added tests/data/000051-007.secret_subkey
Binary file not shown.
Binary file added tests/data/000052-002.sig
Binary file not shown.
Binary file added tests/data/000053-012.ring_trust
Binary file not shown.
Binary file added tests/data/000054-005.secret_key
Binary file not shown.
Binary file added tests/data/000055-002.sig
Binary file not shown.
Binary file added tests/data/000056-012.ring_trust
Binary file not shown.
1 change: 1 addition & 0 deletions tests/data/000057-013.user_id
@@ -0,0 +1 @@
�$Test Key (DSA) <testkey@example.com>
Binary file added tests/data/000058-002.sig
Binary file not shown.
Binary file added tests/data/000059-012.ring_trust
Binary file not shown.
Binary file added tests/data/000060-007.secret_subkey
Binary file not shown.
Binary file added tests/data/000061-002.sig
Binary file not shown.
Binary file added tests/data/000062-012.ring_trust
Binary file not shown.
Binary file added tests/data/000063-005.secret_key
Binary file not shown.
Binary file added tests/data/000064-002.sig
Binary file not shown.
Binary file added tests/data/000065-012.ring_trust
Binary file not shown.
1 change: 1 addition & 0 deletions tests/data/000066-013.user_id
@@ -0,0 +1 @@
�+Test Key (DSA sign-only) <test@example.net>
Binary file added tests/data/000067-002.sig
Binary file not shown.
Binary file added tests/data/000068-012.ring_trust
Binary file not shown.
Binary file added tests/data/000069-005.secret_key
Binary file not shown.
1 change: 1 addition & 0 deletions tests/data/000070-013.user_id
@@ -0,0 +1 @@
�.Test Key (RSA sign-only) <testkey@example.net>
Binary file added tests/data/000071-002.sig
Binary file not shown.
Binary file added tests/data/000072-012.ring_trust
Binary file not shown.
Binary file added tests/data/000073-017.attribute
Binary file not shown.
Binary file added tests/data/000074-002.sig
Binary file not shown.
Binary file added tests/data/000075-012.ring_trust
Binary file not shown.
Binary file added tests/data/000076-007.secret_subkey
Binary file not shown.
Binary file added tests/data/000077-002.sig
Binary file not shown.
Binary file added tests/data/000078-012.ring_trust
Binary file not shown.
Binary file added tests/data/compressedsig-bzip2.gpg
Binary file not shown.
Binary file added tests/data/compressedsig-zlib.gpg
Binary file not shown.
Binary file added tests/data/compressedsig.gpg
Binary file not shown.
1 change: 1 addition & 0 deletions tests/data/encryption-sym-aes256.gpg
@@ -0,0 +1 @@
� ��'6*�W`�V�LE���Q�jNp(Y3��N*�?���!�M��*�*ۈ;�hL�2�+��!x�̄�&&\J{q���<16.�-�D ޿���
Expand Down
Binary file added tests/data/encryption-sym-cast5.gpg
Binary file not shown.
Binary file added tests/data/encryption.gpg
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/data/msg1.asc
@@ -0,0 +1,7 @@
-----BEGIN PGP MESSAGE-----
Version: OpenPrivacy 0.99

yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS
vBSFjNSiVHsuAA==
=njUN
-----END PGP MESSAGE-----
Binary file added tests/data/onepass_sig
Binary file not shown.
Binary file added tests/data/pubring.gpg
Binary file not shown.
Binary file added tests/data/secring.gpg
Binary file not shown.
Binary file added tests/data/uncompressed-ops-dsa-sha384.txt.gpg
Binary file not shown.
Binary file added tests/data/uncompressed-ops-dsa.gpg
Binary file not shown.
Binary file added tests/data/uncompressed-ops-rsa.gpg
Binary file not shown.
126 changes: 126 additions & 0 deletions tests/suite.hs
@@ -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.