add defaults for websockets

This commit is contained in:
Aarushi
2024-08-07 13:52:53 +01:00
parent 2e377e6a65
commit 3be2ce97f2
2 changed files with 18 additions and 15 deletions

View File

@@ -277,21 +277,24 @@ class AgentServer(AppService):
)
async def authenticate_websocket(self, websocket: WebSocket) -> str:
token = websocket.query_params.get("token")
if not token:
await websocket.close(code=4001, reason="Missing authentication token")
return ""
try:
payload = parse_jwt_token(token)
user_id = payload.get("sub")
if not user_id:
await websocket.close(code=4002, reason="Invalid token")
if settings.config.enable_auth.lower() == "true":
token = websocket.query_params.get("token")
if not token:
await websocket.close(code=4001, reason="Missing authentication token")
return ""
return user_id
except ValueError:
await websocket.close(code=4003, reason="Invalid token")
return ""
try:
payload = parse_jwt_token(token)
user_id = payload.get("sub")
if not user_id:
await websocket.close(code=4002, reason="Invalid token")
return ""
return user_id
except ValueError:
await websocket.close(code=4003, reason="Invalid token")
return ""
else:
return "3e53486c-cf57-477e-ba2a-cb02dc828e1a"
async def websocket_router(self, websocket: WebSocket):
user_id = await self.authenticate_websocket(websocket)

View File

@@ -5,7 +5,7 @@ from autogpt_server.executor import ExecutionScheduler
from autogpt_server.usecases.sample import create_test_graph, create_test_user
from autogpt_server.util.service import get_service_client
@pytest.mark.skip(reason="flakey test, needs to be investigated")
@pytest.mark.asyncio(scope="session")
async def test_agent_schedule(server):
await db.connect()