Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/azure-cli/azure/cli/command_modules/acr/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ def acr_login(cmd,
RegionalEndpoints = cmd.get_models('RegionalEndpoints')
if registry.regional_endpoints == RegionalEndpoints.ENABLED and registry.regional_endpoint_host_names:
# Build the expected regional endpoint prefix: registryname.region.geo.
regional_endpoint_prefix = f"{registry_name}.{endpoint}.geo.".lower()
# Use login_server hostname (before the first dot) to account for the DNL suffix if set.
login_server_name = registry.login_server.split('.')[0]
regional_endpoint_prefix = f"{login_server_name}.{endpoint}.geo.".lower()
Comment thread
lizMSFT marked this conversation as resolved.
matching_endpoint = next(
(url for url in registry.regional_endpoint_host_names
if url.lower().strip().startswith(regional_endpoint_prefix)), None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,55 @@ def test_non_regional_endpoint_uris_unchanged(self):
for uri in test_cases:
result = acr_import._regional_endpoint_uri_to_login_server(uri, login_server_suffix)
self.assertEqual(result, uri)

@staticmethod
def _match_regional_endpoint(login_server, endpoint, regional_endpoint_host_names):
"""Replicate the matching logic from acr_login for unit testing."""
login_server_name = login_server.split('.')[0]
regional_endpoint_prefix = f"{login_server_name}.{endpoint}.geo.".lower()
return next(
(url for url in regional_endpoint_host_names
if url.lower().strip().startswith(regional_endpoint_prefix)), None)

def test_match_standard_registry(self):
"""Registry without DNL — login_server starts with registry name."""
login_server = 'myregistry.azurecr.io'
hosts = [
'myregistry.eastus.geo.azurecr.io',
'myregistry.westus.geo.azurecr.io',
]
self.assertEqual(
self._match_regional_endpoint(login_server, 'eastus', hosts),
'myregistry.eastus.geo.azurecr.io')
self.assertEqual(
self._match_regional_endpoint(login_server, 'westus', hosts),
'myregistry.westus.geo.azurecr.io')

def test_match_dnl_registry(self):
"""Registry with DNL suffix — login_server has a hash appended."""
login_server = 'myregistry-d7ezgzevdwfvc8ht.azurecr.io'
hosts = [
'myregistry-d7ezgzevdwfvc8ht.eastus.geo.azurecr.io',
'myregistry-d7ezgzevdwfvc8ht.westus.geo.azurecr.io',
]
self.assertEqual(
self._match_regional_endpoint(login_server, 'eastus', hosts),
'myregistry-d7ezgzevdwfvc8ht.eastus.geo.azurecr.io')
self.assertEqual(
self._match_regional_endpoint(login_server, 'westus', hosts),
'myregistry-d7ezgzevdwfvc8ht.westus.geo.azurecr.io')

def test_no_match_returns_none(self):
"""Endpoint region not in the host list returns None."""
login_server = 'myregistry.azurecr.io'
hosts = ['myregistry.eastus.geo.azurecr.io']
self.assertIsNone(
self._match_regional_endpoint(login_server, 'westus', hosts))

def test_match_case_insensitive(self):
"""Matching is case-insensitive for both endpoint arg and host names."""
login_server = 'MyRegistry.azurecr.io'
hosts = ['MyRegistry.EastUS.geo.azurecr.io']
self.assertEqual(
self._match_regional_endpoint(login_server, 'eastus', hosts),
'MyRegistry.EastUS.geo.azurecr.io')
Loading