diff --git a/src/eligibility_signposting_api/common/request_validator.py b/src/eligibility_signposting_api/common/request_validator.py index cd213287a..e4fe7ab76 100644 --- a/src/eligibility_signposting_api/common/request_validator.py +++ b/src/eligibility_signposting_api/common/request_validator.py @@ -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 diff --git a/tests/unit/common/test_request_validator.py b/tests/unit/common/test_request_validator.py index 7de1c776a..e04392ebd 100644 --- a/tests/unit/common/test_request_validator.py +++ b/tests/unit/common/test_request_validator.py @@ -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), ],