2020-02-21 14:05:56 +00:00
|
|
|
"""Test external encryption commands"""
|
2019-12-16 00:42:21 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'crypt',
|
|
|
|
[False, 'installed', 'installed-but-failed'],
|
|
|
|
ids=['not-installed', 'installed', 'installed-but-failed']
|
|
|
|
)
|
2020-02-21 14:05:56 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'cmd,var', [
|
|
|
|
['git_crypt', 'GIT_CRYPT_PROGRAM'],
|
|
|
|
['transcrypt', 'TRANSCRYPT_PROGRAM'],
|
|
|
|
],
|
|
|
|
ids=['git-crypt', 'transcrypt'])
|
|
|
|
def test_ext_encryption(runner, yadm, paths, tmpdir, crypt, cmd, var):
|
|
|
|
"""External encryption tests"""
|
2019-12-16 00:42:21 +00:00
|
|
|
|
|
|
|
paths.repo.ensure(dir=True)
|
|
|
|
bindir = tmpdir.mkdir('bin')
|
2020-02-21 14:05:56 +00:00
|
|
|
pgm = bindir.join('test-ext-crypt')
|
2019-12-16 00:42:21 +00:00
|
|
|
|
|
|
|
if crypt:
|
2020-02-21 14:05:56 +00:00
|
|
|
pgm.write(f'#!/bin/sh\necho ext-crypt ran\n')
|
2019-12-16 00:42:21 +00:00
|
|
|
pgm.chmod(0o775)
|
|
|
|
if crypt == 'installed-but-failed':
|
|
|
|
pgm.write('false\n', mode='a')
|
|
|
|
|
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {yadm}
|
|
|
|
YADM_REPO={paths.repo}
|
2020-02-21 14:05:56 +00:00
|
|
|
{var}="{pgm}"
|
|
|
|
{cmd} "param1"
|
2019-12-16 00:42:21 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
run = runner(command=['bash'], inp=script)
|
|
|
|
|
|
|
|
if crypt:
|
|
|
|
if crypt == 'installed-but-failed':
|
|
|
|
assert run.failure
|
|
|
|
else:
|
|
|
|
assert run.success
|
2020-02-21 14:05:56 +00:00
|
|
|
assert run.out.strip() == 'ext-crypt ran'
|
2019-12-16 00:42:21 +00:00
|
|
|
else:
|
|
|
|
assert run.failure
|
|
|
|
assert f"command '{pgm}' cannot be located" in run.out
|
|
|
|
assert run.err == ''
|