Skip to content

Commit fd9b189

Browse files
committed
Make functional test fixtures SSM-only (remove file output)
Remove the file-based fixture environment export to avoid clear-text secret storage and keep fixture distribution via SSM parameters only, with tests and command help text aligned to this behavior.
1 parent 737910d commit fd9b189

File tree

3 files changed

+13
-35
lines changed

3 files changed

+13
-35
lines changed

app/commands.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,8 +858,6 @@ def functional_test_fixtures():
858858
859859
REQUEST_BIN_API_TOKEN - request bin token to be used by functional tests
860860
861-
FUNCTIONAL_TEST_ENV_FILE - (optional) output file for the environment variables
862-
863861
SSM_UPLOAD_PATH - (optional) path to upload the environment variables to AWS SSM
864862
865863
PERFORMANCE_SSM_UPLOAD_PATH - (optional) path to upload performance-only environment variables to AWS SSM

app/functional_tests_fixtures/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,6 @@ def apply_fixtures():
152152
functional_test_config = "\n".join(f"export {k}='{v}'" for k, v in functional_env_var_dict.items())
153153
performance_test_config = "\n".join(f"export {k}='{v}'" for k, v in performance_env_var_dict.items())
154154

155-
functional_test_env_file = os.getenv("FUNCTIONAL_TEST_ENV_FILE", "/tmp/functional_test_env.sh")
156-
if functional_test_env_file != "":
157-
with open(functional_test_env_file, "w") as f:
158-
f.write(functional_test_config)
159-
160155
ssm_upload_path = os.getenv("SSM_UPLOAD_PATH")
161156
if ssm_upload_path:
162157
_upload_env_to_ssm(ssm_upload_path, functional_test_config, "functional test environment")

tests/app/functional_test_fixtures/test_functional_test_fixtures.py

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import os
2-
import re
32
from datetime import datetime, timedelta
4-
from tempfile import NamedTemporaryFile
53

64
import boto3
75
import pytest
@@ -179,36 +177,25 @@ def test_create_db_objects_creates_dedicated_performance_service_with_limits_and
179177

180178

181179
@mock_aws
182-
def test_function_test_fixtures_saves_to_disk_and_ssm(notify_api, os_environ, mocker):
180+
def test_function_test_fixtures_uploads_to_ssm(notify_api, os_environ, mocker):
183181
mocker.patch(
184182
"app.functional_tests_fixtures._create_db_objects",
185-
return_value=({"FOO": "BAR", "BAZ": "WAZ"}, {}),
183+
return_value=({"FOO": "BAR", "PASSWORD": "super-secret", "TOKEN": "abc123"}, {}),
186184
)
187185

188-
with NamedTemporaryFile() as temp_file:
189-
temp_file_name = temp_file.name
190-
191-
os.environ["FUNCTIONAL_TEST_ENV_FILE"] = temp_file_name
192-
os.environ["SSM_UPLOAD_PATH"] = "/test/ssm/environment"
193-
# AWS are changing from AWS_DEFAULT_REGION to AWS_REGION for v2 clients. Set both for now.
194-
os.environ["AWS_REGION"] = "eu-west-1"
195-
os.environ["AWS_DEFAULT_REGION"] = "eu-west-1"
196-
197-
apply_fixtures()
186+
os.environ["SSM_UPLOAD_PATH"] = "/test/ssm/environment"
187+
# AWS are changing from AWS_DEFAULT_REGION to AWS_REGION for v2 clients. Set both for now.
188+
os.environ["AWS_REGION"] = "eu-west-1"
189+
os.environ["AWS_DEFAULT_REGION"] = "eu-west-1"
198190

199-
variables = {}
200-
full_file = ""
201-
with open(temp_file_name) as f:
202-
full_file = f.read()
203-
for line in full_file.splitlines():
204-
match = re.match(r"export (?P<key>[A-Z0-9_]+)='(?P<value>[^']+)'", line)
205-
variables[match["key"]] = match["value"]
206-
assert variables == {"FOO": "BAR", "BAZ": "WAZ"}
191+
apply_fixtures()
207192

208-
# test that the SSM parameter was created and contains the same as the file
209-
ssm = boto3.client("ssm")
210-
response = ssm.get_parameter(Name="/test/ssm/environment", WithDecryption=True)
211-
assert response["Parameter"]["Value"] == full_file
193+
# test that the SSM parameter was created and contains full content
194+
ssm = boto3.client("ssm")
195+
response = ssm.get_parameter(Name="/test/ssm/environment", WithDecryption=True)
196+
assert "export FOO='BAR'" in response["Parameter"]["Value"]
197+
assert "export PASSWORD='super-secret'" in response["Parameter"]["Value"]
198+
assert "export TOKEN='abc123'" in response["Parameter"]["Value"]
212199

213200

214201
def test_function_test_fixtures_raises_clear_error_when_ssm_upload_fails(notify_api, os_environ, mocker):
@@ -219,7 +206,6 @@ def test_function_test_fixtures_raises_clear_error_when_ssm_upload_fails(notify_
219206
ssm_client.put_parameter.side_effect = Exception("Parameter value too large")
220207
mocker.patch("app.functional_tests_fixtures.boto3.client", return_value=ssm_client)
221208

222-
os.environ["FUNCTIONAL_TEST_ENV_FILE"] = ""
223209
os.environ["SSM_UPLOAD_PATH"] = "/test/ssm/environment"
224210

225211
with pytest.raises(Exception) as exc:
@@ -246,7 +232,6 @@ def test_function_test_fixtures_uploads_performance_env_to_separate_ssm_path(not
246232
ssm_client.put_parameter.return_value = {"ResponseMetadata": {"HTTPStatusCode": 200}}
247233
mocker.patch("app.functional_tests_fixtures.boto3.client", return_value=ssm_client)
248234

249-
os.environ["FUNCTIONAL_TEST_ENV_FILE"] = ""
250235
os.environ["SSM_UPLOAD_PATH"] = "/test/ssm/functional-environment"
251236
os.environ["PERFORMANCE_SSM_UPLOAD_PATH"] = "/test/ssm/performance-environment"
252237

0 commit comments

Comments
 (0)