|
32 | 32 | StartDate, |
33 | 33 | StatusText, |
34 | 34 | ) |
| 35 | +from eligibility_signposting_api.processors.hashing_service import HashingService, HashSecretName |
| 36 | +from eligibility_signposting_api.repos import SecretRepo |
35 | 37 | from eligibility_signposting_api.repos.campaign_repo import BucketName |
36 | 38 | from eligibility_signposting_api.repos.person_repo import TableName |
37 | 39 | from tests.fixtures.builders.model import rule |
@@ -1039,21 +1041,33 @@ def campaign_config_with_missing_descriptions_missing_rule_text( |
1039 | 1041 | s3_client.delete_object(Bucket=rules_bucket, Key=f"{campaign.name}.json") |
1040 | 1042 |
|
1041 | 1043 |
|
1042 | | -class StubHashingService: |
1043 | | - def hash_with_current_secret(self, nhs_number: str) -> str: |
1044 | | - return hmac.new( |
1045 | | - "test_value".encode("utf-8"), |
1046 | | - nhs_number.encode("utf-8"), |
1047 | | - hashlib.sha512, |
1048 | | - ).hexdigest() |
1049 | 1044 |
|
1050 | | - def hash_with_previous_secret(self, nhs_number: str) -> str: |
1051 | | - return hmac.new( |
1052 | | - "test_old_value".encode("utf-8"), |
1053 | | - nhs_number.encode("utf-8"), |
1054 | | - hashlib.sha512, |
1055 | | - ).hexdigest() |
| 1045 | + |
| 1046 | +# If you put StubSecretRepo in a separate module, import it instead |
| 1047 | +class StubSecretRepo(SecretRepo): |
| 1048 | + def __init__(self, current: str = "test_value", previous: str = "test_value_old"): |
| 1049 | + self._current = current |
| 1050 | + self._previous = previous |
| 1051 | + |
| 1052 | + def get_secret_current(self, secret_name: str) -> dict[str, str]: |
| 1053 | + return {"AWSCURRENT": self._current} |
| 1054 | + |
| 1055 | + def get_secret_previous(self, secret_name: str) -> dict[str, str]: |
| 1056 | + return {"AWSPREVIOUS": self._previous} |
| 1057 | + |
1056 | 1058 |
|
1057 | 1059 | @pytest.fixture |
1058 | | -def hashing_service() -> StubHashingService: |
1059 | | - return StubHashingService() |
| 1060 | +def hashing_service() -> HashingService: |
| 1061 | + secret_repo = StubSecretRepo( |
| 1062 | + current="test_value", |
| 1063 | + previous="test_value_old", |
| 1064 | + ) |
| 1065 | + |
| 1066 | + # The actual value of the name does not matter for the stub, |
| 1067 | + # but we keep it realistic for readability. |
| 1068 | + hash_secret_name = HashSecretName("eligibility-signposting-api-dev/hashing_secret") |
| 1069 | + |
| 1070 | + return HashingService( |
| 1071 | + secret_repo=secret_repo, |
| 1072 | + hash_secret_name=hash_secret_name, |
| 1073 | + ) |
0 commit comments