diff options
-rw-r--r-- | b4/__init__.py | 12 | ||||
-rw-r--r-- | tests/__init__.py | 0 | ||||
-rw-r--r-- | tests/samples/gpg-badsig.txt | 8 | ||||
-rw-r--r-- | tests/samples/gpg-good-invalid-notrust.txt | 19 | ||||
-rw-r--r-- | tests/samples/gpg-good-valid-notrust.txt | 20 | ||||
-rw-r--r-- | tests/samples/gpg-good-valid-trusted.txt | 20 | ||||
-rw-r--r-- | tests/samples/gpg-no-pubkey.txt | 3 | ||||
-rw-r--r-- | tests/test___init__.py | 15 |
8 files changed, 94 insertions, 3 deletions
diff --git a/b4/__init__.py b/b4/__init__.py index d69f80e..2572017 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -2277,20 +2277,26 @@ def parse_int_range(intrange, upper=None): logger.critical('Unknown range value specified: %s', n) -def check_gpg_status(status: str) -> Tuple[bool, bool, bool, str, str]: +def check_gpg_status(status: str) -> Tuple[bool, bool, bool, Optional[str], Optional[str]]: good = False valid = False trusted = False keyid = None - signtime = '' + signtime = None + + # Do we have a BADSIG? + bs_matches = re.search(r'^\[GNUPG:] BADSIG ([0-9A-F]+)\s+(.*)$', status, flags=re.M) + if bs_matches: + keyid = bs_matches.groups()[0] + return good, valid, trusted, keyid, signtime gs_matches = re.search(r'^\[GNUPG:] GOODSIG ([0-9A-F]+)\s+(.*)$', status, flags=re.M) if gs_matches: good = True + keyid = gs_matches.groups()[0] vs_matches = re.search(r'^\[GNUPG:] VALIDSIG ([0-9A-F]+) (\d{4}-\d{2}-\d{2}) (\d+)', status, flags=re.M) if vs_matches: valid = True - keyid = vs_matches.groups()[0] signtime = vs_matches.groups()[2] ts_matches = re.search(r'^\[GNUPG:] TRUST_(FULLY|ULTIMATE)', status, flags=re.M) if ts_matches: diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/__init__.py diff --git a/tests/samples/gpg-badsig.txt b/tests/samples/gpg-badsig.txt new file mode 100644 index 0000000..d53e4cf --- /dev/null +++ b/tests/samples/gpg-badsig.txt @@ -0,0 +1,8 @@ +[GNUPG:] NEWSIG +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] BADSIG B6C41CE35664996C Konstantin Ryabitsev <konstantin@linuxfoundation.org> diff --git a/tests/samples/gpg-good-invalid-notrust.txt b/tests/samples/gpg-good-invalid-notrust.txt new file mode 100644 index 0000000..e531d78 --- /dev/null +++ b/tests/samples/gpg-good-invalid-notrust.txt @@ -0,0 +1,19 @@ +[GNUPG:] NEWSIG +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] SIG_ID 5clUiMzlfE8KIyEu++mBk6I0Rnc 2021-06-09 1623274836 +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] GOODSIG B6C41CE35664996C Konstantin Ryabitsev <konstantin@linuxfoundation.org> +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] TRUST_UNDEFINED 0 tofu diff --git a/tests/samples/gpg-good-valid-notrust.txt b/tests/samples/gpg-good-valid-notrust.txt new file mode 100644 index 0000000..aacb4f8 --- /dev/null +++ b/tests/samples/gpg-good-valid-notrust.txt @@ -0,0 +1,20 @@ +[GNUPG:] NEWSIG +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] SIG_ID 5clUiMzlfE8KIyEu++mBk6I0Rnc 2021-06-09 1623274836 +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] GOODSIG B6C41CE35664996C Konstantin Ryabitsev <konstantin@linuxfoundation.org> +[GNUPG:] VALIDSIG 76BE5DB25271E1481E678C35B6C41CE35664996C 2021-06-09 1623274836 0 4 0 22 8 01 DE0E66E32F1FDD0902666B96E63EDCA9329DD07E +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] TRUST_UNDEFINED 0 tofu diff --git a/tests/samples/gpg-good-valid-trusted.txt b/tests/samples/gpg-good-valid-trusted.txt new file mode 100644 index 0000000..26e7914 --- /dev/null +++ b/tests/samples/gpg-good-valid-trusted.txt @@ -0,0 +1,20 @@ +[GNUPG:] NEWSIG +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] SIG_ID 5clUiMzlfE8KIyEu++mBk6I0Rnc 2021-06-09 1623274836 +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] GOODSIG B6C41CE35664996C Konstantin Ryabitsev <konstantin@linuxfoundation.org> +[GNUPG:] VALIDSIG 76BE5DB25271E1481E678C35B6C41CE35664996C 2021-06-09 1623274836 0 4 0 22 8 01 DE0E66E32F1FDD0902666B96E63EDCA9329DD07E +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] KEYEXPIRED 1446574742 +[GNUPG:] KEYEXPIRED 1525881230 +[GNUPG:] KEY_CONSIDERED DE0E66E32F1FDD0902666B96E63EDCA9329DD07E 0 +[GNUPG:] TRUST_ULTIMATE 0 tofu diff --git a/tests/samples/gpg-no-pubkey.txt b/tests/samples/gpg-no-pubkey.txt new file mode 100644 index 0000000..5026191 --- /dev/null +++ b/tests/samples/gpg-no-pubkey.txt @@ -0,0 +1,3 @@ +[GNUPG:] NEWSIG +[GNUPG:] ERRSIG B6C41CE35664996C 22 8 01 1623274836 9 76BE5DB25271E1481E678C35B6C41CE35664996C +[GNUPG:] NO_PUBKEY B6C41CE35664996C diff --git a/tests/test___init__.py b/tests/test___init__.py new file mode 100644 index 0000000..5a09584 --- /dev/null +++ b/tests/test___init__.py @@ -0,0 +1,15 @@ +import pytest # noqa +import b4 + + +@pytest.mark.parametrize('source,expected', [ + ('good-valid-trusted', (True, True, True, 'B6C41CE35664996C', '1623274836')), + ('good-valid-notrust', (True, True, False, 'B6C41CE35664996C', '1623274836')), + ('good-invalid-notrust', (True, False, False, 'B6C41CE35664996C', None)), + ('badsig', (False, False, False, 'B6C41CE35664996C', None)), + ('no-pubkey', (False, False, False, None, None)), +]) +def test_check_gpg_status(source, expected): + with open(f'tests/samples/gpg-{source}.txt', 'r') as fh: + status = fh.read() + assert b4.check_gpg_status(status) == expected |