Skip to content
Closed
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
4 changes: 4 additions & 0 deletions src/eligibility_signposting_api/common/request_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def validate_request_params() -> Callable:
def decorator(func: Callable) -> Callable:
@wraps(func)
def wrapper(event: LambdaEvent, context: LambdaContext) -> dict[str, Any] | None:
# Skip validation for a status path
http_path = event.get("requestContext", {}).get("http", {}).get("path")
if http_path == "/patient-check/_status":
return func(event, context)
path_nhs_no = event.get("pathParameters", {}).get("id")
header_nhs_no = event.get("headers", {}).get(NHS_NUMBER_HEADER)

Expand Down
5 changes: 5 additions & 0 deletions src/eligibility_signposting_api/views/eligibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def before_request() -> None:
AuditContext.add_request_details(request)


@eligibility_blueprint.get("/_status")
def api_status() -> ResponseReturnValue:
return make_response({"status": "ok", "timestamp": datetime.now(UTC).isoformat()}, HTTPStatus.OK)


@eligibility_blueprint.get("/", defaults={"nhs_number": ""})
@eligibility_blueprint.get("/<nhs_number>")
def check_eligibility(
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/common/test_request_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,31 @@ 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_no_error_from_validate_if_endpoint_is_status(self, caplog):
mock_handler = MagicMock(return_value={"statusCode": 200, "body": "OK"})
mock_context = {}
event = {
"requestContext": {
"http": {
"sourceIp": "192.0.0.1",
"method": "GET",
"path": "/patient-check/_status",
"protocol": "HTTP/1.1",
}
}
}

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_called_once()

assert response is not None
assert response["statusCode"] == HTTPStatus.OK


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