|
21 | 21 | MCPServer, |
22 | 22 | ToolFilter, |
23 | 23 | Tools, |
24 | | - Transport, |
25 | | - build_auth_headers, |
26 | 24 | filter_tools, |
27 | 25 | ) |
28 | 26 | from afm_cli.tools.mcp import ( |
@@ -97,89 +95,6 @@ class MockArgsSchema(BaseModel): |
97 | 95 | # ============================================================================= |
98 | 96 |
|
99 | 97 |
|
100 | | -class TestBuildAuthHeaders: |
101 | | - """Tests for build_auth_headers function.""" |
102 | | - |
103 | | - def test_none_auth_returns_empty_dict(self): |
104 | | - """No auth returns empty headers.""" |
105 | | - result = build_auth_headers(None) |
106 | | - assert result == {} |
107 | | - |
108 | | - def test_bearer_auth_returns_bearer_header(self): |
109 | | - """Bearer auth returns Authorization: Bearer header.""" |
110 | | - auth = ClientAuthentication(type="bearer", token="my-token") |
111 | | - result = build_auth_headers(auth) |
112 | | - assert result == {"Authorization": "Bearer my-token"} |
113 | | - |
114 | | - def test_basic_auth_returns_basic_header(self): |
115 | | - """Basic auth returns base64-encoded Authorization header.""" |
116 | | - auth = ClientAuthentication(type="basic", username="user", password="pass") |
117 | | - result = build_auth_headers(auth) |
118 | | - # "user:pass" -> base64 "dXNlcjpwYXNz" |
119 | | - assert result == {"Authorization": "Basic dXNlcjpwYXNz"} |
120 | | - |
121 | | - def test_api_key_auth_returns_api_key_header(self): |
122 | | - """API key auth returns Authorization header with raw key.""" |
123 | | - auth = ClientAuthentication(type="api-key", api_key="my-api-key") |
124 | | - result = build_auth_headers(auth) |
125 | | - assert result == {"Authorization": "my-api-key"} |
126 | | - |
127 | | - def test_bearer_auth_missing_token_raises_pydantic_error(self): |
128 | | - """Bearer auth without token raises Pydantic ValidationError at model creation.""" |
129 | | - # Pydantic validates at model creation time, not at build_auth_headers |
130 | | - from pydantic import ValidationError |
131 | | - |
132 | | - with pytest.raises(ValidationError, match="requires 'token' field"): |
133 | | - ClientAuthentication(type="bearer") |
134 | | - |
135 | | - def test_basic_auth_missing_username_raises_pydantic_error(self): |
136 | | - """Basic auth without username raises Pydantic ValidationError at model creation.""" |
137 | | - from pydantic import ValidationError |
138 | | - |
139 | | - with pytest.raises(ValidationError, match="requires 'username' and 'password'"): |
140 | | - ClientAuthentication(type="basic", password="pass") |
141 | | - |
142 | | - def test_basic_auth_missing_password_raises_pydantic_error(self): |
143 | | - """Basic auth without password raises Pydantic ValidationError at model creation.""" |
144 | | - from pydantic import ValidationError |
145 | | - |
146 | | - with pytest.raises(ValidationError, match="requires 'username' and 'password'"): |
147 | | - ClientAuthentication(type="basic", username="user") |
148 | | - |
149 | | - def test_api_key_auth_missing_key_raises_pydantic_error(self): |
150 | | - """API key auth without key raises Pydantic ValidationError at model creation.""" |
151 | | - from pydantic import ValidationError |
152 | | - |
153 | | - with pytest.raises(ValidationError, match="requires 'api_key' field"): |
154 | | - ClientAuthentication(type="api-key") |
155 | | - |
156 | | - def test_oauth2_auth_not_supported(self): |
157 | | - """OAuth2 auth raises not supported error.""" |
158 | | - auth = ClientAuthentication(type="oauth2") |
159 | | - with pytest.raises(MCPAuthenticationError, match="not yet supported"): |
160 | | - build_auth_headers(auth) |
161 | | - |
162 | | - def test_jwt_auth_not_supported(self): |
163 | | - """JWT auth raises not supported error.""" |
164 | | - auth = ClientAuthentication(type="jwt") |
165 | | - with pytest.raises(MCPAuthenticationError, match="not yet supported"): |
166 | | - build_auth_headers(auth) |
167 | | - |
168 | | - def test_unknown_auth_type_raises_error(self): |
169 | | - """Unknown auth type raises MCPAuthenticationError.""" |
170 | | - auth = ClientAuthentication(type="unknown") |
171 | | - with pytest.raises( |
172 | | - MCPAuthenticationError, match="Unsupported authentication type" |
173 | | - ): |
174 | | - build_auth_headers(auth) |
175 | | - |
176 | | - def test_auth_type_is_case_insensitive(self): |
177 | | - """Auth type matching is case-insensitive.""" |
178 | | - auth = ClientAuthentication(type="BEARER", token="my-token") |
179 | | - result = build_auth_headers(auth) |
180 | | - assert result == {"Authorization": "Bearer my-token"} |
181 | | - |
182 | | - |
183 | 98 | class TestBuildHttpxAuth: |
184 | 99 | """Tests for build_httpx_auth function.""" |
185 | 100 |
|
@@ -385,7 +300,7 @@ def test_build_connection_config_with_auth(self): |
385 | 300 | config = client._build_connection_config() |
386 | 301 |
|
387 | 302 | assert "auth" in config |
388 | | - assert isinstance(config["auth"], BearerAuth) |
| 303 | + assert isinstance(config.get("auth"), BearerAuth) |
389 | 304 |
|
390 | 305 | @pytest.mark.asyncio |
391 | 306 | async def test_get_tools_calls_mcp_client(self): |
|
0 commit comments