Skip to content

Commit

Permalink
Migrate ACR tests (#36238)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyan99 authored Jun 26, 2024
1 parent 55d4d55 commit 48590d5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from azure.identity.aio import DefaultAzureCredential, ClientSecretCredential
from azure.identity import AzureAuthorityHosts

from testcase import ContainerRegistryTestClass, get_audience, get_authority
from testcase import ContainerRegistryTestClass, get_audience, get_authority, get_credential

logger = logging.getLogger()

Expand All @@ -32,14 +32,7 @@ async def get_token(self, *args, **kwargs):
class AsyncContainerRegistryTestClass(ContainerRegistryTestClass):
def get_credential(self, authority=None, **kwargs):
if self.is_live:
if authority != AzureAuthorityHosts.AZURE_PUBLIC_CLOUD:
return ClientSecretCredential(
tenant_id=os.environ["CONTAINERREGISTRY_TENANT_ID"],
client_id=os.environ["CONTAINERREGISTRY_CLIENT_ID"],
client_secret=os.environ["CONTAINERREGISTRY_CLIENT_SECRET"],
authority=authority,
)
return DefaultAzureCredential(**kwargs)
return get_credential(is_async=True, authority=authority, **kwargs)
return AsyncFakeTokenCredential()

def create_registry_client(self, endpoint, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def test_expiration_time_parsing(self, containerregistry_endpoint):
def construct_container_registry_client(self, **kwargs):
containerregistry_endpoint = kwargs.pop("containerregistry_endpoint")
authority = get_authority(containerregistry_endpoint)
credential = self.get_credential(authority)
credential = self.get_credential(authority=authority)

with ContainerRegistryClient(
endpoint=containerregistry_endpoint, credential=credential, audience="https://microsoft.com"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ async def test_expiration_time_parsing(self, containerregistry_endpoint):
async def test_construct_container_registry_client(self, **kwargs):
containerregistry_endpoint = kwargs.pop("containerregistry_endpoint")
authority = get_authority(containerregistry_endpoint)
credential = self.get_credential(authority)
credential = self.get_credential(authority=authority)

async with ContainerRegistryClient(
endpoint=containerregistry_endpoint, credential=credential, audience="https://microsoft.com"
Expand Down
15 changes: 3 additions & 12 deletions sdk/containerregistry/azure-containerregistry/tests/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from azure.containerregistry._helpers import _is_tag
from azure.identity import AzureAuthorityHosts, ClientSecretCredential

from devtools_testutils import AzureRecordedTestCase, FakeTokenCredential
from devtools_testutils import AzureRecordedTestCase, FakeTokenCredential, get_credential

logger = logging.getLogger()

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

def get_credential(self, authority=None, **kwargs):
if self.is_live:
return get_credential(authority)
return get_credential(authority=authority, **kwargs)
return FakeTokenCredential()

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


def get_credential(authority: str, **kwargs):
return ClientSecretCredential(
tenant_id=os.environ.get("CONTAINERREGISTRY_TENANT_ID"),
client_id=os.environ.get("CONTAINERREGISTRY_CLIENT_ID"),
client_secret=os.environ.get("CONTAINERREGISTRY_CLIENT_SECRET"),
authority=authority,
)


def import_image(endpoint, repository, tags):
authority = get_authority(endpoint)
logger.warning(f"Import image authority: {authority}")
credential = get_credential(authority)
credential = get_credential(authority=authority)

with ContainerRegistryClient(endpoint, credential) as client:
# Upload a layer
Expand Down
4 changes: 4 additions & 0 deletions sdk/containerregistry/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ extends:
ServiceDirectory: containerregistry
SupportedClouds: 'Public,UsGov,China'
TestTimeoutInMinutes: 240
UseFederatedAuth: true
CloudConfig:
Public:
SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources)
ServiceConnection: azure-sdk-tests
SubscriptionConfigurationFilePaths:
- eng/common/TestResources/sub-config/AzurePublicMsft.json
UsGov:
SubscriptionConfiguration: $(sub-config-gov-test-resources)
China:
Expand Down

0 comments on commit 48590d5

Please sign in to comment.