|
23 | 23 | StdioTransport, |
24 | 24 | ToolFilter, |
25 | 25 | Tools, |
26 | | - build_auth_headers, |
27 | 26 | filter_tools, |
28 | 27 | ) |
29 | 28 | from afm_cli.tools.mcp import ( |
@@ -114,89 +113,6 @@ class MockArgsSchema(BaseModel): |
114 | 113 | # ============================================================================= |
115 | 114 |
|
116 | 115 |
|
117 | | -class TestBuildAuthHeaders: |
118 | | - """Tests for build_auth_headers function.""" |
119 | | - |
120 | | - def test_none_auth_returns_empty_dict(self): |
121 | | - """No auth returns empty headers.""" |
122 | | - result = build_auth_headers(None) |
123 | | - assert result == {} |
124 | | - |
125 | | - def test_bearer_auth_returns_bearer_header(self): |
126 | | - """Bearer auth returns Authorization: Bearer header.""" |
127 | | - auth = ClientAuthentication(type="bearer", token="my-token") |
128 | | - result = build_auth_headers(auth) |
129 | | - assert result == {"Authorization": "Bearer my-token"} |
130 | | - |
131 | | - def test_basic_auth_returns_basic_header(self): |
132 | | - """Basic auth returns base64-encoded Authorization header.""" |
133 | | - auth = ClientAuthentication(type="basic", username="user", password="pass") |
134 | | - result = build_auth_headers(auth) |
135 | | - # "user:pass" -> base64 "dXNlcjpwYXNz" |
136 | | - assert result == {"Authorization": "Basic dXNlcjpwYXNz"} |
137 | | - |
138 | | - def test_api_key_auth_returns_api_key_header(self): |
139 | | - """API key auth returns Authorization header with raw key.""" |
140 | | - auth = ClientAuthentication(type="api-key", api_key="my-api-key") |
141 | | - result = build_auth_headers(auth) |
142 | | - assert result == {"Authorization": "my-api-key"} |
143 | | - |
144 | | - def test_bearer_auth_missing_token_raises_pydantic_error(self): |
145 | | - """Bearer auth without token raises Pydantic ValidationError at model creation.""" |
146 | | - # Pydantic validates at model creation time, not at build_auth_headers |
147 | | - from pydantic import ValidationError |
148 | | - |
149 | | - with pytest.raises(ValidationError, match="requires 'token' field"): |
150 | | - ClientAuthentication(type="bearer") |
151 | | - |
152 | | - def test_basic_auth_missing_username_raises_pydantic_error(self): |
153 | | - """Basic auth without username raises Pydantic ValidationError at model creation.""" |
154 | | - from pydantic import ValidationError |
155 | | - |
156 | | - with pytest.raises(ValidationError, match="requires 'username' and 'password'"): |
157 | | - ClientAuthentication(type="basic", password="pass") |
158 | | - |
159 | | - def test_basic_auth_missing_password_raises_pydantic_error(self): |
160 | | - """Basic auth without password raises Pydantic ValidationError at model creation.""" |
161 | | - from pydantic import ValidationError |
162 | | - |
163 | | - with pytest.raises(ValidationError, match="requires 'username' and 'password'"): |
164 | | - ClientAuthentication(type="basic", username="user") |
165 | | - |
166 | | - def test_api_key_auth_missing_key_raises_pydantic_error(self): |
167 | | - """API key auth without key raises Pydantic ValidationError at model creation.""" |
168 | | - from pydantic import ValidationError |
169 | | - |
170 | | - with pytest.raises(ValidationError, match="requires 'api_key' field"): |
171 | | - ClientAuthentication(type="api-key") |
172 | | - |
173 | | - def test_oauth2_auth_not_supported(self): |
174 | | - """OAuth2 auth raises not supported error.""" |
175 | | - auth = ClientAuthentication(type="oauth2") |
176 | | - with pytest.raises(MCPAuthenticationError, match="not yet supported"): |
177 | | - build_auth_headers(auth) |
178 | | - |
179 | | - def test_jwt_auth_not_supported(self): |
180 | | - """JWT auth raises not supported error.""" |
181 | | - auth = ClientAuthentication(type="jwt") |
182 | | - with pytest.raises(MCPAuthenticationError, match="not yet supported"): |
183 | | - build_auth_headers(auth) |
184 | | - |
185 | | - def test_unknown_auth_type_raises_error(self): |
186 | | - """Unknown auth type raises MCPAuthenticationError.""" |
187 | | - auth = ClientAuthentication(type="unknown") |
188 | | - with pytest.raises( |
189 | | - MCPAuthenticationError, match="Unsupported authentication type" |
190 | | - ): |
191 | | - build_auth_headers(auth) |
192 | | - |
193 | | - def test_auth_type_is_case_insensitive(self): |
194 | | - """Auth type matching is case-insensitive.""" |
195 | | - auth = ClientAuthentication(type="BEARER", token="my-token") |
196 | | - result = build_auth_headers(auth) |
197 | | - assert result == {"Authorization": "Bearer my-token"} |
198 | | - |
199 | | - |
200 | 116 | class TestBuildHttpxAuth: |
201 | 117 | """Tests for build_httpx_auth function.""" |
202 | 118 |
|
@@ -406,7 +322,7 @@ def test_build_connection_config_http_with_auth(self): |
406 | 322 | config = client._build_connection_config() |
407 | 323 |
|
408 | 324 | assert "auth" in config |
409 | | - assert isinstance(config["auth"], BearerAuth) |
| 325 | + assert isinstance(config.get("auth"), BearerAuth) |
410 | 326 |
|
411 | 327 | # ---- Stdio transport tests ---- |
412 | 328 |
|
@@ -489,7 +405,7 @@ def test_build_connection_config_stdio_no_args_defaults_to_empty_list(self): |
489 | 405 | ) |
490 | 406 | config = client._build_connection_config() |
491 | 407 |
|
492 | | - assert config["args"] == [] |
| 408 | + assert config.get("args") == [] |
493 | 409 |
|
494 | 410 | # ---- Shared async tests ---- |
495 | 411 |
|
|
0 commit comments