Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ async def get_token(self, *args):


class AsyncContainerRegistryTestClass(ContainerRegistryTestClass):
def __init__(self, method_name):
super(AsyncContainerRegistryTestClass, self).__init__(method_name)

def get_credential(self, authority=None, **kwargs):
if self.is_live:
if authority != AzureAuthorityHosts.AZURE_PUBLIC_CLOUD:
Expand Down
23 changes: 23 additions & 0 deletions sdk/containerregistry/azure-containerregistry/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,31 @@
# license information.
# --------------------------------------------------------------------------

import os

import pytest
from devtools_testutils import add_general_regex_sanitizer, add_body_key_sanitizer, add_uri_regex_sanitizer, test_proxy

# Fixture
from testcase import load_registry


def pytest_configure(config):
config.addinivalue_line("usefixtures", "load_registry")

@pytest.fixture(scope="session", autouse=True)
def add_sanitizers(test_proxy):
# sanitizes access and refresh tokens that are present in single-string request or response bodies
# we expect tokens to either be at the end of this body string, or followed by "\u0026" and more content
add_general_regex_sanitizer(value="access_token", regex="(?<=access_token=).*?(?=(?:\\u0026|$))")
add_general_regex_sanitizer(value="refresh_token", regex="(?<=refresh_token=).*?(?=(?:\\u0026|$))")
# sanitizes access and refresh tokens in JSON-formatted request or response bodies
add_body_key_sanitizer(json_path="$..access_token", value="access_token")
add_body_key_sanitizer(json_path="$..refresh_token", value="refresh_token")

add_uri_regex_sanitizer(regex="sha256%3A(.*)", value="sha256_encoded_stream")

client_id = os.environ.get("CONTAINERREGISTRY_CLIENT_ID", "client-id")
add_general_regex_sanitizer(regex=client_id, value="client-id")
client_secret = os.environ.get("CONTAINERREGISTRY_CLIENT_SECRET", "client-secret")
add_general_regex_sanitizer(regex=client_secret, value="client-secret")
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
{
"Entries": [
{
"RequestUri": "https://fake_url.azurecr.io/acr/v1/library%2Fhello-world/_tags/latest?api-version=2021-07-01",
"RequestMethod": "GET",
"RequestHeaders": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"User-Agent": "azsdk-python-azure-containerregistry/1.1.0b2 Python/3.9.2 (Windows-10-10.0.22000-SP0)"
},
"RequestBody": null,
"StatusCode": 401,
"ResponseHeaders": {
"Access-Control-Expose-Headers": [
"Docker-Content-Digest",
"WWW-Authenticate",
"Link",
"X-Ms-Correlation-Request-Id"
],
"Connection": "keep-alive",
"Content-Length": "222",
"Content-Type": "application/json; charset=utf-8",
"Date": "Thu, 28 Jul 2022 08:47:43 GMT",
"Docker-Distribution-Api-Version": "registry/2.0",
"Server": "openresty",
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains",
"max-age=31536000; includeSubDomains"
],
"WWW-Authenticate": "Bearer realm=\u0022https://fake_url.azurecr.io/oauth2/token\u0022,service=\u0022yallacrtestsanon.azurecr.io\u0022,scope=\u0022repository:library/hello-world:metadata_read\u0022",
"X-Content-Type-Options": "nosniff",
"X-Ms-Correlation-Request-Id": "ce555cf7-129c-4176-9547-8ae31fda2e5a"
},
"ResponseBody": {
"errors": [
{
"code": "UNAUTHORIZED",
"message": "authentication required, visit https://aka.ms/acr/authorization for more information.",
"detail": [
{
"Type": "repository",
"Name": "library/hello-world",
"Action": "metadata_read"
}
]
}
]
}
},
{
"RequestUri": "https://fake_url.azurecr.io/oauth2/token?api-version=2021-07-01",
"RequestMethod": "POST",
"RequestHeaders": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Content-Length": "112",
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "azsdk-python-azure-containerregistry/1.1.0b2 Python/3.9.2 (Windows-10-10.0.22000-SP0)"
},
"RequestBody": "service=yallacrtestsanon.azurecr.io\u0026scope=repository%3Alibrary%2Fhello-world%3Ametadata_read\u0026grant_type=password",
"StatusCode": 200,
"ResponseHeaders": {
"Connection": "keep-alive",
"Content-Type": "application/json; charset=utf-8",
"Date": "Thu, 28 Jul 2022 08:47:43 GMT",
"Server": "openresty",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"Transfer-Encoding": "chunked",
"X-Ms-Correlation-Request-Id": "2dce36e1-4737-49af-9d9a-6cb94f7d896d",
"x-ms-ratelimit-remaining-calls-per-second": "166.65"
},
"ResponseBody": {
"access_token": "access_token"
}
},
{
"RequestUri": "https://fake_url.azurecr.io/acr/v1/library%2Fhello-world/_tags/latest?api-version=2021-07-01",
"RequestMethod": "GET",
"RequestHeaders": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"User-Agent": "azsdk-python-azure-containerregistry/1.1.0b2 Python/3.9.2 (Windows-10-10.0.22000-SP0)"
},
"RequestBody": null,
"StatusCode": 200,
"ResponseHeaders": {
"Access-Control-Expose-Headers": [
"Docker-Content-Digest",
"WWW-Authenticate",
"Link",
"X-Ms-Correlation-Request-Id"
],
"Connection": "keep-alive",
"Content-Length": "396",
"Content-Type": "application/json; charset=utf-8",
"Date": "Thu, 28 Jul 2022 08:47:43 GMT",
"Docker-Distribution-Api-Version": "registry/2.0",
"Server": "openresty",
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains",
"max-age=31536000; includeSubDomains"
],
"X-Content-Type-Options": "nosniff",
"X-Ms-Correlation-Request-Id": "4693f1e0-31c5-47ab-8625-f3e26af03f05"
},
"ResponseBody": {
"registry": "yallacrtestsanon.azurecr.io",
"imageName": "library/hello-world",
"tag": {
"name": "latest",
"digest": "sha256:53f1bbee2f52c39e41682ee1d388285290c5c8a76cc92b42687eecf38e0af3f0",
"createdTime": "2022-07-28T07:05:13.3334843Z",
"lastUpdateTime": "2022-07-28T07:05:13.3334843Z",
"signed": false,
"changeableAttributes": {
"deleteEnabled": true,
"writeEnabled": true,
"readEnabled": true,
"listEnabled": true
}
}
}
},
{
"RequestUri": "https://fake_url.azurecr.io/v2/library%2Fhello-world/manifests/sha256_encoded_stream",
"RequestMethod": "DELETE",
"RequestHeaders": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Content-Length": "0",
"User-Agent": "azsdk-python-azure-containerregistry/1.1.0b2 Python/3.9.2 (Windows-10-10.0.22000-SP0)"
},
"RequestBody": null,
"StatusCode": 401,
"ResponseHeaders": {
"Access-Control-Expose-Headers": [
"Docker-Content-Digest",
"WWW-Authenticate",
"Link",
"X-Ms-Correlation-Request-Id"
],
"Connection": "keep-alive",
"Content-Length": "215",
"Content-Type": "application/json; charset=utf-8",
"Date": "Thu, 28 Jul 2022 08:47:43 GMT",
"Docker-Distribution-Api-Version": "registry/2.0",
"Server": "openresty",
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains",
"max-age=31536000; includeSubDomains"
],
"WWW-Authenticate": "Bearer realm=\u0022https://fake_url.azurecr.io/oauth2/token\u0022,service=\u0022yallacrtestsanon.azurecr.io\u0022,scope=\u0022repository:library/hello-world:delete\u0022",
"X-Content-Type-Options": "nosniff",
"X-Ms-Correlation-Request-Id": "3a82605d-ef85-4f86-9bf1-65f42164fdfc"
},
"ResponseBody": {
"errors": [
{
"code": "UNAUTHORIZED",
"message": "authentication required, visit https://aka.ms/acr/authorization for more information.",
"detail": [
{
"Type": "repository",
"Name": "library/hello-world",
"Action": "delete"
}
]
}
]
}
},
{
"RequestUri": "https://fake_url.azurecr.io/oauth2/token?api-version=2021-07-01",
"RequestMethod": "POST",
"RequestHeaders": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Content-Length": "105",
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "azsdk-python-azure-containerregistry/1.1.0b2 Python/3.9.2 (Windows-10-10.0.22000-SP0)"
},
"RequestBody": "service=yallacrtestsanon.azurecr.io\u0026scope=repository%3Alibrary%2Fhello-world%3Adelete\u0026grant_type=password",
"StatusCode": 200,
"ResponseHeaders": {
"Connection": "keep-alive",
"Content-Type": "application/json; charset=utf-8",
"Date": "Thu, 28 Jul 2022 08:47:43 GMT",
"Server": "openresty",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"Transfer-Encoding": "chunked",
"X-Ms-Correlation-Request-Id": "e6dff6ba-6290-45f2-9f5f-368e6e8f3319",
"x-ms-ratelimit-remaining-calls-per-second": "166.633333"
},
"ResponseBody": {
"access_token": "access_token"
}
},
{
"RequestUri": "https://fake_url.azurecr.io/v2/library%2Fhello-world/manifests/sha256_encoded_stream",
"RequestMethod": "DELETE",
"RequestHeaders": {
"Accept": "application/json",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
"Content-Length": "0",
"User-Agent": "azsdk-python-azure-containerregistry/1.1.0b2 Python/3.9.2 (Windows-10-10.0.22000-SP0)"
},
"RequestBody": null,
"StatusCode": 401,
"ResponseHeaders": {
"Access-Control-Expose-Headers": [
"Docker-Content-Digest",
"WWW-Authenticate",
"Link",
"X-Ms-Correlation-Request-Id"
],
"Connection": "keep-alive",
"Content-Length": "215",
"Content-Type": "application/json; charset=utf-8",
"Date": "Thu, 28 Jul 2022 08:47:43 GMT",
"Docker-Distribution-Api-Version": "registry/2.0",
"Server": "openresty",
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains",
"max-age=31536000; includeSubDomains"
],
"WWW-Authenticate": "Bearer realm=\u0022https://fake_url.azurecr.io/oauth2/token\u0022,service=\u0022yallacrtestsanon.azurecr.io\u0022,scope=\u0022repository:library/hello-world:delete\u0022,error=\u0022insufficient_scope\u0022",
"X-Content-Type-Options": "nosniff",
"X-Ms-Correlation-Request-Id": "b12b357f-9b6e-4d76-bf00-5bfb61d88e31"
},
"ResponseBody": {
"errors": [
{
"code": "UNAUTHORIZED",
"message": "authentication required, visit https://aka.ms/acr/authorization for more information.",
"detail": [
{
"Type": "repository",
"Name": "library/hello-world",
"Action": "delete"
}
]
}
]
}
}
],
"Variables": {}
}
Loading