]> git.decadent.org.uk Git - dak.git/commitdiff
Add first unit tests for GnuPG wrapper.
authorAnsgar Burchardt <ansgar@debian.org>
Tue, 2 Sep 2014 21:55:22 +0000 (23:55 +0200)
committerAnsgar Burchardt <ansgar@debian.org>
Tue, 2 Sep 2014 21:55:29 +0000 (23:55 +0200)
tests/fixtures/gpg/expired-subkey.asc [new file with mode: 0644]
tests/fixtures/gpg/expired.asc [new file with mode: 0644]
tests/fixtures/gpg/gnupghome/pubring.gpg [new file with mode: 0644]
tests/fixtures/gpg/gnupghome/secring.gpg [new file with mode: 0644]
tests/fixtures/gpg/valid.asc [new file with mode: 0644]
tests/test_gpg.py [new file with mode: 0755]

diff --git a/tests/fixtures/gpg/expired-subkey.asc b/tests/fixtures/gpg/expired-subkey.asc
new file mode 100644 (file)
index 0000000..d105f6b
--- /dev/null
@@ -0,0 +1,13 @@
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA512
+
+Valid: expired-subkey
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1
+
+iJwEAQEKAAYFAlLsQwMACgkQ+DxQkDe7kaCctQQAuzx+L6Bo+8oI9zTb04Cg2EAW
+ul4rN7XIqj3Q9/Cy2/+6+ET7GE414cA3KEElrimgAHHNdr6xPOJnEYAHSlMRG0wk
+gP9zk0nAt1ZJRgmWKb2zgbV6DYz7gAcUVaZMd+fixBdn39E3SkMnDHsUhWZNecsG
+BpSvYQJ7pQDnqo9gWbY=
+=AKH9
+-----END PGP SIGNATURE-----
diff --git a/tests/fixtures/gpg/expired.asc b/tests/fixtures/gpg/expired.asc
new file mode 100644 (file)
index 0000000..42b5217
--- /dev/null
@@ -0,0 +1,13 @@
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA512
+
+Valid: expired
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1
+
+iJwEAQEKAAYFAjp4sQMACgkQVDsrrtoETwtbowQAxZ+imlX8u44TCRaJmgSDx6dV
+G+BiNiM7RXbfoYD3jmKWX8ILdxBXyMP2YaPmtRij03h1q8idjol6mxGl2xBrOdbB
+hE7N+67MuvpGB1yBOb6JJQuqLALyoK+efzcqPBEJv3s0eeYbWkB4ZxWRhso1DDnm
+RYieWYyoR9/oNVhsBmE=
+=WR84
+-----END PGP SIGNATURE-----
diff --git a/tests/fixtures/gpg/gnupghome/pubring.gpg b/tests/fixtures/gpg/gnupghome/pubring.gpg
new file mode 100644 (file)
index 0000000..88d7e4d
Binary files /dev/null and b/tests/fixtures/gpg/gnupghome/pubring.gpg differ
diff --git a/tests/fixtures/gpg/gnupghome/secring.gpg b/tests/fixtures/gpg/gnupghome/secring.gpg
new file mode 100644 (file)
index 0000000..a524519
Binary files /dev/null and b/tests/fixtures/gpg/gnupghome/secring.gpg differ
diff --git a/tests/fixtures/gpg/valid.asc b/tests/fixtures/gpg/valid.asc
new file mode 100644 (file)
index 0000000..2daae47
--- /dev/null
@@ -0,0 +1,13 @@
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA512
+
+Valid: yes
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1
+
+iJwEAQEKAAYFAlQGNXoACgkQy51cWChgboRrDAP9E/cwAQgF5BpzIEN5Wnus4mf0
+L4QdVPXCVjU4f8YS4FKali0++shPRFxgqBhWaOT9XFR9y0+ZzHjfcXffY0loYMQ6
+JCZdIK0lQ4aPDFqX6892+Aka0ZaijL+20yd9IE+9E7M7rCCW+PgVFRIIKnB7Eyc2
+MkCGwQ91CAOjErXnZPw=
+=UsYp
+-----END PGP SIGNATURE-----
diff --git a/tests/test_gpg.py b/tests/test_gpg.py
new file mode 100755 (executable)
index 0000000..8f752f6
--- /dev/null
@@ -0,0 +1,57 @@
+#! /usr/bin/env python
+#
+# Copyright (C) 2014, Ansgar Burchardt <ansgar@debian.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import unittest
+from base_test import DakTestCase, fixture
+from daklib.gpg import GpgException, SignedFile
+
+keyring = fixture('gpg/gnupghome/pubring.gpg')
+fpr_valid = '0ABB89079CB58F8F94F6F310CB9D5C5828606E84'
+fpr_expired = '05A558AE65B77B559BBE0C4D543B2BAEDA044F0B'
+fpr_expired_subkey = '8865D9EC71713394ADBD8F729F7A24B7F6388CE1'
+
+def verify(filename, require_signature=True):
+    with open(fixture(filename)) as fh:
+        data = fh.read()
+    return SignedFile(data, [keyring], require_signature)
+
+class GpgTest(DakTestCase):
+    def test_valid(self):
+        result = verify('gpg/valid.asc')
+        self.assertTrue(result.valid)
+        self.assertEqual(result.primary_fingerprint, fpr_valid)
+        self.assertEqual(result.contents, "Valid: yes\n")
+
+    def test_expired(self):
+        result = verify('gpg/expired.asc', False)
+        self.assertFalse(result.valid)
+        self.assertEqual(result.primary_fingerprint, fpr_expired)
+        self.assertEqual(result.contents, "Valid: expired\n")
+
+    def test_expired_assertion(self):
+        with self.assertRaises(GpgException):
+            verify('gpg/expired.asc')
+
+    def test_expired_subkey(self):
+        result = verify('gpg/expired-subkey.asc', False)
+        self.assertFalse(result.valid)
+        self.assertEqual(result.primary_fingerprint, fpr_expired_subkey)
+        self.assertEqual(result.contents, "Valid: expired-subkey\n")
+
+if __name__ == '__main__':
+    unittest.main()