Skip to content

Commit

Permalink
Fix functional tests to align status code after the predicate removal
Browse files Browse the repository at this point in the history
Failures render the same HTML but with different error code now.
  • Loading branch information
marcospri committed Jul 10, 2023
1 parent 73e4183 commit e153c7a
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions tests/functional/lti_certification/v13/core/test_bad_payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_no_kid_sent_in_jwt_header(
"""
del jwt_headers["kid"]

do_lti_launch({"id_token": make_jwt(test_payload, jwt_headers)}, status=422)
do_lti_launch({"id_token": make_jwt(test_payload, jwt_headers)}, status=403)

assert "Missing 'kid' value in JWT header" in caplog.messages

Expand All @@ -28,7 +28,7 @@ def test_incorrect_kid_in_jwt_header(
):
jwt_headers["kid"] = "imstester_66067"

do_lti_launch({"id_token": make_jwt(test_payload, jwt_headers)}, status=422)
do_lti_launch({"id_token": make_jwt(test_payload, jwt_headers)}, status=403)
assert (
Any.string.matching(
"^Invalid JWT for:.* Unable to find a signing key that matches:.*$"
Expand Down Expand Up @@ -58,9 +58,7 @@ def test_invalid_lti_message(self, make_jwt, do_lti_launch):
"""The provided JSON is NOT a 1.3 JWT launch"""
payload = {"name": "badltilaunch"}

response = do_lti_launch({"id_token": make_jwt(payload)}, status=422)

assert response.status_code == 422
_ = do_lti_launch({"id_token": make_jwt(payload)}, status=403)

def test_missing_lti_claims(self, test_payload, do_lti_launch, make_jwt):
"""The provided 1.3 JWT launch is missing one or more required claims"""
Expand All @@ -74,23 +72,24 @@ def test_missing_lti_claims(self, test_payload, do_lti_launch, make_jwt):
for missing_claim in missing_claims:
del test_payload[missing_claim]

response = do_lti_launch({"id_token": make_jwt(test_payload)}, status=422)
response = do_lti_launch({"id_token": make_jwt(test_payload)}, status=403)

assert response.status_code == 422
assert response.html

def test_timestamps_incorrect(self, test_payload, do_lti_launch, make_jwt):
"""Incorrect JWT iat and exp timestamp Values are Invalid"""
test_payload["iat"] = 11111
test_payload["exp"] = 22222

response = do_lti_launch({"id_token": make_jwt(test_payload)}, status=422)
response = do_lti_launch({"id_token": make_jwt(test_payload)}, status=403)
assert response.html

def test_message_type_claim_missing(self, test_payload, assert_missing_claim):
"""The Required message_type Claim Not Present"""
response = assert_missing_claim(
test_payload, "https://purl.imsglobal.org/spec/lti/claim/message_type"
test_payload,
"https://purl.imsglobal.org/spec/lti/claim/message_type",
status=422,
)

assert "There were problems with these request parameters" in response.text
Expand All @@ -99,23 +98,21 @@ def test_message_type_claim_missing(self, test_payload, assert_missing_claim):
def test_role_claim_missing(self, test_payload, assert_missing_claim):
"""The Required role Claim Not Present"""
assert_missing_claim(
test_payload,
"https://purl.imsglobal.org/spec/lti/claim/roles",
status=403,
test_payload, "https://purl.imsglobal.org/spec/lti/claim/roles"
)

def test_deployment_id_claim_missing(self, test_payload, assert_missing_claim):
"""The Required deployment_id Claim Not Present"""
assert_missing_claim(
test_payload,
"https://purl.imsglobal.org/spec/lti/claim/deployment_id",
status=403,
test_payload, "https://purl.imsglobal.org/spec/lti/claim/deployment_id"
)

def test_resource_link_id_claim_missing(self, test_payload, assert_missing_claim):
"""The Required resource_link_id Claim Not Present"""
assert_missing_claim(
test_payload, "https://purl.imsglobal.org/spec/lti/claim/resource_link"
test_payload,
"https://purl.imsglobal.org/spec/lti/claim/resource_link",
status=422,
)

def test_user_claim_missing(self, test_payload, assert_missing_claim):
Expand All @@ -134,7 +131,7 @@ def debug_log_capture(self, caplog):

@pytest.fixture
def assert_missing_claim(self, do_lti_launch, make_jwt):
def _missing_claim(payload, missing_claim, status=422):
def _missing_claim(payload, missing_claim, status=403):
del payload[missing_claim]

response = do_lti_launch({"id_token": make_jwt(payload)}, status=status)
Expand Down

0 comments on commit e153c7a

Please sign in to comment.