Get baseline 100% clean coverage (#1553)

This commit is contained in:
Max Isbey 2025-11-11 13:09:32 +00:00 • committed by GitHub
commit 89e9c43acf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 1032 additions and 1084 deletions

View file

@ -99,7 +99,7 @@ class RequireAuthMiddleware:
"""Send an authentication error response with WWW-Authenticate header."""
# Build WWW-Authenticate header value
www_auth_parts = [f'error="{error}"', f'error_description="{description}"']
if self.resource_metadata_url:
if self.resource_metadata_url: # pragma: no cover
www_auth_parts.append(f'resource_metadata="{self.resource_metadata_url}"')
www_authenticate = f"Bearer {', '.join(www_auth_parts)}"

View file

@ -7,7 +7,7 @@ from mcp.shared.auth import OAuthClientInformationFull
class AuthenticationError(Exception):
def __init__(self, message: str):
self.message = message
self.message = message # pragma: no cover
class ClientAuthenticator:
@ -34,18 +34,18 @@ class ClientAuthenticator:
# Look up client information
client = await self.provider.get_client(client_id)
if not client:
raise AuthenticationError("Invalid client_id")
raise AuthenticationError("Invalid client_id") # pragma: no cover
# If client from the store expects a secret, validate that the request provides
# that secret
if client.client_secret:
if client.client_secret: # pragma: no branch
if not client_secret:
raise AuthenticationError("Client secret is required")
raise AuthenticationError("Client secret is required") # pragma: no cover
if client.client_secret != client_secret:
raise AuthenticationError("Invalid client_secret")
raise AuthenticationError("Invalid client_secret") # pragma: no cover
if client.client_secret_expires_at and client.client_secret_expires_at < int(time.time()):
raise AuthenticationError("Client secret has expired")
raise AuthenticationError("Client secret has expired") # pragma: no cover
return client