|
3 | 3 | # Licensed under the MIT License.
|
4 | 4 | # ------------------------------------
|
5 | 5 | import os
|
| 6 | +import sys |
6 | 7 |
|
7 | 8 | from azure.core.credentials import AccessToken, AccessTokenInfo
|
8 | 9 | from azure.identity import (
|
@@ -432,3 +433,22 @@ def test_validate_cloud_shell_credential_in_dac():
|
432 | 433 | DefaultAzureCredential(identity_config={"client_id": "foo"})
|
433 | 434 | DefaultAzureCredential(identity_config={"object_id": "foo"})
|
434 | 435 | DefaultAzureCredential(identity_config={"resource_id": "foo"})
|
| 436 | + |
| 437 | + |
| 438 | +@pytest.mark.skipif(not sys.platform.startswith("win"), reason="tests Windows-specific behavior") |
| 439 | +def test_broker_credential(): |
| 440 | + """Test that DefaultAzureCredential uses the broker credential when available""" |
| 441 | + with patch("azure.identity.broker.InteractiveBrowserBrokerCredential") as mock_credential: |
| 442 | + DefaultAzureCredential() |
| 443 | + assert mock_credential.call_count == 1, "InteractiveBrowserBrokerCredential should be instantiated once" |
| 444 | + |
| 445 | + |
| 446 | +@pytest.mark.skipif(not sys.platform.startswith("win"), reason="tests Windows-specific behavior") |
| 447 | +def test_broker_credential_requirements_not_installed(): |
| 448 | + """Test that DefaultAzureCredential does not use the broker credential when requirements are not installed""" |
| 449 | + |
| 450 | + with patch.dict("sys.modules", {"azure.identity.broker": None}): |
| 451 | + with patch("azure.identity.broker.InteractiveBrowserBrokerCredential") as mock_credential: |
| 452 | + DefaultAzureCredential() |
| 453 | + |
| 454 | + assert mock_credential.call_count == 0, "InteractiveBrowserBrokerCredential should not be instantiated" |
0 commit comments