BUG: Raise ClientAuthenticationError in default get credential (#659)

Device Login was skipped because exception not raised
This commit is contained in:
Kenza Bouzid 2022-11-14 14:54:44 +00:00 коммит произвёл GitHub
Родитель 70885901e8
Коммит f97d368870
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 6 добавлений и 9 удалений

Просмотреть файл

@ -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()