Adding safety test for keyrings.

This commit is contained in:
2022-01-19 18:01:29 -06:00
parent 5b9f6ec79d
commit e74a77387f
2 changed files with 30 additions and 0 deletions

28
tests/test_gpg.py Normal file
View File

@@ -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 <ircs://aninix.net:6697/DarkFeather>' not in publickeys.stdout:
assertion = False
print('Did not find the public key.')
print(publickeys.stdout)
shutil.rmtree(testdir)
assert assertion