|
13 | 13 | from django.test import Client |
14 | 14 | from unittest.mock import patch, MagicMock |
15 | 15 | from urllib.parse import parse_qs, urlencode, urlparse |
| 16 | +import uuid |
16 | 17 | from waffle.testutils import override_switch |
17 | 18 |
|
18 | 19 | from apps.test import BaseApiTest |
@@ -1123,3 +1124,37 @@ def test_permission_denied_raised_for_refresh_token_app_not_in_flag( |
1123 | 1124 |
|
1124 | 1125 | with self.assertRaises(AccessDeniedTokenCustomError): |
1125 | 1126 | view_instance.validate_v3_token_call(request) |
| 1127 | + |
| 1128 | + def test_invalid_uuid_authorize_call(self): |
| 1129 | + """BB2-4326: Ensure a 404 is thrown if a non-UUID is passed to an authorize endpoint |
| 1130 | + """ |
| 1131 | + auth_uri_v1 = reverse("oauth2_provider:authorize-instance", args=['jolokia']) |
| 1132 | + auth_uri_v2 = reverse("oauth2_provider_v2:authorize-instance-v2", args=['jolokia']) |
| 1133 | + auth_uri_v3 = reverse("oauth2_provider_v3:authorize-instance-v3", args=['jolokia']) |
| 1134 | + |
| 1135 | + response_v1 = self.client.get(auth_uri_v1) |
| 1136 | + response_v2 = self.client.get(auth_uri_v2) |
| 1137 | + response_v3 = self.client.get(auth_uri_v3) |
| 1138 | + |
| 1139 | + assert response_v1.status_code == HTTPStatus.NOT_FOUND |
| 1140 | + assert response_v2.status_code == HTTPStatus.NOT_FOUND |
| 1141 | + assert response_v3.status_code == HTTPStatus.NOT_FOUND |
| 1142 | + |
| 1143 | + @override_switch('v3_endpoints', active=True) |
| 1144 | + def test_valid_uuid_authorize_call(self): |
| 1145 | + """BB2-4326: Ensure a 302 is thrown if a valid UUID is passed to an authorize endpoint |
| 1146 | + """ |
| 1147 | + auth_uri_v1 = reverse("oauth2_provider:authorize-instance", args=[uuid.uuid4()]) |
| 1148 | + auth_uri_v2 = reverse("oauth2_provider_v2:authorize-instance-v2", args=[uuid.uuid4()]) |
| 1149 | + auth_uri_v3 = reverse("oauth2_provider_v3:authorize-instance-v3", args=[uuid.uuid4()]) |
| 1150 | + |
| 1151 | + response_v1 = self.client.get(auth_uri_v1) |
| 1152 | + response_v2 = self.client.get(auth_uri_v2) |
| 1153 | + response_v3 = self.client.get(auth_uri_v3) |
| 1154 | + |
| 1155 | + assert response_v1.status_code == HTTPStatus.FOUND |
| 1156 | + assert response_v2.status_code == HTTPStatus.FOUND |
| 1157 | + # The behavior is different for v3, as we check v3 authorize calls to see if the application is in |
| 1158 | + # the v3_early_adopter flag (part of BB2-4250). Because all of the mocks are not included in this test |
| 1159 | + # such that the authorize call will return a 302 for v3, v3 in this test throws a 403 |
| 1160 | + assert response_v3.status_code == HTTPStatus.FORBIDDEN |
0 commit comments