Skip to main content
Glama
test_auth_exceptions.py4.37 kB
"""Unit tests for Auth Exceptions. Tests custom authentication exception classes. """ from __future__ import annotations from sso_mcp_server.auth.exceptions import ( AuthError, AuthNotConfiguredError, ConfigurationError, InteractiveAuthFailedError, NotAuthenticatedError, SilentAuthFailedError, TokenExpiredError, ) class TestAuthError: """Tests for base AuthError exception.""" def test_auth_error_with_message_only(self) -> None: """Test AuthError with message only.""" error = AuthError("Test error") assert str(error) == "Test error" assert error.message == "Test error" assert error.action is None assert error.code == "AUTH_ERROR" def test_auth_error_with_all_params(self) -> None: """Test AuthError with all parameters.""" error = AuthError("Test error", action="Do something", code="TEST_ERROR") assert error.message == "Test error" assert error.action == "Do something" assert error.code == "TEST_ERROR" assert "Test error" in str(error) assert "Action: Do something" in str(error) class TestConfigurationError: """Tests for ConfigurationError exception.""" def test_with_action(self) -> None: """Test ConfigurationError with custom action.""" error = ConfigurationError("Missing value", action="Set the VALUE env var") assert error.code == "CONFIG_ERROR" assert "Missing value" in error.message assert "Set the VALUE env var" in error.action def test_default_action(self) -> None: """Test ConfigurationError with default action.""" error = ConfigurationError("Missing config") assert error.action is not None assert ".env" in error.action.lower() class TestAuthNotConfiguredError: """Tests for AuthNotConfiguredError exception.""" def test_default_values(self) -> None: """Test AuthNotConfiguredError has correct defaults.""" error = AuthNotConfiguredError() assert error.code == "AUTH_NOT_CONFIGURED" assert "not configured" in error.message.lower() assert error.action is not None class TestNotAuthenticatedError: """Tests for NotAuthenticatedError exception.""" def test_default_values(self) -> None: """Test NotAuthenticatedError has correct defaults.""" error = NotAuthenticatedError() assert error.code == "NOT_AUTHENTICATED" assert "required" in error.message.lower() assert error.action is not None class TestTokenExpiredError: """Tests for TokenExpiredError exception.""" def test_default_values(self) -> None: """Test TokenExpiredError has correct defaults.""" error = TokenExpiredError() assert error.code == "TOKEN_EXPIRED" assert "expired" in error.message.lower() assert error.action is not None class TestSilentAuthFailedError: """Tests for SilentAuthFailedError exception.""" def test_default_values(self) -> None: """Test SilentAuthFailedError has correct defaults.""" error = SilentAuthFailedError() assert error.code == "SILENT_AUTH_FAILED" assert "silent" in error.message.lower() def test_with_reason(self) -> None: """Test SilentAuthFailedError with reason.""" error = SilentAuthFailedError(reason="Token expired") assert "Token expired" in error.message class TestInteractiveAuthFailedError: """Tests for InteractiveAuthFailedError exception.""" def test_default_values(self) -> None: """Test InteractiveAuthFailedError has correct defaults.""" error = InteractiveAuthFailedError() assert error.code == "INTERACTIVE_AUTH_FAILED" assert "browser" in error.message.lower() or "authentication" in error.message.lower() def test_with_error_code(self) -> None: """Test InteractiveAuthFailedError with error code.""" error = InteractiveAuthFailedError(error="access_denied") assert "access_denied" in error.message def test_with_error_description(self) -> None: """Test InteractiveAuthFailedError with error description.""" error = InteractiveAuthFailedError( error="access_denied", error_description="User cancelled" ) assert "User cancelled" in error.message

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/DauQuangThanh/sso-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server