From 3b5f198f7625cf6ddc50f2a54608c07726b4e923 Mon Sep 17 00:00:00 2001 From: Ansgar Burchardt Date: Tue, 2 Sep 2014 23:55:22 +0200 Subject: [PATCH] Add first unit tests for GnuPG wrapper. --- tests/fixtures/gpg/expired-subkey.asc | 13 ++++++ tests/fixtures/gpg/expired.asc | 13 ++++++ tests/fixtures/gpg/gnupghome/pubring.gpg | Bin 0 -> 1609 bytes tests/fixtures/gpg/gnupghome/secring.gpg | Bin 0 -> 2937 bytes tests/fixtures/gpg/valid.asc | 13 ++++++ tests/test_gpg.py | 57 +++++++++++++++++++++++ 6 files changed, 96 insertions(+) create mode 100644 tests/fixtures/gpg/expired-subkey.asc create mode 100644 tests/fixtures/gpg/expired.asc create mode 100644 tests/fixtures/gpg/gnupghome/pubring.gpg create mode 100644 tests/fixtures/gpg/gnupghome/secring.gpg create mode 100644 tests/fixtures/gpg/valid.asc create mode 100755 tests/test_gpg.py diff --git a/tests/fixtures/gpg/expired-subkey.asc b/tests/fixtures/gpg/expired-subkey.asc new file mode 100644 index 00000000..d105f6bd --- /dev/null +++ b/tests/fixtures/gpg/expired-subkey.asc @@ -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 index 00000000..42b52172 --- /dev/null +++ b/tests/fixtures/gpg/expired.asc @@ -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 index 0000000000000000000000000000000000000000..88d7e4db74ed0d9cc0baa58c81d97e368900f6ca GIT binary patch literal 1609 zcmajfcTm%37{Kx5mk_3eA;Tcb6evPi0c1(l2oh9eiBwP^j2MWBWflUmWJP630s=)4 zC`-Z+4jM+mvb3_11Y|{KSmlVUVj1=9U3=}H@7?pq`+nZem(GH^XSsNh`#ja>tryu3YK zRdEDACr=#KD5e1_3{fPjG$U_dMk z#KSFMt*=~0hhF6cR-vGw0tXP)%p@wmTFW;^lu;NVu<=`pO0ukGCd%N`cynuBYSijW zgc5R^#D)5-&eXSvHZ%C6aXW=*;NBoj$Jcdr$IEY?A!kW5drDr}BqI zWN6a2B1{sP5?aD0N--j|_HD@{S(PHRz;jQPc@_F4;qCqvZ$irf5QI#ETDF)M@99@+ z%PY0!RLNfZmb@OzMp_gT;bSP`YEo_S@hmy#H0H^i%*oh-mp%>OTZr~Uu64#)G6|O{ zT3Rx#9ZqpeF5T|f9nrL|wcCIEoTcY*vZEK1Hk6dHZFIIOpBR-8VpEE3jplK$PN5@d zAJ>C%1v9MCP>nWh8b*3$jeu`VKYOSzZ@W)>Xn&ym@A9<=@-iI2{^j@N|I@rH^QN8R zZ9=5rG-T%p-eNrY5qvPaywm)~(cy;y7bP4iJq%HQbn~QoGb>dh6;0MDg`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+q{(AU9+iujfd-FMF%n2NTy7z@LAVkJQyiFDlfDV?}T_!{i+whM47OBWg)k{9K ztPJIQ9GVJ|Q)`r!oFRUS_eurfHl#b_!zAClquT?Tt!;B+gcl@#<5%(`Rp4X3QjLrY zm&>@=Zhk7t?J(#L(lSLz!Q_pCA8p$BaFdlB1X30ncydE2scR<)4LQ9xc>R0an`FZA z=J`o}GDQ~)4{(UTN^Ifpa@ya2$N0|A`9FL7cggktPjW$sNYk!rA_28TaUwUd$7Ss4 zVMjS9JA?5`3NPbI&nU%J#CTSzp_QC+wT(Kn>wmTe-hPM*m9 zX3%+gM9H@-g~O5Fve|-d4dSQZD)t@*d$%wz@PP4M(yp$8YyFzA-=n22z4o!)CRFe>}vJyq%Ws$#Z3CE?MF6MXWa z9`m!=8dpC3t8etAhUA|mFe)EP=Ft)7K8n}^pmAv*JJx~%o6=~6%WFC3c4}6>Tx_+2f}@NDKPzPED?YMzb*w(IW6;F46yra{CS_lqch_TAbkKtMgp6VFt+OM0B36-BSUdMJs?>r_QWBhL zrT~T>Tg*jTl}x98yE1B^mC%wEZ=;&+V?0d#bfHsS +# +# 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() -- 2.39.5