File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments