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:
parent
fe96cfce28
commit
e5ff95d09c
1 changed files with 27 additions and 0 deletions
|
@ -8,6 +8,7 @@ import os
|
||||||
import platform
|
import platform
|
||||||
import pwd
|
import pwd
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@ -544,3 +545,29 @@ def ds1(ds1_work_copy, paths, ds1_dset):
|
||||||
dscopy = copy.deepcopy(ds1_dset)
|
dscopy = copy.deepcopy(ds1_dset)
|
||||||
dscopy.relative_to(copy.deepcopy(paths.work))
|
dscopy.relative_to(copy.deepcopy(paths.work))
|
||||||
return dscopy
|
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)
|
||||||
|
|
Loading…
Reference in a new issue