X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=tests%2Ftest_gpg.py;fp=tests%2Ftest_gpg.py;h=8f752f66d428235009768661b4545623cc1fdc41;hb=3b5f198f7625cf6ddc50f2a54608c07726b4e923;hp=0000000000000000000000000000000000000000;hpb=bc2a2a5909f657dcc83c992b1f113dbff7bb1e9c;p=dak.git diff --git a/tests/test_gpg.py b/tests/test_gpg.py new file mode 100755 index 00000000..8f752f66 --- /dev/null +++ b/tests/test_gpg.py @@ -0,0 +1,57 @@ +#! /usr/bin/env python +# +# Copyright (C) 2014, Ansgar Burchardt +# +# 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()