Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/eligibility_signposting_api/common/request_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ def validate_query_params(query_params: dict[str, str]) -> tuple[bool, ResponseR
def validate_nhs_number(path_nhs: str | None, header_nhs: str | None) -> bool:
logger.info("NHS numbers from the request", extra={"header_nhs": header_nhs, "path_nhs": path_nhs})

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

if not header_nhs: # Not a validation error
logger.info("NHS number is not present in header", extra={"header_nhs": header_nhs, "path_nhs": path_nhs})
return True

if header_nhs != path_nhs:
logger.error("NHS number mismatch", extra={"header_nhs": header_nhs, "path_nhs": path_nhs})
return False
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/common/test_request_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class TestValidateNHSNumber:
@pytest.mark.parametrize(
("path_nhs", "header_nhs", "expected_result", "expected_log_msg"),
[
(None, None, False, "NHS number is not present"),
("1234567890", None, False, "NHS number is not present"),
(None, "1234567890", False, "NHS number is not present"),
(None, None, False, "NHS number is not present in path"),
("1234567890", None, True, None),
(None, "1234567890", False, "NHS number is not present in path"),
("1234567890", "0987654321", False, "NHS number mismatch"),
("1234567890", "1234567890", True, None),
],
Expand Down
Loading