Skip to content

Commit 63585be

Browse files
eli 584 - NHS number validation modified (#536)
1 parent 92cb0d1 commit 63585be

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/eligibility_signposting_api/common/request_validator.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,14 @@ def validate_query_params(query_params: dict[str, str]) -> tuple[bool, ResponseR
4242
def validate_nhs_number(path_nhs: str | None, header_nhs: str | None) -> bool:
4343
logger.info("NHS numbers from the request", extra={"header_nhs": header_nhs, "path_nhs": path_nhs})
4444

45-
if not header_nhs or not path_nhs:
46-
logger.error("NHS number is not present", extra={"header_nhs": header_nhs, "path_nhs": path_nhs})
45+
if not path_nhs:
46+
logger.error("NHS number is not present in path", extra={"path_nhs": path_nhs})
4747
return False
4848

49+
if not header_nhs: # Not a validation error
50+
logger.info("NHS number is not present in header", extra={"header_nhs": header_nhs, "path_nhs": path_nhs})
51+
return True
52+
4953
if header_nhs != path_nhs:
5054
logger.error("NHS number mismatch", extra={"header_nhs": header_nhs, "path_nhs": path_nhs})
5155
return False

tests/unit/common/test_request_validator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class TestValidateNHSNumber:
2020
@pytest.mark.parametrize(
2121
("path_nhs", "header_nhs", "expected_result", "expected_log_msg"),
2222
[
23-
(None, None, False, "NHS number is not present"),
24-
("1234567890", None, False, "NHS number is not present"),
25-
(None, "1234567890", False, "NHS number is not present"),
23+
(None, None, False, "NHS number is not present in path"),
24+
("1234567890", None, True, None),
25+
(None, "1234567890", False, "NHS number is not present in path"),
2626
("1234567890", "0987654321", False, "NHS number mismatch"),
2727
("1234567890", "1234567890", True, None),
2828
],

0 commit comments

Comments
 (0)