Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/cwltool/tests/test_secrets.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
| author | shellac |
|---|---|
| date | Sat, 02 May 2020 07:14:21 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:26e78fe6e8c4 |
|---|---|
| 1 import shutil | |
| 2 import sys | |
| 3 import tempfile | |
| 4 import pytest | |
| 5 from cwltool.secrets import SecretStore | |
| 6 from cwltool.main import main | |
| 7 from .util import (get_data, needs_docker, needs_singularity, | |
| 8 windows_needs_docker) | |
| 9 from io import StringIO | |
| 10 | |
| 11 | |
| 12 @pytest.fixture | |
| 13 def secrets(): | |
| 14 sec_store = SecretStore() | |
| 15 job = {'foo': 'bar', | |
| 16 'baz': 'quux'} | |
| 17 | |
| 18 sec_store.store(['foo'], job) | |
| 19 return sec_store, job | |
| 20 | |
| 21 def test_obscuring(secrets): | |
| 22 storage, obscured = secrets | |
| 23 assert obscured['foo'] != 'bar' | |
| 24 assert obscured['baz'] == 'quux' | |
| 25 assert storage.retrieve(obscured)['foo'] == 'bar' | |
| 26 | |
| 27 obscured_factories_expected = [ | |
| 28 ((lambda x: 'hello %s' % x), 'hello bar'), | |
| 29 ((lambda x: ['echo', 'hello %s' % x]), ['echo', 'hello bar']), | |
| 30 ((lambda x: {'foo': x}), {'foo': 'bar'}), | |
| 31 ] | |
| 32 | |
| 33 @pytest.mark.parametrize('factory,expected', obscured_factories_expected) | |
| 34 def test_secrets(factory, expected, secrets): | |
| 35 storage, obscured = secrets | |
| 36 pattern = factory(obscured['foo']) | |
| 37 assert pattern != expected | |
| 38 | |
| 39 assert storage.has_secret(pattern) | |
| 40 assert storage.retrieve(pattern) == expected | |
| 41 | |
| 42 assert obscured['foo'] != 'bar' | |
| 43 assert obscured['baz'] == 'quux' | |
| 44 | |
| 45 @needs_docker | |
| 46 def test_secret_workflow_log(): | |
| 47 stream = StringIO() | |
| 48 tmpdir = tempfile.mkdtemp() | |
| 49 main(["--debug", "--enable-ext", "--outdir", tmpdir, | |
| 50 get_data("tests/wf/secret_wf.cwl"), "--pw", "Hoopla!"], | |
| 51 stderr=stream) | |
| 52 | |
| 53 shutil.rmtree(tmpdir) | |
| 54 assert "Hoopla!" not in stream.getvalue() | |
| 55 | |
| 56 @needs_singularity | |
| 57 def test_secret_workflow_log_singularity(): | |
| 58 stream = StringIO() | |
| 59 tmpdir = tempfile.mkdtemp() | |
| 60 main(["--debug", "--outdir", tmpdir, "--singularity", | |
| 61 get_data("tests/wf/secret_wf.cwl"), "--pw", "Hoopla!"], | |
| 62 stderr=stream) | |
| 63 | |
| 64 shutil.rmtree(tmpdir) | |
| 65 assert "Hoopla!" not in stream.getvalue() | |
| 66 | |
| 67 @needs_docker | |
| 68 def test_secret_workflow_log_override(): | |
| 69 stream = StringIO() | |
| 70 tmpdir = tempfile.mkdtemp() | |
| 71 main(["--debug", "--outdir", tmpdir, "--enable-ext", "--overrides", | |
| 72 get_data("tests/wf/override-no-secrets.yml"), | |
| 73 get_data("tests/wf/secret_wf.cwl"), "--pw", "Hoopla!"], | |
| 74 stderr=stream) | |
| 75 shutil.rmtree(tmpdir) | |
| 76 | |
| 77 assert "Hoopla!" in stream.getvalue() |
