Skip to content

Commit 6bca431

Browse files
authored
Improve coverage (#1317)
1 parent fe7b086 commit 6bca431

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

tests/test_oidc_views.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
from django.utils import timezone
77
from pytest_django.asserts import assertRedirects
88

9-
from oauth2_provider.exceptions import ClientIdMissmatch, InvalidOIDCClientError, InvalidOIDCRedirectURIError
9+
from oauth2_provider.exceptions import (
10+
ClientIdMissmatch,
11+
InvalidIDTokenError,
12+
InvalidOIDCClientError,
13+
InvalidOIDCRedirectURIError,
14+
)
1015
from oauth2_provider.models import get_access_token_model, get_id_token_model, get_refresh_token_model
1116
from oauth2_provider.oauth2_validators import OAuth2Validator
1217
from oauth2_provider.settings import oauth2_settings
@@ -236,6 +241,13 @@ def test_deprecated_validate_logout_request(
236241
client_id=client_id,
237242
post_logout_redirect_uri="http://example.org",
238243
) == (ALWAYS_PROMPT, ("http://example.org", application), oidc_tokens.user)
244+
with pytest.raises(InvalidIDTokenError):
245+
validate_logout_request(
246+
request=mock_request_for(oidc_tokens.user),
247+
id_token_hint="111",
248+
client_id=public_application.client_id,
249+
post_logout_redirect_uri="http://other.org",
250+
)
239251
with pytest.raises(ClientIdMissmatch):
240252
validate_logout_request(
241253
request=mock_request_for(oidc_tokens.user),
@@ -271,10 +283,18 @@ def test_deprecated_validate_logout_request(
271283
client_id=client_id,
272284
post_logout_redirect_uri="http://other.org",
273285
)
286+
with pytest.raises(InvalidOIDCRedirectURIError):
287+
rp_settings.OIDC_RP_INITIATED_LOGOUT_STRICT_REDIRECT_URIS = True
288+
validate_logout_request(
289+
request=mock_request_for(oidc_tokens.user),
290+
id_token_hint=None,
291+
client_id=public_application.client_id,
292+
post_logout_redirect_uri="http://other.org",
293+
)
274294

275295

276296
@pytest.mark.django_db
277-
def test_validate_logout_request(oidc_tokens, public_application):
297+
def test_validate_logout_request(oidc_tokens, public_application, rp_settings):
278298
oidc_tokens = oidc_tokens
279299
application = oidc_tokens.application
280300
client_id = application.client_id
@@ -306,6 +326,12 @@ def test_validate_logout_request(oidc_tokens, public_application):
306326
client_id=client_id,
307327
post_logout_redirect_uri="http://example.org",
308328
) == (application, oidc_tokens.user)
329+
with pytest.raises(InvalidIDTokenError):
330+
view.validate_logout_request(
331+
id_token_hint="111",
332+
client_id=public_application.client_id,
333+
post_logout_redirect_uri="http://other.org",
334+
)
309335
with pytest.raises(ClientIdMissmatch):
310336
view.validate_logout_request(
311337
id_token_hint=id_token,
@@ -336,6 +362,13 @@ def test_validate_logout_request(oidc_tokens, public_application):
336362
client_id=client_id,
337363
post_logout_redirect_uri="http://other.org",
338364
)
365+
with pytest.raises(InvalidOIDCRedirectURIError):
366+
rp_settings.OIDC_RP_INITIATED_LOGOUT_STRICT_REDIRECT_URIS = True
367+
view.validate_logout_request(
368+
id_token_hint=None,
369+
client_id=public_application.client_id,
370+
post_logout_redirect_uri="http://other.org",
371+
)
339372

340373

341374
@pytest.mark.django_db

0 commit comments

Comments
 (0)