88
88
from mcpgateway .utils .retry_manager import ResilientHttpClient
89
89
from mcpgateway .utils .security_cookies import set_auth_cookie
90
90
from mcpgateway .utils .verify_credentials import require_auth , require_basic_auth
91
+ from mcpgateway .middleware .rate_limiter import content_rate_limiter
91
92
92
93
# Import the shared logging service from main
93
94
# This will be set by main.py when it imports admin_router
@@ -1504,7 +1505,16 @@ async def admin_ui(
1504
1505
True
1505
1506
>>>
1506
1507
>>> # Test with populated data (mocking a few items)
1507
- >>> mock_server = ServerRead(id="s1", name="S1", description="d", created_at=datetime.now(timezone.utc), updated_at=datetime.now(timezone.utc), is_active=True, associated_tools=[], associated_resources=[], associated_prompts=[], icon="i", metrics=ServerMetrics(total_executions=0, successful_executions=0, failed_executions=0, failure_rate=0.0, min_response_time=0.0, max_response_time=0.0, avg_response_time=0.0, last_execution_time=None))
1508
+ >>> mock_server = ServerRead(
1509
+ ... id="s1", name="S1", description="d", created_at=datetime.now(timezone.utc),
1510
+ ... updated_at=datetime.now(timezone.utc), is_active=True, associated_tools=[],
1511
+ ... associated_resources=[], associated_prompts=[], icon="i",
1512
+ ... metrics=ServerMetrics(
1513
+ ... total_executions=0, successful_executions=0, failed_executions=0,
1514
+ ... failure_rate=0.0, min_response_time=0.0, max_response_time=0.0,
1515
+ ... avg_response_time=0.0, last_execution_time=None
1516
+ ... )
1517
+ ... )
1508
1518
>>> mock_tool = ToolRead(
1509
1519
... id="t1", name="T1", original_name="T1", url="http://t1.com", description="d",
1510
1520
... created_at=datetime.now(timezone.utc), updated_at=datetime.now(timezone.utc),
@@ -2588,7 +2598,10 @@ async def admin_add_gateway(request: Request, db: Session = Depends(get_db), use
2588
2598
True
2589
2599
>>>
2590
2600
>>> # Error path: Gateway connection error
2591
- >>> form_data_conn_error = FormData([("name", "Bad Gateway"), ("url", "http://bad.com"), ("auth_type", "bearer"), ("auth_token", "abc")]) # Added auth_type and token
2601
+ >>> form_data_conn_error = FormData([
2602
+ ... ("name", "Bad Gateway"), ("url", "http://bad.com"),
2603
+ ... ("auth_type", "bearer"), ("auth_token", "abc")
2604
+ ... ]) # Added auth_type and token
2592
2605
>>> mock_request_conn_error = MagicMock(spec=Request)
2593
2606
>>> mock_request_conn_error.form = AsyncMock(return_value=form_data_conn_error)
2594
2607
>>> gateway_service.register_gateway = AsyncMock(side_effect=GatewayConnectionError("Connection failed"))
@@ -2601,7 +2614,10 @@ async def admin_add_gateway(request: Request, db: Session = Depends(get_db), use
2601
2614
True
2602
2615
>>>
2603
2616
>>> # Error path: Validation error (e.g., missing name)
2604
- >>> form_data_validation_error = FormData([("url", "http://no-name.com"), ("auth_type", "headers"), ("auth_header_key", "X-Key"), ("auth_header_value", "val")]) # 'name' is missing, added auth_type
2617
+ >>> form_data_validation_error = FormData([
2618
+ ... ("url", "http://no-name.com"), ("auth_type", "headers"),
2619
+ ... ("auth_header_key", "X-Key"), ("auth_header_value", "val")
2620
+ ... ]) # 'name' is missing, added auth_type
2605
2621
>>> mock_request_validation_error = MagicMock(spec=Request)
2606
2622
>>> mock_request_validation_error.form = AsyncMock(return_value=form_data_validation_error)
2607
2623
>>> # No need to mock register_gateway, ValidationError happens during GatewayCreate()
@@ -4191,12 +4207,19 @@ async def get_aggregated_metrics(
4191
4207
4192
4208
4193
4209
@admin_router .post ("/rate-limiter/reset" )
4194
- async def admin_reset_rate_limiter (user : str = Depends (require_auth )) -> JSONResponse :
4195
- """Reset the rate limiter state."""
4196
- from mcpgateway .middleware .rate_limiter import content_rate_limiter
4210
+ async def admin_reset_rate_limiter (_user : str = Depends (require_auth )) -> JSONResponse :
4211
+ """Reset the rate limiter state.
4212
+
4213
+ Args:
4214
+ _user: Authenticated user dependency (unused but required for auth).
4215
+
4216
+ Returns:
4217
+ JSONResponse: Success message indicating rate limiter was reset.
4218
+ """
4197
4219
await content_rate_limiter .reset ()
4198
4220
return JSONResponse (content = {"message" : "Rate limiter reset successfully" , "success" : True }, status_code = 200 )
4199
4221
4222
+
4200
4223
@admin_router .post ("/metrics/reset" , response_model = Dict [str , object ])
4201
4224
async def admin_reset_metrics (db : Session = Depends (get_db ), user : str = Depends (require_auth )) -> Dict [str , object ]:
4202
4225
"""
0 commit comments