diff --git a/modoboa/core/commands/templates/settings.py.tpl b/modoboa/core/commands/templates/settings.py.tpl index a404ca01d..cab8a30e3 100644 --- a/modoboa/core/commands/templates/settings.py.tpl +++ b/modoboa/core/commands/templates/settings.py.tpl @@ -197,7 +197,8 @@ REST_FRAMEWORK = { SPECTACULAR_SETTINGS = { 'SCHEMA_PATH_PREFIX': r'/api/v1', 'TITLE': 'Modoboa API', - 'VERSION': '1.0.0' + 'VERSION': '1.0.0', + 'SERVE_PERMISSIONS': ['rest_framework.permissions.IsAuthenticated'], } # Modoboa settings diff --git a/modoboa/core/tests/test_api.py b/modoboa/core/tests/test_api.py index ef1fe5b77..043222304 100644 --- a/modoboa/core/tests/test_api.py +++ b/modoboa/core/tests/test_api.py @@ -4,16 +4,13 @@ from modoboa.lib.tests import ModoTestCase class OpenAPITestCase(ModoTestCase): - openapi_schema_url = reverse_lazy('openapi_schema') + openapi_schema_url = reverse_lazy('schema') def test_unauthorized(self): self.client.logout() - response = self.client.get("/docs/api/") - self.assertRedirects(response, "/accounts/login/?next=/docs/api/") - response = self.client.get(self.openapi_schema_url) - self.assertEqual(response.status_code, 403) + self.assertEqual(response.status_code, 401) def test_get_schema(self): self.assertEqual(self.openapi_schema_url, "/docs/openapi.json") @@ -24,7 +21,3 @@ class OpenAPITestCase(ModoTestCase): 'title': "Modoboa API", 'version': "1.0.0", }) - - def test_get_swagger_ui(self): - response = self.client.get("/docs/api/") - self.assertContains(response, "Modoboa API") diff --git a/test_project/test_project/settings.py b/test_project/test_project/settings.py index 29f83a8ff..a2579f81b 100644 --- a/test_project/test_project/settings.py +++ b/test_project/test_project/settings.py @@ -191,7 +191,8 @@ REST_FRAMEWORK = { SPECTACULAR_SETTINGS = { 'SCHEMA_PATH_PREFIX': r'/api/v1', 'TITLE': 'Modoboa API', - 'VERSION': '1.0.0' + 'VERSION': '1.0.0', + 'SERVE_PERMISSIONS': ['rest_framework.permissions.IsAuthenticated'], } # Modoboa settings