Skip to content

Commit b70d397

Browse files
authored
fix: move calls requiring integ test environment setup from test setup to inside test body (#256)
* chore: fix 'nocmk' test environment to block environment variables again * fix: move calls requiring integ test environment setup from test parameterization setup to inside test body * fix: fix broken parameter reconfiguration
1 parent 00fcfe7 commit b70d397

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

test/integration/test_client.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,41 @@
2727
}
2828

2929

30+
def _generate_mkp():
31+
"""Isolated inside a function to avoid calling get_cmk_arn during test discovery."""
32+
return setup_kms_master_key_provider().master_key(get_cmk_arn())
33+
34+
3035
@pytest.mark.parametrize(
31-
"kwargs",
36+
"parameter_name, value_partial",
3237
(
33-
pytest.param(dict(key_provider=setup_kms_master_key_provider()), id="AWS KMS master key provider"),
34-
pytest.param(
35-
dict(key_provider=setup_kms_master_key_provider().master_key(get_cmk_arn())), id="AWS KMS master key"
36-
),
37-
pytest.param(dict(keyring=build_aws_kms_keyring()), id="AWS KMS keyring"),
38+
pytest.param("key_provider", setup_kms_master_key_provider, id="AWS KMS master key provider"),
39+
pytest.param("key_provider", _generate_mkp, id="AWS KMS master key"),
40+
pytest.param("keyring", build_aws_kms_keyring, id="AWS KMS keyring"),
3841
),
3942
)
40-
def test_encrypt_verify_user_agent_in_logs(caplog, kwargs):
43+
def test_encrypt_verify_user_agent_in_logs(caplog, parameter_name, value_partial):
4144
caplog.set_level(level=logging.DEBUG)
4245

43-
aws_encryption_sdk.encrypt(source=VALUES["plaintext_128"], **kwargs)
46+
aws_encryption_sdk.encrypt(source=VALUES["plaintext_128"], **{parameter_name: value_partial()})
4447

4548
assert USER_AGENT_SUFFIX in caplog.text
4649

4750

4851
@pytest.mark.parametrize("frame_size", (pytest.param(0, id="unframed"), pytest.param(1024, id="1024 byte frame")))
4952
@pytest.mark.parametrize("algorithm_suite", Algorithm)
5053
@pytest.mark.parametrize(
51-
"encrypt_key_provider_kwargs",
54+
"encrypt_key_provider_param, encrypt_key_provider_partial",
5255
(
53-
pytest.param(dict(key_provider=setup_kms_master_key_provider()), id="encrypt with MKP"),
54-
pytest.param(dict(keyring=build_aws_kms_keyring()), id="encrypt with keyring"),
56+
pytest.param("key_provider", setup_kms_master_key_provider, id="encrypt with MKP"),
57+
pytest.param("keyring", build_aws_kms_keyring, id="encrypt with keyring"),
5558
),
5659
)
5760
@pytest.mark.parametrize(
58-
"decrypt_key_provider_kwargs",
61+
"decrypt_key_provider_param, decrypt_key_provider_partial",
5962
(
60-
pytest.param(dict(key_provider=setup_kms_master_key_provider()), id="decrypt with MKP"),
61-
pytest.param(dict(keyring=build_aws_kms_keyring()), id="decrypt with keyring"),
63+
pytest.param("key_provider", setup_kms_master_key_provider, id="decrypt with MKP"),
64+
pytest.param("keyring", build_aws_kms_keyring, id="decrypt with keyring"),
6265
),
6366
)
6467
@pytest.mark.parametrize(
@@ -76,16 +79,25 @@ def test_encrypt_verify_user_agent_in_logs(caplog, kwargs):
7679
),
7780
)
7881
def test_encrypt_decrypt_cycle_aws_kms(
79-
frame_size, algorithm_suite, encrypt_key_provider_kwargs, decrypt_key_provider_kwargs, encryption_context, plaintext
82+
frame_size,
83+
algorithm_suite,
84+
encrypt_key_provider_param,
85+
encrypt_key_provider_partial,
86+
decrypt_key_provider_param,
87+
decrypt_key_provider_partial,
88+
encryption_context,
89+
plaintext,
8090
):
8191
ciphertext, _ = aws_encryption_sdk.encrypt(
8292
source=plaintext,
8393
encryption_context=encryption_context,
8494
frame_length=frame_size,
8595
algorithm=algorithm_suite,
86-
**encrypt_key_provider_kwargs
96+
**{encrypt_key_provider_param: encrypt_key_provider_partial()}
97+
)
98+
decrypted, _ = aws_encryption_sdk.decrypt(
99+
source=ciphertext, **{decrypt_key_provider_param: decrypt_key_provider_partial()}
87100
)
88-
decrypted, _ = aws_encryption_sdk.decrypt(source=ciphertext, **decrypt_key_provider_kwargs)
89101
assert decrypted == plaintext
90102

91103

tox.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ commands =
6161
[testenv:nocmk]
6262
basepython = python3
6363
sitepackages = False
64+
#########################################################
65+
# Do not pass through or set any environment variables! #
66+
passenv =
67+
setenv =
68+
#########################################################
6469
deps = -rtest/requirements.txt
6570
commands = {[testenv:base-command]commands} test/ -m local
6671

0 commit comments

Comments
 (0)