|
1 | 1 | import pytest
|
2 |
| -from django.contrib.auth import get_user |
| 2 | +from django.contrib.auth import get_user, get_user_model |
3 | 3 | from django.contrib.auth.models import AnonymousUser
|
4 | 4 | from django.test import RequestFactory
|
5 | 5 | from django.urls import reverse
|
|
12 | 12 | InvalidOIDCClientError,
|
13 | 13 | InvalidOIDCRedirectURIError,
|
14 | 14 | )
|
15 |
| -from oauth2_provider.models import get_access_token_model, get_id_token_model, get_refresh_token_model |
| 15 | +from oauth2_provider.models import ( |
| 16 | + get_access_token_model, |
| 17 | + get_application_model, |
| 18 | + get_id_token_model, |
| 19 | + get_refresh_token_model, |
| 20 | +) |
16 | 21 | from oauth2_provider.oauth2_validators import OAuth2Validator
|
17 | 22 | from oauth2_provider.settings import oauth2_settings
|
18 | 23 | from oauth2_provider.views.oidc import RPInitiatedLogoutView, _load_id_token, _validate_claims
|
@@ -132,7 +137,10 @@ def test_get_connect_discovery_info_without_issuer_url(self):
|
132 | 137 | ],
|
133 | 138 | "subject_types_supported": ["public"],
|
134 | 139 | "id_token_signing_alg_values_supported": ["RS256", "HS256"],
|
135 |
| - "token_endpoint_auth_methods_supported": ["client_secret_post", "client_secret_basic"], |
| 140 | + "token_endpoint_auth_methods_supported": [ |
| 141 | + "client_secret_post", |
| 142 | + "client_secret_basic", |
| 143 | + ], |
136 | 144 | "code_challenge_methods_supported": ["plain", "S256"],
|
137 | 145 | "claims_supported": ["sub"],
|
138 | 146 | }
|
@@ -206,6 +214,42 @@ def test_get_jwks_info_multiple_rsa_keys(self):
|
206 | 214 | assert response.json() == expected_response
|
207 | 215 |
|
208 | 216 |
|
| 217 | +@pytest.mark.usefixtures("oauth2_settings") |
| 218 | +@pytest.mark.oauth2_settings(presets.OIDC_SETTINGS_SESSION_MANAGEMENT) |
| 219 | +class TestAuthorizationView(TestCase): |
| 220 | + def test_session_state_is_present_in_url(self): |
| 221 | + User = get_user_model() |
| 222 | + Application = get_application_model() |
| 223 | + |
| 224 | + User.objects.create_user("test_user", "test@example.com", "123456") |
| 225 | + dev_user = User.objects.create_user("dev_user", "dev@example.com", "123456") |
| 226 | + |
| 227 | + application = Application.objects.create( |
| 228 | + name="Test Application", |
| 229 | + redirect_uris=( |
| 230 | + "http://localhost http://example.com http://example.org custom-scheme://example.com" |
| 231 | + ), |
| 232 | + user=dev_user, |
| 233 | + client_type=Application.CLIENT_CONFIDENTIAL, |
| 234 | + authorization_grant_type=Application.GRANT_AUTHORIZATION_CODE, |
| 235 | + client_secret="1234567890qwertyuiop", |
| 236 | + ) |
| 237 | + self.client.login(username="test_user", password="123456") |
| 238 | + response = self.client.post( |
| 239 | + reverse("oauth2_provider:authorize"), |
| 240 | + { |
| 241 | + "client_id": application.client_id, |
| 242 | + "response_type": "code", |
| 243 | + "state": "random_state_string", |
| 244 | + "scope": "read write", |
| 245 | + "redirect_uri": "http://example.org", |
| 246 | + "allow": True, |
| 247 | + }, |
| 248 | + ) |
| 249 | + self.assertEqual(response.status_code, 302) |
| 250 | + self.assertTrue("session_state" in response["Location"]) |
| 251 | + |
| 252 | + |
209 | 253 | def mock_request():
|
210 | 254 | """
|
211 | 255 | Dummy request with an AnonymousUser attached.
|
|
0 commit comments