diff --git a/env.d/development/common.dist b/env.d/development/common.dist index a63f2ed4..161cf649 100644 --- a/env.d/development/common.dist +++ b/env.d/development/common.dist @@ -104,3 +104,6 @@ APPLICATION_JWT_AUDIENCE=http://localhost:8071/external-api/v1.0/ APPLICATION_JWT_SECRET_KEY=devKey APPLICATION_BASE_URL=http://localhost:3000 +# Diagnostics +CONNECTION_TEST_ENABLED = True + diff --git a/src/backend/core/api/__init__.py b/src/backend/core/api/__init__.py index b343dbd4..7d21dc71 100644 --- a/src/backend/core/api/__init__.py +++ b/src/backend/core/api/__init__.py @@ -65,6 +65,9 @@ def get_frontend_configuration(request): "default_access_level": settings.RESOURCE_DEFAULT_ACCESS_LEVEL, }, "subtitle": {"enabled": settings.ROOM_SUBTITLE_ENABLED}, + "diagnostics": { + "connection_test_enabled": settings.CONNECTION_TEST_ENABLED + }, "livekit": { "url": settings.LIVEKIT_CONFIGURATION["url"], "force_wss_protocol": settings.LIVEKIT_FORCE_WSS_PROTOCOL, diff --git a/src/backend/core/api/feature_flag.py b/src/backend/core/api/feature_flag.py index db9251fb..eca2a2fb 100644 --- a/src/backend/core/api/feature_flag.py +++ b/src/backend/core/api/feature_flag.py @@ -17,6 +17,7 @@ class FeatureFlag: "addons": "ADDONS_ENABLED", "application": "APPLICATION_ENABLED", "roomkit": "ROOMKIT_ENABLED", + "connection_test": "CONNECTION_TEST_ENABLED", } @classmethod diff --git a/src/backend/core/api/viewsets.py b/src/backend/core/api/viewsets.py index cfc27a40..1f5401c7 100644 --- a/src/backend/core/api/viewsets.py +++ b/src/backend/core/api/viewsets.py @@ -1597,6 +1597,7 @@ class DiagnosticsViewSet(viewsets.ViewSet): throttling.ConnectionTestAnonRateThrottle, ], ) + @FeatureFlag.require("connection_test") def connection(self, request): """Return a short-lived LiveKit token for an ephemeral test room. diff --git a/src/backend/core/tests/test_api_diagnostics.py b/src/backend/core/tests/test_api_diagnostics.py index 49fa8a84..ddede3f6 100644 --- a/src/backend/core/tests/test_api_diagnostics.py +++ b/src/backend/core/tests/test_api_diagnostics.py @@ -154,3 +154,12 @@ def test_api_diagnostics_connection_is_throttled(throttle_class, client): response = client.post("/api/v1.0/diagnostics/connection/") assert response.status_code == 429 + + +def test_api_diagnostics_connection_is_throttled(client, settings): + """Should return a not found error when the connection diagnostics feature is disabled.""" + + settings.CONNECTION_TEST_ENABLED = False + + response = client.post("/api/v1.0/diagnostics/connection/") + assert response.status_code == 404 diff --git a/src/backend/meet/settings.py b/src/backend/meet/settings.py index e307cb66..f9accbdc 100755 --- a/src/backend/meet/settings.py +++ b/src/backend/meet/settings.py @@ -665,6 +665,11 @@ class Base(Configuration): environ_prefix=None, default=False, ) + CONNECTION_TEST_ENABLED = values.BooleanValue( + environ_name="CONNECTION_TEST_ENABLED", + environ_prefix=None, + default=False, + ) CONNECTION_TEST_TOKEN_TTL_SECONDS = values.PositiveIntegerValue( 300, environ_name="CONNECTION_TEST_TOKEN_TTL_SECONDS", @@ -1290,6 +1295,8 @@ class Test(Base): ADDONS_CSRF_SECRET = "secret-key-padded-for-minimum-len!-addons" # noqa:S105 ADDONS_TOKEN_SECRET_KEY = "secret-key-padded-for-minimum-len!-addons" # noqa:S105 + CONNECTION_TEST_ENABLED = True + def __init__(self): # pylint: disable=invalid-name self.INSTALLED_APPS += ["drf_spectacular_sidecar"]