|
| 1 | +from django.contrib.auth import get_user_model |
| 2 | +from django.test import TestCase, override_settings |
| 3 | +from django.urls import reverse |
| 4 | + |
| 5 | +from oauth2_provider.models import get_application_model |
| 6 | + |
| 7 | + |
| 8 | +UserModel = get_user_model() |
| 9 | +Application = get_application_model() |
| 10 | + |
| 11 | + |
| 12 | +@override_settings( |
| 13 | + OAUTH2_PROVIDER={ |
| 14 | + "OIDC_ENABLED": True, |
| 15 | + "PKCE_REQUIRED": False, |
| 16 | + "SCOPES": { |
| 17 | + "openid": "OpenID connect", |
| 18 | + }, |
| 19 | + } |
| 20 | +) |
| 21 | +class TestUILocalesParam(TestCase): |
| 22 | + @classmethod |
| 23 | + def setUpTestData(cls): |
| 24 | + cls.application = Application.objects.create( |
| 25 | + name="Test Application", |
| 26 | + client_id="test", |
| 27 | + redirect_uris="https://www.example.com/", |
| 28 | + client_type=Application.CLIENT_PUBLIC, |
| 29 | + authorization_grant_type=Application.GRANT_AUTHORIZATION_CODE, |
| 30 | + ) |
| 31 | + cls.trusted_application = Application.objects.create( |
| 32 | + name="Trusted Application", |
| 33 | + client_id="trusted", |
| 34 | + redirect_uris="https://www.example.com/", |
| 35 | + client_type=Application.CLIENT_PUBLIC, |
| 36 | + authorization_grant_type=Application.GRANT_AUTHORIZATION_CODE, |
| 37 | + skip_authorization=True, |
| 38 | + ) |
| 39 | + cls.user = UserModel.objects.create_user("test_user") |
| 40 | + cls.url = reverse("oauth2_provider:authorize") |
| 41 | + |
| 42 | + def setUp(self): |
| 43 | + self.client.force_login(self.user) |
| 44 | + |
| 45 | + def test_application_ui_locales_param(self): |
| 46 | + response = self.client.get( |
| 47 | + f"{self.url}?response_type=code&client_id=test&scope=openid&ui_locales=de", |
| 48 | + ) |
| 49 | + self.assertEqual(response.status_code, 200) |
| 50 | + self.assertTemplateUsed(response, "oauth2_provider/authorize.html") |
| 51 | + |
| 52 | + def test_trusted_application_ui_locales_param(self): |
| 53 | + response = self.client.get( |
| 54 | + f"{self.url}?response_type=code&client_id=trusted&scope=openid&ui_locales=de", |
| 55 | + ) |
| 56 | + self.assertEqual(response.status_code, 302) |
| 57 | + self.assertRegex(response.url, r"https://www\.example\.com/\?code=[a-zA-Z0-9]+") |
0 commit comments