Skip to content

Commit b78505d

Browse files
committed
ELI-404: Fix Error message returned for authorisation failure
1 parent e1d20a9 commit b78505d

4 files changed

Lines changed: 14 additions & 15 deletions

File tree

src/eligibility_signposting_api/common/api_error_response.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FHIRIssueCode(str, Enum):
2626

2727

2828
class FHIRSpineErrorCode(str, Enum):
29-
INVALID_NHS_NUMBER = "INVALID_NHS_NUMBER"
29+
ACCESS_DENIED = "ACCESS_DENIED"
3030
INVALID_PARAMETER = "INVALID_PARAMETER"
3131
BAD_REQUEST = "BAD_REQUEST"
3232
INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"
@@ -144,8 +144,8 @@ def log_and_generate_response(
144144
fhir_issue_code=FHIRIssueCode.FORBIDDEN,
145145
fhir_issue_severity=FHIRIssueSeverity.ERROR,
146146
fhir_coding_system="https://fhir.nhs.uk/STU3/ValueSet/Spine-ErrorOrWarningCode-1",
147-
fhir_error_code=FHIRSpineErrorCode.INVALID_NHS_NUMBER,
148-
fhir_display_message="The provided NHS number does not match the record.",
147+
fhir_error_code=FHIRSpineErrorCode.ACCESS_DENIED,
148+
fhir_display_message="Access has been denied to process this request.",
149149
)
150150

151151

src/eligibility_signposting_api/common/request_validator.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,8 @@ def wrapper(event: LambdaEvent, context: LambdaContext) -> dict[str, Any] | None
6767
)
6868

6969
if not validate_nhs_number(path_nhs_no, header_nhs_no):
70-
message = f"NHS Number {path_nhs_no or ''} does not match the header NHS Number {header_nhs_no or ''}"
71-
return NHS_NUMBER_MISMATCH_ERROR.log_and_generate_response(
72-
log_message=message, diagnostics=message, location_param="id"
73-
)
70+
message = "You are not authorised to request information for the supplied NHS Number"
71+
return NHS_NUMBER_MISMATCH_ERROR.log_and_generate_response(log_message=message, diagnostics=message)
7472

7573
query_params = event.get("queryStringParameters")
7674
if query_params:

tests/integration/lambda/test_app_running_as_lambda.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,13 @@ def test_given_nhs_number_in_path_does_not_match_with_nhs_number_in_headers_resu
303303
has_entries(
304304
severity="error",
305305
code="forbidden",
306-
diagnostics=f"NHS Number {persisted_person} does "
307-
f"not match the header NHS Number 123{persisted_person!s}",
306+
diagnostics="You are not authorised to request information for the supplied NHS Number",
308307
details={
309308
"coding": [
310309
{
311310
"system": "https://fhir.nhs.uk/STU3/ValueSet/Spine-ErrorOrWarningCode-1",
312-
"code": "INVALID_NHS_NUMBER",
313-
"display": "The provided NHS number does not match the record.",
311+
"code": "ACCESS_DENIED",
312+
"display": "Access has been denied to process this request.",
314313
}
315314
]
316315
},
@@ -350,13 +349,13 @@ def test_given_nhs_number_not_present_in_headers_results_in_error_response(
350349
has_entries(
351350
severity="error",
352351
code="forbidden",
353-
diagnostics=f"NHS Number {persisted_person} does not match the header NHS Number ",
352+
diagnostics="You are not authorised to request information for the supplied NHS Number",
354353
details={
355354
"coding": [
356355
{
357356
"system": "https://fhir.nhs.uk/STU3/ValueSet/Spine-ErrorOrWarningCode-1",
358-
"code": "INVALID_NHS_NUMBER",
359-
"display": "The provided NHS number does not match the record.",
357+
"code": "ACCESS_DENIED",
358+
"display": "Access has been denied to process this request.",
360359
}
361360
]
362361
},

tests/unit/common/test_request_validator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ def test_validate_request_params_nhs_mismatch(self, caplog):
7979
response_body = json.loads(response["body"])
8080
issue = response_body["issue"][0]
8181
assert issue["code"] == "forbidden"
82-
assert issue["diagnostics"] == ("NHS Number 0987654321 does not match the header NHS Number 1234567890")
82+
assert issue["details"]["coding"][0]["code"] == "ACCESS_DENIED"
83+
assert issue["details"]["coding"][0]["display"] == "Access has been denied to process this request."
84+
assert issue["diagnostics"] == "You are not authorised to request information for the supplied NHS Number"
8385

8486
def test_validate_request_params_nhs_missing_in_path(self, caplog):
8587
mock_handler = MagicMock()

0 commit comments

Comments
 (0)