Skip to content

Commit 5d95435

Browse files
Stub for hashing service and secret repo.
1 parent 8c3941c commit 5d95435

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

tests/integration/conftest.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
StartDate,
3333
StatusText,
3434
)
35+
from eligibility_signposting_api.processors.hashing_service import HashingService, HashSecretName
36+
from eligibility_signposting_api.repos import SecretRepo
3537
from eligibility_signposting_api.repos.campaign_repo import BucketName
3638
from eligibility_signposting_api.repos.person_repo import TableName
3739
from tests.fixtures.builders.model import rule
@@ -1039,21 +1041,33 @@ def campaign_config_with_missing_descriptions_missing_rule_text(
10391041
s3_client.delete_object(Bucket=rules_bucket, Key=f"{campaign.name}.json")
10401042

10411043

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()
10491044

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+
10561058

10571059
@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+
)

tests/integration/repo/test_person_repo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
from hamcrest import assert_that, contains_inanyorder, has_entries
88

99
from eligibility_signposting_api.model.eligibility_status import NHSNumber
10+
from eligibility_signposting_api.processors.hashing_service import HashingService
1011
from eligibility_signposting_api.repos import NotFoundError
1112
from eligibility_signposting_api.repos.person_repo import PersonRepo
12-
from tests.integration.conftest import StubHashingService
1313

1414

1515
def test_person_found(person_table: Any, persisted_person: NHSNumber,
16-
hashing_service: StubHashingService,):
16+
hashing_service: HashingService,):
1717
# Given
1818
#repo = PersonRepo(person_table)
1919
repo = PersonRepo(person_table, hashing_service)

0 commit comments

Comments
 (0)