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