diff --git a/src/apps/user/sso_views.py b/src/apps/user/sso_views.py index 48ec62b..007d05e 100644 --- a/src/apps/user/sso_views.py +++ b/src/apps/user/sso_views.py @@ -183,3 +183,9 @@ class SsoCallbackView(APIView): response = HttpResponse(status=303) response["Location"] = redirect_path return response + + +class SsoCallbackWithoutSlashView(SsoCallbackView): + """Accept legacy callback URLs without duplicating the public API schema.""" + + swagger_schema = None diff --git a/src/core/api_v1_urls.py b/src/core/api_v1_urls.py index 7366654..671dea0 100644 --- a/src/core/api_v1_urls.py +++ b/src/core/api_v1_urls.py @@ -11,7 +11,11 @@ from apps.core.views import ( BackgroundJobStatusView, BackgroundJobStreamView, ) -from apps.user.sso_views import SsoCallbackView, SsoStartView +from apps.user.sso_views import ( + SsoCallbackView, + SsoCallbackWithoutSlashView, + SsoStartView, +) from django.urls import include, path app_name = "api_v1" @@ -24,7 +28,7 @@ jobs_urlpatterns = [ urlpatterns = [ # Accept IAS POST forms without a slash without CommonMiddleware's 301. - path("auth/sso", SsoCallbackView.as_view()), + path("auth/sso", SsoCallbackWithoutSlashView.as_view()), path("auth/sso/", SsoCallbackView.as_view(), name="sso-callback"), path("auth/sso/start/", SsoStartView.as_view(), name="sso-start"), path("analytics/", include("apps.organization.analytics_root_urls")), diff --git a/tests/apps/user/test_sso.py b/tests/apps/user/test_sso.py index b243c4b..3837814 100644 --- a/tests/apps/user/test_sso.py +++ b/tests/apps/user/test_sso.py @@ -39,6 +39,26 @@ class SsoStartViewTest(SimpleTestCase): {"target": ["fkc"], "path": ["/open-data?scope=rosatom"]}, ) + def test_callback_alias_does_not_duplicate_openapi_operations(self): + from core.api_v1_urls import urlpatterns + from drf_yasg import openapi + from drf_yasg.generators import OpenAPISchemaGenerator + + schema = OpenAPISchemaGenerator( + info=openapi.Info(title="SSO", default_version="v1"), + patterns=[ + item for item in urlpatterns if str(item.pattern).startswith("auth/sso") + ], + ).get_schema(request=None, public=True) + operations = [ + operation.operation_id + for item in schema.paths.values() + for _, operation in item.operations + ] + self.assertEqual(len(operations), len(set(operations))) + self.assertIn("/sso/", schema.paths) + self.assertNotIn("/sso", schema.paths) + def test_rejects_absolute_redirect_path(self): response = self.client.get( "/api/v1/auth/sso/start/",