Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always convert azureservicebus namespace to fully qualified #1892

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions kombu/transport/azureservicebus.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,8 @@ def _try_parse_connection_string(self) -> None:
if ":" in self._credential:
self._policy, self._sas_key = self._credential.split(':', 1)

# Convert
endpoint = 'sb://' + self._namespace
if not endpoint.endswith('.net'):
endpoint += '.servicebus.windows.net'

conn_dict = {
'Endpoint': endpoint,
'Endpoint': 'sb://' + self._namespace,
'SharedAccessKeyName': self._policy,
'SharedAccessKey': self._sas_key,
}
Expand Down Expand Up @@ -451,6 +446,9 @@ def parse_uri(uri: str) -> tuple[str, str | DefaultAzureCredential |
# > 'rootpolicy:some/key', 'somenamespace'
credential, namespace = uri.rsplit('@', 1)

if not namespace.endswith('.net'):
namespace += '.servicebus.windows.net'

if "DefaultAzureCredential".lower() == credential.lower():
if DefaultAzureCredential is None:
raise ImportError('Azure Service Bus transport with a '
Expand Down
12 changes: 9 additions & 3 deletions t/unit/transport/test_azureservicebus.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ def get_queue_runtime_properties(self, queue_name):

URL_NOCREDS = 'azureservicebus://'
URL_CREDS_SAS = 'azureservicebus://policyname:ke/y@hostname'
URL_CREDS_SAS_FQ = 'azureservicebus://policyname:ke/[email protected]' # noqa
URL_CREDS_DA = 'azureservicebus://DefaultAzureCredential@hostname'
URL_CREDS_DA_FQ = 'azureservicebus://[email protected]' # noqa
URL_CREDS_MI = 'azureservicebus://ManagedIdentityCredential@hostname'
URL_CREDS_MI_FQ = 'azureservicebus://[email protected]' # noqa


def test_queue_service_nocredentials():
Expand Down Expand Up @@ -133,6 +136,7 @@ def test_queue_service_sas():
# Ensure that queue_service is cached
assert channel.queue_service == 'test'
assert m.from_connection_string.call_count == 1
assert channel._namespace == 'hostname.servicebus.windows.net'


def test_queue_service_da():
Expand All @@ -142,6 +146,7 @@ def test_queue_service_da():
# Check the DefaultAzureCredential has been parsed from the url correctly
# and the credential is a ManagedIdentityCredential
assert isinstance(channel._credential, DefaultAzureCredential)
assert channel._namespace == 'hostname.servicebus.windows.net'


def test_queue_service_mi():
Expand All @@ -151,6 +156,7 @@ def test_queue_service_mi():
# Check the ManagedIdentityCredential has been parsed from the url
# correctly and the credential is a ManagedIdentityCredential
assert isinstance(channel._credential, ManagedIdentityCredential)
assert channel._namespace == 'hostname.servicebus.windows.net'


def test_conninfo():
Expand Down Expand Up @@ -450,14 +456,14 @@ def test_basic_ack_reject_message_when_raises_exception(

def test_returning_sas():
conn = Connection(URL_CREDS_SAS, transport=azureservicebus.Transport)
assert conn.as_uri(True) == URL_CREDS_SAS
assert conn.as_uri(True) == URL_CREDS_SAS_FQ


def test_returning_da():
conn = Connection(URL_CREDS_DA, transport=azureservicebus.Transport)
assert conn.as_uri(True) == URL_CREDS_DA
assert conn.as_uri(True) == URL_CREDS_DA_FQ


def test_returning_mi():
conn = Connection(URL_CREDS_MI, transport=azureservicebus.Transport)
assert conn.as_uri(True) == URL_CREDS_MI
assert conn.as_uri(True) == URL_CREDS_MI_FQ