From e74a77387f74d21da405cc45bae33f4f818963db Mon Sep 17 00:00:00 2001 From: DarkFeather Date: Wed, 19 Jan 2022 18:01:29 -0600 Subject: [PATCH] Adding safety test for keyrings. --- .gitignore | 2 ++ tests/test_gpg.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/test_gpg.py diff --git a/.gitignore b/.gitignore index a006ce3..c2de7da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ src/ pkg/ +__pycache__ +*.pyc *.tar.xz *.tar.zst diff --git a/tests/test_gpg.py b/tests/test_gpg.py new file mode 100644 index 0000000..b459021 --- /dev/null +++ b/tests/test_gpg.py @@ -0,0 +1,28 @@ +import os +import pytest +import shutil +import subprocess + + +def test_gpg_key_import(): + testdir = './gpg2-testdir' + os.mkdir(testdir) + assertion = True + # Import the key + subprocess.run(['gpg2','--no-permission-warning','--homedir',testdir,'--import','EtcFiles/aninix.gpg'],stdout=subprocess.PIPE) + + # Check for private keys -- should not disclose these. + privatekeys = subprocess.run(['gpg2','--no-permission-warning','--homedir','./gpg2-testdir','-K'],stdout=subprocess.PIPE) + if privatekeys.stdout != b'': + assertion = False + print('Private key should not be included in the GPG key.') + print(privatekeys.stdout) + + # Check for public keys -- need to disclose these. + publickeys = subprocess.run(['gpg2','--no-permission-warning','--homedir',testdir,'-k'],stdout=subprocess.PIPE) + if b'904DE6275579CB589D85720C1CC1E3F4ED06F296' not in publickeys.stdout or b'DarkFeather ' not in publickeys.stdout: + assertion = False + print('Did not find the public key.') + print(publickeys.stdout) + shutil.rmtree(testdir) + assert assertion