Skip to content

Commit

Permalink
Improve coverage (#1317)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonial authored Sep 18, 2023
1 parent fe7b086 commit 6bca431
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions tests/test_oidc_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
from django.utils import timezone
from pytest_django.asserts import assertRedirects

from oauth2_provider.exceptions import ClientIdMissmatch, InvalidOIDCClientError, InvalidOIDCRedirectURIError
from oauth2_provider.exceptions import (
ClientIdMissmatch,
InvalidIDTokenError,
InvalidOIDCClientError,
InvalidOIDCRedirectURIError,
)
from oauth2_provider.models import get_access_token_model, get_id_token_model, get_refresh_token_model
from oauth2_provider.oauth2_validators import OAuth2Validator
from oauth2_provider.settings import oauth2_settings
Expand Down Expand Up @@ -236,6 +241,13 @@ def test_deprecated_validate_logout_request(
client_id=client_id,
post_logout_redirect_uri="http://example.org",
) == (ALWAYS_PROMPT, ("http://example.org", application), oidc_tokens.user)
with pytest.raises(InvalidIDTokenError):
validate_logout_request(
request=mock_request_for(oidc_tokens.user),
id_token_hint="111",
client_id=public_application.client_id,
post_logout_redirect_uri="http://other.org",
)
with pytest.raises(ClientIdMissmatch):
validate_logout_request(
request=mock_request_for(oidc_tokens.user),
Expand Down Expand Up @@ -271,10 +283,18 @@ def test_deprecated_validate_logout_request(
client_id=client_id,
post_logout_redirect_uri="http://other.org",
)
with pytest.raises(InvalidOIDCRedirectURIError):
rp_settings.OIDC_RP_INITIATED_LOGOUT_STRICT_REDIRECT_URIS = True
validate_logout_request(
request=mock_request_for(oidc_tokens.user),
id_token_hint=None,
client_id=public_application.client_id,
post_logout_redirect_uri="http://other.org",
)


@pytest.mark.django_db
def test_validate_logout_request(oidc_tokens, public_application):
def test_validate_logout_request(oidc_tokens, public_application, rp_settings):
oidc_tokens = oidc_tokens
application = oidc_tokens.application
client_id = application.client_id
Expand Down Expand Up @@ -306,6 +326,12 @@ def test_validate_logout_request(oidc_tokens, public_application):
client_id=client_id,
post_logout_redirect_uri="http://example.org",
) == (application, oidc_tokens.user)
with pytest.raises(InvalidIDTokenError):
view.validate_logout_request(
id_token_hint="111",
client_id=public_application.client_id,
post_logout_redirect_uri="http://other.org",
)
with pytest.raises(ClientIdMissmatch):
view.validate_logout_request(
id_token_hint=id_token,
Expand Down Expand Up @@ -336,6 +362,13 @@ def test_validate_logout_request(oidc_tokens, public_application):
client_id=client_id,
post_logout_redirect_uri="http://other.org",
)
with pytest.raises(InvalidOIDCRedirectURIError):
rp_settings.OIDC_RP_INITIATED_LOGOUT_STRICT_REDIRECT_URIS = True
view.validate_logout_request(
id_token_hint=None,
client_id=public_application.client_id,
post_logout_redirect_uri="http://other.org",
)


@pytest.mark.django_db
Expand Down

0 comments on commit 6bca431

Please sign in to comment.