Skip to content

Commit 2837355

Browse files
committed
Fix smoketest
Signed-off-by: Mihai Criveti <[email protected]>
1 parent 33ac92f commit 2837355

20 files changed

+46
-39
lines changed

mcpgateway/services/gateway_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ async def check_health_of_gateways(self, gateways: List[DbGateway]) -> bool:
589589
# Mark successful check
590590
gateway.last_seen = datetime.utcnow()
591591

592-
except Exception as e:
592+
except Exception:
593593
await self._handle_gateway_failure(gateway)
594594

595595
# All gateways passed

smoketest.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ def port_open(port: int, host="127.0.0.1", timeout=1.0) -> bool:
153153
return s.connect_ex((host, port)) == 0
154154

155155

156-
def wait_http_ok(url: str, timeout: int = 30) -> bool:
156+
def wait_http_ok(url: str, timeout: int = 30, *, headers: dict | None = None) -> bool:
157157
import requests
158158

159159
end = time.time() + timeout
160160
while time.time() < end:
161161
try:
162-
if requests.get(url, timeout=2, verify=False).status_code == 200:
162+
if requests.get(url, timeout=2, verify=False, headers=headers).status_code == 200:
163163
return True
164164
except requests.RequestException:
165165
pass
@@ -174,14 +174,27 @@ def wait_http_ok(url: str, timeout: int = 30) -> bool:
174174

175175

176176
def generate_jwt() -> str:
177-
return (
178-
subprocess.check_output(
179-
["docker", "exec", DOCKER_CONTAINER, "python3", "-m", "mcpgateway.utils.create_jwt_token", "--username", "admin", "--exp", "300", "--secret", "my-test-key"],
180-
text=True,
181-
)
182-
.strip()
183-
.strip('"')
184-
)
177+
"""
178+
Create a short-lived admin JWT that matches the gateway's settings.
179+
Resolution order → environment-variable override, then package defaults.
180+
"""
181+
user = os.getenv("BASIC_AUTH_USER", "admin")
182+
secret = os.getenv("JWT_SECRET_KEY", "my-test-key")
183+
expiry = os.getenv("TOKEN_EXPIRY", "300") # seconds
184+
185+
cmd = [
186+
"docker",
187+
"exec",
188+
DOCKER_CONTAINER,
189+
"python3",
190+
"-m",
191+
"mcpgateway.utils.create_jwt_token",
192+
"--username", user,
193+
"--exp", expiry,
194+
"--secret", secret,
195+
]
196+
return subprocess.check_output(cmd, text=True).strip().strip('"')
197+
185198

186199

187200
def request(method: str, path: str, *, json_data=None, **kw):
@@ -238,11 +251,19 @@ def step_3_docker_build():
238251

239252
def step_4_docker_run():
240253
sh(MAKE_DOCKER_RUN, "4️⃣ Run Docker container (HTTPS)")
241-
# wait until gateway exposes the basic endpoints
254+
255+
# Build one token and reuse it for the health probes below.
256+
token = generate_jwt()
257+
auth_headers = {"Authorization": f"Bearer {token}"}
258+
259+
# Probe endpoints until they respond with 200.
242260
for ep in ("/health", "/ready", "/version"):
243-
full = f"https://localhost:{PORT_GATEWAY}{ep}"
244-
if not wait_http_ok(full, 45):
261+
full = f"https://localhost:{PORT_GATEWAY}{ep}"
262+
need_auth = os.getenv("AUTH_REQUIRED", "true").lower() == "true"
263+
headers = auth_headers if (ep == "/version" or need_auth) else None
264+
if not wait_http_ok(full, 45, headers=headers):
245265
raise RuntimeError(f"Gateway endpoint {ep} not ready")
266+
246267
logging.info("✅ Gateway /health /ready /version all OK")
247268

248269

tests/unit/mcpgateway/handlers/test_sampling.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
from __future__ import annotations
2020

21-
import asyncio
22-
from types import SimpleNamespace
2321
from typing import List
2422

2523
import pytest

tests/unit/mcpgateway/services/test_gateway_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from __future__ import annotations
1616

1717
from datetime import datetime, timezone
18-
from unittest.mock import AsyncMock, MagicMock, Mock, patch
18+
from unittest.mock import AsyncMock, MagicMock, Mock
1919

2020
import pytest
2121

tests/unit/mcpgateway/services/test_prompt_service.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414

1515
from __future__ import annotations
1616

17-
import asyncio
1817
from datetime import datetime, timezone
19-
from string import Formatter
20-
from typing import Any, Dict, List, Optional
18+
from typing import Any, List, Optional
2119
from unittest.mock import AsyncMock, MagicMock, Mock
2220

2321
import pytest
@@ -27,11 +25,10 @@
2725
from mcpgateway.schemas import PromptCreate, PromptRead, PromptUpdate
2826
from mcpgateway.services.prompt_service import (
2927
PromptError,
30-
PromptNameConflictError,
3128
PromptNotFoundError,
3229
PromptService,
3330
)
34-
from mcpgateway.types import LogLevel, Message, PromptResult, Role, TextContent
31+
from mcpgateway.types import Message, PromptResult, Role
3532

3633
# ---------------------------------------------------------------------------
3734
# helpers

tests/unit/mcpgateway/services/test_resource_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
ResourceError,
1717
ResourceNotFoundError,
1818
ResourceService,
19-
ResourceURIConflictError,
2019
)
2120

2221

tests/unit/mcpgateway/services/test_server_service.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
Tests for server service implementation.
88
"""
99

10-
from unittest.mock import AsyncMock, MagicMock, Mock, patch
10+
from unittest.mock import AsyncMock, MagicMock, Mock
1111

1212
import pytest
13-
from sqlalchemy.exc import IntegrityError
1413

1514
from mcpgateway.db import Prompt as DbPrompt
1615
from mcpgateway.db import Resource as DbResource

tests/unit/mcpgateway/services/test_tool_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from mcpgateway.services.tool_service import (
1919
ToolError,
2020
ToolInvocationError,
21-
ToolNameConflictError,
2221
ToolNotFoundError,
2322
ToolService,
2423
)

tests/unit/mcpgateway/test_admin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
from mcpgateway.services.gateway_service import GatewayService
5757
from mcpgateway.services.prompt_service import PromptService
5858
from mcpgateway.services.resource_service import ResourceService
59-
from mcpgateway.services.root_service import RootService
6059
from mcpgateway.services.server_service import ServerNotFoundError, ServerService
6160
from mcpgateway.services.tool_service import (
6261
ToolNameConflictError,

tests/unit/mcpgateway/test_cli.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
from __future__ import annotations
1818

19-
import importlib
2019
import sys
21-
from pathlib import Path
2220
from typing import Any, Dict, List
2321

2422
import pytest

0 commit comments

Comments
 (0)