Create gnupg fixture

This fixture is a session scoped gnupg home directory, along with a
method to set the mocked password which will be used by the
pinentry-mock program.
This commit is contained in:
Tim Byrne 2019-11-30 20:16:44 -06:00
parent fe96cfce28
commit e5ff95d09c
No known key found for this signature in database
GPG Key ID: 14DB4FC2465A4B12
1 changed files with 27 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import os
import platform
import pwd
from subprocess import Popen, PIPE
import py
import pytest
@ -544,3 +545,29 @@ def ds1(ds1_work_copy, paths, ds1_dset):
dscopy = copy.deepcopy(ds1_dset)
dscopy.relative_to(copy.deepcopy(paths.work))
return dscopy
@pytest.fixture(scope='session')
def gnupg(tmpdir_factory, runner):
"""Location of GNUPGHOME"""
def register_gpg_password(password):
"""Publish a new GPG mock password"""
py.path.local('/tmp/mock-password').write(password)
home = tmpdir_factory.mktemp('gnupghome')
home.chmod(0o700)
conf = home.join('gpg-agent.conf')
conf.write(
f'pinentry-program {os.path.abspath("test/pinentry-mock")}\n'
'max-cache-ttl 0\n'
)
conf.chmod(0o600)
data = collections.namedtuple('GNUPG', ['home', 'pw'])
env = os.environ.copy()
env['GNUPGHOME'] = home
# this pre-populates std files in the GNUPGHOME
runner(['gpg', '-k'], env=env)
return data(home, register_gpg_password)