Adding safety test for keyrings.

This commit is contained in:
DarkFeather 2022-01-19 18:01:29 -06:00
parent 5b9f6ec79d
commit e74a77387f
Signed by: DarkFeather
GPG Key ID: 1CC1E3F4ED06F296
2 changed files with 30 additions and 0 deletions

2
.gitignore vendored
View File

@ -1,4 +1,6 @@
src/ src/
pkg/ pkg/
__pycache__
*.pyc
*.tar.xz *.tar.xz
*.tar.zst *.tar.zst

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