Skip to content

Commit fe7f125

Browse files
author
Lukas Puehringer
committed
Separate test builds w/o native libs and w/o gpg
Update tox and travis configuration to run tests - with all extra dependencies and gpg (if available) - without native dependencies (i.e. cryptography and nacl) - without gpg Previously the latter two were combined. The separation allows for more fine grained testing of the gpg subpackage whose, signature creation and key export function should fail on both, missing gpg and missing cryptography library (with different error messages), whereas the signature verification function should only fail if the cryptography library is missing.
1 parent d1d2fda commit fe7f125

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ matrix:
88
env: TOXENV=py27
99
- python: "2.7"
1010
env: TOXENV=purepy27
11+
- python: "2.7"
12+
env: TOXENV=py27-no-gpg
1113
before_install:
1214
- sudo apt-get remove -y --allow-remove-essential gnupg gnupg2
1315
- python: "3.5"
@@ -20,8 +22,10 @@ matrix:
2022
env: TOXENV=py38
2123
- python: "3.8"
2224
env: TOXENV=purepy38
25+
- python: "3.8"
26+
env: TOXENV=py38-no-gpg
2327
before_install:
24-
- sudo apt-get remove -y --allow-remove-essential gnupg gnupg2
28+
- sudo apt-get remove -y --allow-remove-essential gnupg gnupg2
2529

2630
install:
2731
- pip install -U tox coveralls

tests/check_public_interfaces.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,23 @@ def test_purepy_ed25519(self):
193193
pub, 'ed25519', bsig, data)
194194
self.assertEqual(False, invalid)
195195

196-
def test_gpg_cmds(self):
197-
"""Ensure functions calling GPG commands throw an appropriate error"""
196+
def test_gpg_functions(self):
197+
"""Public GPG functions must raise error on missing cryptography lib. """
198+
expected_error = securesystemslib.exceptions.UnsupportedLibraryError
199+
expected_error_msg = securesystemslib.gpg.functions.NO_CRYPTO_MSG
198200

199-
with self.assertRaises(securesystemslib.exceptions.UnsupportedLibraryError):
201+
with self.assertRaises(expected_error) as ctx:
200202
securesystemslib.gpg.functions.create_signature('bar')
203+
self.assertEqual(expected_error_msg, str(ctx.exception))
201204

202-
with self.assertRaises(securesystemslib.exceptions.UnsupportedLibraryError):
205+
with self.assertRaises(expected_error) as ctx:
203206
securesystemslib.gpg.functions.verify_signature(None, 'f00', 'bar')
207+
self.assertEqual(expected_error_msg, str(ctx.exception))
204208

205-
with self.assertRaises(securesystemslib.exceptions.UnsupportedLibraryError):
209+
with self.assertRaises(expected_error) as ctx:
206210
securesystemslib.gpg.functions.export_pubkey('f00')
211+
self.assertEqual(expected_error_msg, str(ctx.exception))
207212

208-
with self.assertRaises(securesystemslib.exceptions.UnsupportedLibraryError):
209-
securesystemslib.gpg.util.get_version()
210213

211214

212215
if __name__ == '__main__':

tox.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,13 @@ deps =
3232

3333
commands =
3434
python -m tests.check_public_interfaces
35+
36+
# Below test envs require manual removal of gpg on the host system (see
37+
# .travis.yml) and are excluded from the default tox run
38+
[testenv:py27-no-gpg]
39+
commands =
40+
python -m tests.check_public_interfaces_gpg
41+
42+
[testenv:py38-no-gpg]
43+
commands =
44+
python -m tests.check_public_interfaces_gpg

0 commit comments

Comments
 (0)