Skip to content

Commit 2f7a17a

Browse files
committed
Add a test for http redirect of public Application
1 parent c39d65b commit 2f7a17a

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

tests/conftest.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ def application():
109109

110110

111111
@pytest.fixture
112-
def other_application():
112+
def public_application():
113113
return Application.objects.create(
114114
name="Other Application",
115115
redirect_uris="http://other.org",
116116
post_logout_redirect_uris="http://other.org",
117-
client_type=Application.CLIENT_CONFIDENTIAL,
117+
client_type=Application.CLIENT_PUBLIC,
118118
authorization_grant_type=Application.GRANT_AUTHORIZATION_CODE,
119119
algorithm=Application.RS256_ALGORITHM,
120120
client_secret=CLEARTEXT_SECRET,
@@ -220,3 +220,16 @@ def oidc_email_scope_tokens(oauth2_settings, application, test_user, client):
220220
"openid email",
221221
"http://example.org",
222222
)
223+
224+
225+
@pytest.fixture
226+
def oidc_non_confidential_tokens(oauth2_settings, public_application, test_user, client):
227+
return generate_access_token(
228+
oauth2_settings,
229+
public_application,
230+
test_user,
231+
client,
232+
presets.OIDC_SETTINGS_EMAIL_SCOPE,
233+
"openid",
234+
"http://other.org",
235+
)

tests/test_oidc_views.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def test_get_jwks_info_multiple_rsa_keys(self):
171171

172172
@pytest.mark.django_db
173173
@pytest.mark.parametrize("ALWAYS_PROMPT", [True, False])
174-
def test_validate_logout_request(oidc_tokens, other_application, other_user, rp_settings, ALWAYS_PROMPT):
174+
def test_validate_logout_request(oidc_tokens, public_application, other_user, rp_settings, ALWAYS_PROMPT):
175175
rp_settings.OIDC_RP_INITIATED_LOGOUT_ALWAYS_PROMPT = ALWAYS_PROMPT
176176
oidc_tokens = oidc_tokens
177177
application = oidc_tokens.application
@@ -211,7 +211,7 @@ def test_validate_logout_request(oidc_tokens, other_application, other_user, rp_
211211
validate_logout_request(
212212
user=oidc_tokens.user,
213213
id_token_hint=id_token,
214-
client_id=other_application.client_id,
214+
client_id=public_application.client_id,
215215
post_logout_redirect_uri="http://other.org",
216216
)
217217
with pytest.raises(InvalidOIDCClientError):
@@ -304,11 +304,27 @@ def test_rp_initiated_logout_get_id_token_redirect_with_state(loggend_in_client,
304304

305305
@pytest.mark.django_db
306306
def test_rp_initiated_logout_get_id_token_missmatch_client_id(
307-
loggend_in_client, oidc_tokens, other_application, rp_settings
307+
loggend_in_client, oidc_tokens, public_application, rp_settings
308308
):
309309
rsp = loggend_in_client.get(
310310
reverse("oauth2_provider:rp-initiated-logout"),
311-
data={"id_token_hint": oidc_tokens.id_token, "client_id": other_application.client_id},
311+
data={"id_token_hint": oidc_tokens.id_token, "client_id": public_application.client_id},
312+
)
313+
assert rsp.status_code == 400
314+
assert is_logged_in(loggend_in_client)
315+
316+
317+
@pytest.mark.django_db
318+
def test_rp_initiated_logout_public_client_redirect_client_id(
319+
loggend_in_client, oidc_non_confidential_tokens, public_application, rp_settings
320+
):
321+
rsp = loggend_in_client.get(
322+
reverse("oauth2_provider:rp-initiated-logout"),
323+
data={
324+
"id_token_hint": oidc_non_confidential_tokens.id_token,
325+
"client_id": public_application.client_id,
326+
"post_logout_redirect_uri": "http://other.org",
327+
},
312328
)
313329
assert rsp.status_code == 400
314330
assert is_logged_in(loggend_in_client)

0 commit comments

Comments
 (0)