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
11 changes: 0 additions & 11 deletions src/eligibility_signposting_api/common/api_error_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ class FHIRIssueCode(str, Enum):
FORBIDDEN = "forbidden"
PROCESSING = "processing"
VALUE = "value"
INVALID = "invalid"


class FHIRSpineErrorCode(str, Enum):
ACCESS_DENIED = "ACCESS_DENIED"
INVALID_PARAMETER = "INVALID_PARAMETER"
BAD_REQUEST = "BAD_REQUEST"
INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"
REFERENCE_NOT_FOUND = "REFERENCE_NOT_FOUND"

Expand Down Expand Up @@ -140,12 +138,3 @@ def log_and_generate_response(
fhir_error_code=FHIRSpineErrorCode.ACCESS_DENIED,
fhir_display_message="Access has been denied to process this request.",
)


NHS_NUMBER_MISSING_ERROR = APIErrorResponse(
status_code=HTTPStatus.BAD_REQUEST,
fhir_issue_code=FHIRIssueCode.INVALID,
fhir_issue_severity=FHIRIssueSeverity.ERROR,
fhir_error_code=FHIRSpineErrorCode.BAD_REQUEST,
fhir_display_message="Bad Request",
)
7 changes: 0 additions & 7 deletions src/eligibility_signposting_api/common/request_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
INVALID_CONDITION_FORMAT_ERROR,
INVALID_INCLUDE_ACTIONS_ERROR,
NHS_NUMBER_MISMATCH_ERROR,
NHS_NUMBER_MISSING_ERROR,
)
from eligibility_signposting_api.config.contants import NHS_NUMBER_HEADER

Expand Down Expand Up @@ -60,12 +59,6 @@ def wrapper(event: LambdaEvent, context: LambdaContext) -> dict[str, Any] | None
path_nhs_no = event.get("pathParameters", {}).get("id")
header_nhs_no = event.get("headers", {}).get(NHS_NUMBER_HEADER)

if not path_nhs_no:
message = "Missing required NHS Number from path parameters"
return NHS_NUMBER_MISSING_ERROR.log_and_generate_response(
log_message=message, diagnostics=message, location_param="id"
)

if not validate_nhs_number(path_nhs_no, header_nhs_no):
message = "You are not authorised to request information for the supplied NHS Number"
return NHS_NUMBER_MISMATCH_ERROR.log_and_generate_response(log_message=message, diagnostics=message)
Expand Down
30 changes: 0 additions & 30 deletions tests/unit/common/test_request_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,36 +83,6 @@ def test_validate_request_params_nhs_mismatch(self, caplog):
assert issue["details"]["coding"][0]["display"] == "Access has been denied to process this request."
assert issue["diagnostics"] == "You are not authorised to request information for the supplied NHS Number"

def test_validate_request_params_nhs_missing_in_path(self, caplog):
mock_handler = MagicMock()
mock_context = {}
event = {
"headers": {"nhs-login-nhs-number": "1234567890"},
}

decorator = request_validator.validate_request_params()
wrapped_handler = decorator(mock_handler)

with caplog.at_level(logging.ERROR):
response = wrapped_handler(event, mock_context)

mock_handler.assert_not_called()

assert response is not None
assert response["statusCode"] == HTTPStatus.BAD_REQUEST
response_body = json.loads(response["body"])
issue = response_body["issue"][0]
assert issue["code"] == "invalid"
assert issue["severity"] == "error"
assert issue["details"]["coding"][0]["code"] == "BAD_REQUEST"
assert issue["details"]["coding"][0]["display"] == "Bad Request"
assert issue["diagnostics"] == "Missing required NHS Number from path parameters"
assert issue["location"][0] == "parameters/id"
assert any(
(record.levelname == "ERROR" and "Missing required NHS Number from path parameters" in record.message)
for record in caplog.records
)


class TestValidateQueryParameters:
@pytest.mark.parametrize(
Expand Down