Skip to content

Commit afc9cee

Browse files
DX-119909: harden auth warning logging
1 parent c2064ea commit afc9cee

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/dremioai/servers/mcp.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,18 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint):
183183
and request.url.path.startswith("/mcp")
184184
):
185185
client_host = request.client.host if request.client else "unknown"
186+
inst = settings.instance()
187+
endpoint = (
188+
str(inst.dremio.uri)
189+
if inst is not None and inst.dremio is not None and inst.dremio.uri
190+
else None
191+
)
186192
self.logger.warning(
187193
"Unauthorized request rejected",
188194
path=request.url.path,
189195
client=client_host,
190196
project_id=ProjectIdMiddleware.get_project_id(),
191-
endpoint=str(settings.instance().dremio.uri),
197+
endpoint=endpoint,
192198
)
193199
# Return 401 with WWW-Authenticate header
194200
return StarletteResponse(

tests/servers/test_jwks_verifier.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from starlette.responses import Response
3737

3838
from dremioai import log
39+
from dremioai.config import settings
3940
from dremioai.servers.jwks_verifier import JWKSVerifier, VerifiedClaims, TokenExpiredError
4041
from dremioai.servers.mcp import (
4142
FastMCPServerWithAuthToken,
@@ -293,6 +294,7 @@ class TestDispatchWarning:
293294

294295
@pytest.mark.asyncio
295296
async def test_dispatch_logs_warning_on_401(self, caplog):
297+
settings.set_base_settings(settings.Settings())
296298
middleware = RequireAuthWithWWWAuthenticateMiddleware(app=MagicMock())
297299

298300
mock_user = MagicMock()

0 commit comments

Comments
 (0)