]> git.donarmstrong.com Git - dak.git/blob - tests/test_gpg.py
8f752f66d428235009768661b4545623cc1fdc41
[dak.git] / tests / test_gpg.py
1 #! /usr/bin/env python
2 #
3 # Copyright (C) 2014, Ansgar Burchardt <ansgar@debian.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 import unittest
20 from base_test import DakTestCase, fixture
21 from daklib.gpg import GpgException, SignedFile
22
23 keyring = fixture('gpg/gnupghome/pubring.gpg')
24 fpr_valid = '0ABB89079CB58F8F94F6F310CB9D5C5828606E84'
25 fpr_expired = '05A558AE65B77B559BBE0C4D543B2BAEDA044F0B'
26 fpr_expired_subkey = '8865D9EC71713394ADBD8F729F7A24B7F6388CE1'
27
28 def verify(filename, require_signature=True):
29     with open(fixture(filename)) as fh:
30         data = fh.read()
31     return SignedFile(data, [keyring], require_signature)
32
33 class GpgTest(DakTestCase):
34     def test_valid(self):
35         result = verify('gpg/valid.asc')
36         self.assertTrue(result.valid)
37         self.assertEqual(result.primary_fingerprint, fpr_valid)
38         self.assertEqual(result.contents, "Valid: yes\n")
39
40     def test_expired(self):
41         result = verify('gpg/expired.asc', False)
42         self.assertFalse(result.valid)
43         self.assertEqual(result.primary_fingerprint, fpr_expired)
44         self.assertEqual(result.contents, "Valid: expired\n")
45
46     def test_expired_assertion(self):
47         with self.assertRaises(GpgException):
48             verify('gpg/expired.asc')
49
50     def test_expired_subkey(self):
51         result = verify('gpg/expired-subkey.asc', False)
52         self.assertFalse(result.valid)
53         self.assertEqual(result.primary_fingerprint, fpr_expired_subkey)
54         self.assertEqual(result.contents, "Valid: expired-subkey\n")
55
56 if __name__ == '__main__':
57     unittest.main()