diff options
author | Jason Barnett <J@sonBarnett.com> | 2022-12-26 13:51:47 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-27 00:51:47 +0600 |
commit | 4fac6bc84c1374e5cde8cfd2125f214d1830b5f4 (patch) | |
tree | 4c5a447c554d24fbca6df31e11c1f075161b5034 /t | |
parent | 77876967374acb6a141b9ae3d6a8559fd9283e96 (diff) | |
download | kombu-4fac6bc84c1374e5cde8cfd2125f214d1830b5f4.tar.gz |
add managed identity support to azure storage queue (#1631)
* add managed identity support to azure storage queue
* flake8 fixes
Diffstat (limited to 't')
-rw-r--r-- | t/unit/transport/test_azurestoragequeues.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/t/unit/transport/test_azurestoragequeues.py b/t/unit/transport/test_azurestoragequeues.py index 44fa859b..0c9ef32a 100644 --- a/t/unit/transport/test_azurestoragequeues.py +++ b/t/unit/transport/test_azurestoragequeues.py @@ -3,6 +3,7 @@ from __future__ import annotations from unittest.mock import patch import pytest +from azure.identity import DefaultAzureCredential, ManagedIdentityCredential from kombu import Connection @@ -13,6 +14,8 @@ URL_NOCREDS = 'azurestoragequeues://' URL_CREDS = 'azurestoragequeues://sas/key%@https://STORAGE_ACCOUNT_NAME.queue.core.windows.net/' # noqa AZURITE_CREDS = 'azurestoragequeues://Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==@http://localhost:10001/devstoreaccount1' # noqa AZURITE_CREDS_DOCKER_COMPOSE = 'azurestoragequeues://Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==@http://azurite:10001/devstoreaccount1' # noqa +DEFAULT_AZURE_URL_CREDS = 'azurestoragequeues://DefaultAzureCredential@https://STORAGE_ACCOUNT_NAME.queue.core.windows.net/' # noqa +MANAGED_IDENTITY_URL_CREDS = 'azurestoragequeues://ManagedIdentityCredential@https://STORAGE_ACCOUNT_NAME.queue.core.windows.net/' # noqa def test_queue_service_nocredentials(): @@ -52,3 +55,31 @@ def test_queue_service_works_for_azurite(creds, hostname): 'account_key': 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==' # noqa } assert channel._url == f'http://{hostname}:10001/devstoreaccount1' # noqa + + +def test_queue_service_works_for_default_azure_credentials(): + conn = Connection( + DEFAULT_AZURE_URL_CREDS, transport=azurestoragequeues.Transport + ) + with patch("kombu.transport.azurestoragequeues.QueueServiceClient"): + channel = conn.channel() + + assert isinstance(channel._credential, DefaultAzureCredential) + assert ( + channel._url + == "https://STORAGE_ACCOUNT_NAME.queue.core.windows.net/" + ) + + +def test_queue_service_works_for_managed_identity_credentials(): + conn = Connection( + MANAGED_IDENTITY_URL_CREDS, transport=azurestoragequeues.Transport + ) + with patch("kombu.transport.azurestoragequeues.QueueServiceClient"): + channel = conn.channel() + + assert isinstance(channel._credential, ManagedIdentityCredential) + assert ( + channel._url + == "https://STORAGE_ACCOUNT_NAME.queue.core.windows.net/" + ) |