Skip to content

Commit 8c3941c

Browse files
Fixed integration test hashing serivce.
1 parent 304b89f commit 8c3941c

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

tests/integration/conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,3 +1037,23 @@ def campaign_config_with_missing_descriptions_missing_rule_text(
10371037
)
10381038
yield campaign
10391039
s3_client.delete_object(Bucket=rules_bucket, Key=f"{campaign.name}.json")
1040+
1041+
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+
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()
1056+
1057+
@pytest.fixture
1058+
def hashing_service() -> StubHashingService:
1059+
return StubHashingService()

tests/integration/repo/test_person_repo.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import hashlib
2+
import hmac
13
from typing import Any
24

35
import pytest
@@ -7,21 +9,27 @@
79
from eligibility_signposting_api.model.eligibility_status import NHSNumber
810
from eligibility_signposting_api.repos import NotFoundError
911
from eligibility_signposting_api.repos.person_repo import PersonRepo
12+
from tests.integration.conftest import StubHashingService
1013

1114

12-
def test_person_found(person_table: Any, persisted_person: NHSNumber):
15+
def test_person_found(person_table: Any, persisted_person: NHSNumber,
16+
hashing_service: StubHashingService,):
1317
# Given
14-
repo = PersonRepo(person_table)
18+
#repo = PersonRepo(person_table)
19+
repo = PersonRepo(person_table, hashing_service)
1520

1621
# When
1722
actual = repo.get_eligibility_data(persisted_person)
1823

1924
# Then
25+
nhs_num_hash = hashing_service.hash_with_current_secret(persisted_person)
26+
2027
assert_that(
2128
actual.data,
2229
contains_inanyorder(
23-
has_entries({"NHS_NUMBER": persisted_person, "ATTRIBUTE_TYPE": "PERSON"}),
24-
has_entries({"NHS_NUMBER": persisted_person, "ATTRIBUTE_TYPE": "COHORTS"}),
30+
#has_entries({"NHS_NUMBER": persisted_person, "ATTRIBUTE_TYPE": "PERSON"}),
31+
has_entries({"NHS_NUMBER": nhs_num_hash, "ATTRIBUTE_TYPE": "PERSON"}),
32+
has_entries({"NHS_NUMBER": nhs_num_hash, "ATTRIBUTE_TYPE": "COHORTS"}),
2533
),
2634
)
2735

0 commit comments

Comments
 (0)