Skip to content

Commit 48590d5

Browse files
authored
Migrate ACR tests (#36238)
1 parent 55d4d55 commit 48590d5

File tree

5 files changed

+11
-23
lines changed

5 files changed

+11
-23
lines changed

sdk/containerregistry/azure-containerregistry/tests/asynctestcase.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from azure.identity.aio import DefaultAzureCredential, ClientSecretCredential
1313
from azure.identity import AzureAuthorityHosts
1414

15-
from testcase import ContainerRegistryTestClass, get_audience, get_authority
15+
from testcase import ContainerRegistryTestClass, get_audience, get_authority, get_credential
1616

1717
logger = logging.getLogger()
1818

@@ -32,14 +32,7 @@ async def get_token(self, *args, **kwargs):
3232
class AsyncContainerRegistryTestClass(ContainerRegistryTestClass):
3333
def get_credential(self, authority=None, **kwargs):
3434
if self.is_live:
35-
if authority != AzureAuthorityHosts.AZURE_PUBLIC_CLOUD:
36-
return ClientSecretCredential(
37-
tenant_id=os.environ["CONTAINERREGISTRY_TENANT_ID"],
38-
client_id=os.environ["CONTAINERREGISTRY_CLIENT_ID"],
39-
client_secret=os.environ["CONTAINERREGISTRY_CLIENT_SECRET"],
40-
authority=authority,
41-
)
42-
return DefaultAzureCredential(**kwargs)
35+
return get_credential(is_async=True, authority=authority, **kwargs)
4336
return AsyncFakeTokenCredential()
4437

4538
def create_registry_client(self, endpoint, **kwargs):

sdk/containerregistry/azure-containerregistry/tests/test_container_registry_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ def test_expiration_time_parsing(self, containerregistry_endpoint):
448448
def construct_container_registry_client(self, **kwargs):
449449
containerregistry_endpoint = kwargs.pop("containerregistry_endpoint")
450450
authority = get_authority(containerregistry_endpoint)
451-
credential = self.get_credential(authority)
451+
credential = self.get_credential(authority=authority)
452452

453453
with ContainerRegistryClient(
454454
endpoint=containerregistry_endpoint, credential=credential, audience="https://microsoft.com"

sdk/containerregistry/azure-containerregistry/tests/test_container_registry_client_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ async def test_expiration_time_parsing(self, containerregistry_endpoint):
452452
async def test_construct_container_registry_client(self, **kwargs):
453453
containerregistry_endpoint = kwargs.pop("containerregistry_endpoint")
454454
authority = get_authority(containerregistry_endpoint)
455-
credential = self.get_credential(authority)
455+
credential = self.get_credential(authority=authority)
456456

457457
async with ContainerRegistryClient(
458458
endpoint=containerregistry_endpoint, credential=credential, audience="https://microsoft.com"

sdk/containerregistry/azure-containerregistry/tests/testcase.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from azure.containerregistry._helpers import _is_tag
1313
from azure.identity import AzureAuthorityHosts, ClientSecretCredential
1414

15-
from devtools_testutils import AzureRecordedTestCase, FakeTokenCredential
15+
from devtools_testutils import AzureRecordedTestCase, FakeTokenCredential, get_credential
1616

1717
logger = logging.getLogger()
1818

@@ -27,7 +27,7 @@ def import_image(self, endpoint, repository, tags):
2727

2828
def get_credential(self, authority=None, **kwargs):
2929
if self.is_live:
30-
return get_credential(authority)
30+
return get_credential(authority=authority, **kwargs)
3131
return FakeTokenCredential()
3232

3333
def create_registry_client(self, endpoint, **kwargs):
@@ -115,19 +115,10 @@ def get_audience(authority: str) -> str:
115115
return "https://management.usgovcloudapi.net"
116116

117117

118-
def get_credential(authority: str, **kwargs):
119-
return ClientSecretCredential(
120-
tenant_id=os.environ.get("CONTAINERREGISTRY_TENANT_ID"),
121-
client_id=os.environ.get("CONTAINERREGISTRY_CLIENT_ID"),
122-
client_secret=os.environ.get("CONTAINERREGISTRY_CLIENT_SECRET"),
123-
authority=authority,
124-
)
125-
126-
127118
def import_image(endpoint, repository, tags):
128119
authority = get_authority(endpoint)
129120
logger.warning(f"Import image authority: {authority}")
130-
credential = get_credential(authority)
121+
credential = get_credential(authority=authority)
131122

132123
with ContainerRegistryClient(endpoint, credential) as client:
133124
# Upload a layer

sdk/containerregistry/tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ extends:
77
ServiceDirectory: containerregistry
88
SupportedClouds: 'Public,UsGov,China'
99
TestTimeoutInMinutes: 240
10+
UseFederatedAuth: true
1011
CloudConfig:
1112
Public:
1213
SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources)
14+
ServiceConnection: azure-sdk-tests
15+
SubscriptionConfigurationFilePaths:
16+
- eng/common/TestResources/sub-config/AzurePublicMsft.json
1317
UsGov:
1418
SubscriptionConfiguration: $(sub-config-gov-test-resources)
1519
China:

0 commit comments

Comments
 (0)