Skip to content

Commit e79cb8b

Browse files
committed
add test
1 parent 2e064ef commit e79cb8b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/catalog/test_rest_auth.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,22 @@ def test_entra_auth_manager_import_error() -> None:
230230
with patch.dict("sys.modules", {"azure.identity": None}):
231231
with pytest.raises(ImportError, match="Azure Identity library not found"):
232232
EntraAuthManager()
233+
234+
235+
@patch("azure.identity.DefaultAzureCredential")
236+
def test_entra_auth_manager_token_failure(mock_default_cred: MagicMock, rest_mock: Mocker) -> None:
237+
"""Test EntraAuthManager raises exception when token acquisition fails."""
238+
mock_credential_instance = MagicMock()
239+
mock_credential_instance.get_token.side_effect = Exception("Failed to acquire token")
240+
mock_default_cred.return_value = mock_credential_instance
241+
242+
auth_manager = EntraAuthManager()
243+
session = requests.Session()
244+
session.auth = AuthManagerAdapter(auth_manager)
245+
246+
with pytest.raises(Exception, match="Failed to acquire token"):
247+
session.get(TEST_URI)
248+
249+
# Verify no requests were made with a blank/missing auth header
250+
history = rest_mock.request_history
251+
assert len(history) == 0

0 commit comments

Comments
 (0)