Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make response expiry date mandatory #1104

Merged
merged 13 commits into from
May 18, 2023
2 changes: 1 addition & 1 deletion app/data_models/metadata_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class MetadataProxy:
case_id: str
collection_exercise_sid: str
response_id: str
response_expires_at: datetime
survey_metadata: Optional[SurveyMetadata] = None
schema_url: Optional[str] = None
schema_name: Optional[str] = None
language_code: Optional[str] = None
response_expires_at: Optional[datetime] = None
channel: Optional[str] = None
region_code: Optional[str] = None
version: Optional[AuthPayloadVersion] = None
Expand Down
2 changes: 1 addition & 1 deletion app/utilities/metadata_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class RunnerMetadataSchema(Schema, StripWhitespaceMixin):
) # type:ignore
case_type = VALIDATORS["string"](required=False) # type:ignore
response_expires_at = VALIDATORS["iso_8601_date_string"](
required=False,
required=True,
validate=lambda x: parse_iso_8601_datetime(x) > datetime.now(tz=timezone.utc),
) # type:ignore

Expand Down
2 changes: 1 addition & 1 deletion app/utilities/metadata_parser_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class RunnerMetadataSchema(Schema, StripWhitespaceMixin):
required=False, validate=validate.Length(min=1)
) # type:ignore
response_expires_at = VALIDATORS["iso_8601_date_string"](
required=False,
required=True,
validate=lambda x: parse_iso_8601_datetime(x) > datetime.now(tz=timezone.utc),
) # type:ignore
region_code = VALIDATORS["string"](
Expand Down
5 changes: 5 additions & 0 deletions tests/app/parser/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def fake_metadata_runner():
"response_id": str(uuid.uuid4()),
"account_service_url": "https://ras.ons.gov.uk",
"case_id": str(uuid.uuid4()),
"response_expires_at": "2023-05-18T10:38:13+00:00",
}


Expand All @@ -48,6 +49,7 @@ def fake_business_metadata_runner():

metadata["eq_id"] = "mbs"
metadata["form_type"] = "0253"
metadata["response_expires_at"] = "2023-05-18T10:38:13+00:00"

return metadata

Expand All @@ -67,6 +69,7 @@ def fake_metadata_full():
"return_by": "2016-07-07",
"case_ref": "1000000000000001",
"case_id": str(uuid.uuid4()),
"response_expires_at": "2023-05-18T10:38:13+00:00",
}

return dict(fake_metadata_runner(), **fake_questionnaire_claims)
Expand All @@ -84,6 +87,7 @@ def fake_metadata_runner_v2():
"case_id": str(uuid.uuid4()),
"version": AuthPayloadVersion.V2.value,
"survey_metadata": {"data": {"key": "value"}},
"response_expires_at": "2023-05-18T10:38:13+00:00",
}


Expand All @@ -103,6 +107,7 @@ def fake_metadata_full_v2_business():
"case_ref": "1000000000000001",
"ru_ref": "123456789",
"form_type": "I",
"response_expires_at": "2023-05-18T10:38:13+00:00",
}

metadata = fake_metadata_runner_v2()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_sms_fulfilment_request_payload():
response_id="response_id",
account_service_url="account_service_url",
collection_exercise_sid="collection_exercise_sid",
response_expires_at=datetime.now(tz=timezone.utc),
)

fulfilment_request = IndividualResponseFulfilmentRequest(
Expand Down
2 changes: 2 additions & 0 deletions tests/functional/jwt_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export function generateToken(
account_service_url: "http://localhost:8000",
survey_metadata: getSurveyMetadata(theme, userId, displayAddress, periodId, periodStr),
version: "v2",
response_expires_at: "2023-05-18T10:38:13+00:00",
};
} else {
payload = {
Expand All @@ -131,6 +132,7 @@ export function generateToken(
region_code: regionCode,
language_code: languageCode,
account_service_url: "http://localhost:8000",
response_expires_at: "2023-05-18T10:38:13+00:00",
};
}

Expand Down
1 change: 1 addition & 0 deletions tests/integration/create_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def _get_payload_with_params(
payload_vars["exp"] = payload_vars["iat"] + float(3600) # one hour from now
payload_vars["jti"] = str(uuid4())
payload_vars["case_id"] = str(uuid4())
payload_vars["response_expires_at"] = "2023-05-18T10:38:13+00:00"

for key, value in extra_payload.items():
payload_vars[key] = value
Expand Down
1 change: 1 addition & 0 deletions tests/integration/routes/test_jwt_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def create_payload():
"ru_name": "Test",
"return_by": "2016-09-09",
"account_service_url": "http://upstream.url/",
"response_expires_at": "2023-05-18T10:38:13+00:00",
}


Expand Down