зеркало из https://github.com/microsoft/hi-ml.git
BUG: Raise ClientAuthenticationError in default get credential (#659)
Device Login was skipped because exception not raised
This commit is contained in:
Родитель
70885901e8
Коммит
f97d368870
|
@ -2164,17 +2164,13 @@ def _get_legitimate_device_code_credential() -> Optional[TokenCredential]:
|
|||
|
||||
def _get_legitimate_default_credential() -> Optional[TokenCredential]:
|
||||
"""
|
||||
Create a DefaultAzure credential for interacting with Azure resources. If the credential can't be
|
||||
validated, return None.
|
||||
Create a DefaultAzure credential for interacting with Azure resources and validates it.
|
||||
|
||||
:return: A valid Azure credential.
|
||||
"""
|
||||
cred = DefaultAzureCredential(timeout=60)
|
||||
try:
|
||||
_validate_credential(cred)
|
||||
return cred
|
||||
except ClientAuthenticationError:
|
||||
return None
|
||||
_validate_credential(cred)
|
||||
return cred
|
||||
|
||||
|
||||
def _get_legitimate_interactive_browser_credential() -> Optional[TokenCredential]:
|
||||
|
|
|
@ -2477,8 +2477,9 @@ def test_get_legitimate_default_credential() -> None:
|
|||
return DefaultAzureCredential(timeout=1)
|
||||
|
||||
with patch("health_azure.utils.DefaultAzureCredential", new=_mock_credential_fast_timeout):
|
||||
cred = util._get_legitimate_default_credential()
|
||||
assert cred is None
|
||||
exception_message = r"DefaultAzureCredential failed to retrieve a token from the included credentials."
|
||||
with pytest.raises(ClientAuthenticationError, match=exception_message):
|
||||
cred = util._get_legitimate_default_credential()
|
||||
|
||||
with patch("health_azure.utils._validate_credential"):
|
||||
cred = util._get_legitimate_default_credential()
|
||||
|
|
Загрузка…
Ссылка в новой задаче