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

[Storage] Modified StorageRetryPolicy to skip AzureSigningError from bad storage account key #36431

Merged
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-blob/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/storage/azure-storage-blob",
"Tag": "python/storage/azure-storage-blob_4bb162f320"
"Tag": "python/storage/azure-storage-blob_a8a931c55d"
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
SansIOHTTPPolicy,
)

from .authentication import StorageHttpChallenge
from .authentication import AzureSigningError, StorageHttpChallenge
from .constants import DEFAULT_OAUTH_SCOPE
from .models import LocationMode

Expand Down Expand Up @@ -542,6 +542,8 @@ def send(self, request):
continue
break
except AzureError as err:
weirongw23-msft marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(err, AzureSigningError):
raise err
weirongw23-msft marked this conversation as resolved.
Show resolved Hide resolved
retries_remaining = self.increment(
retry_settings, request=request.http_request, error=err)
if retries_remaining:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from azure.core.exceptions import AzureError
from azure.core.pipeline.policies import AsyncBearerTokenCredentialPolicy, AsyncHTTPPolicy

from .authentication import StorageHttpChallenge
from .authentication import AzureSigningError, StorageHttpChallenge
from .constants import DEFAULT_OAUTH_SCOPE
from .policies import is_retry, StorageRetryPolicy

Expand Down Expand Up @@ -127,6 +127,8 @@ async def send(self, request):
continue
break
except AzureError as err:
if isinstance(err, AzureSigningError):
raise err
retries_remaining = self.increment(
retry_settings, request=request.http_request, error=err)
if retries_remaining:
Expand Down
23 changes: 23 additions & 0 deletions sdk/storage/azure-storage-blob/tests/test_blob_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# --------------------------------------------------------------------------

import platform
import time
jalauzon-msft marked this conversation as resolved.
Show resolved Hide resolved
from datetime import datetime, timedelta

import pytest
Expand All @@ -19,6 +20,7 @@
VERSION,
)
from azure.storage.blob._shared.base_client import create_configuration
from azure.storage.blob._shared.authentication import AzureSigningError

from devtools_testutils import recorded_by_proxy
from devtools_testutils.storage import StorageRecordedTestCase
Expand Down Expand Up @@ -731,4 +733,25 @@ def test_create_configuration_legacy(self, **kwargs):
assert config.max_block_size == 4 * 1024 * 1024
assert sdk_name in config.user_agent_policy.user_agent

@BlobPreparer()
@recorded_by_proxy
def test_bad_storage_account_key_no_retry(self, **kwargs):
storage_account_name = kwargs.pop("storage_account_name")
storage_account_key = "a"

blob_client = BlobClient(
account_url=self.account_url(storage_account_name, "blob"),
container_name="foo",
blob_name="bar",
credential=storage_account_key,
)

start = time.time()
with pytest.raises(AzureSigningError) as e:
blob_client.get_blob_properties()
weirongw23-msft marked this conversation as resolved.
Show resolved Hide resolved
end = time.time()

assert "Invalid base64-encoded string" in e.value.message
assert end - start < 2.0

# ------------------------------------------------------------------------------
23 changes: 23 additions & 0 deletions sdk/storage/azure-storage-blob/tests/test_blob_client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# --------------------------------------------------------------------------

import platform
import time
from datetime import datetime, timedelta

import pytest
Expand All @@ -20,6 +21,7 @@
ContainerClient,
BlobServiceClient
)
from azure.storage.blob._shared.authentication import AzureSigningError

from devtools_testutils.aio import recorded_by_proxy_async
from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase
Expand Down Expand Up @@ -680,4 +682,25 @@ async def test_closing_pipeline_client_simple(self, **kwargs):
self.account_url(storage_account_name, "blob"), credential=storage_account_key, container_name='foo', blob_name='bar')
await service.close()

@BlobPreparer()
@recorded_by_proxy_async
async def test_bad_storage_account_key_no_retry(self, **kwargs):
storage_account_name = kwargs.pop("storage_account_name")
storage_account_key = "a"

blob_client = BlobClient(
account_url=self.account_url(storage_account_name, "blob"),
container_name="foo",
blob_name="bar",
credential=storage_account_key,
)

start = time.time()
with pytest.raises(AzureSigningError) as e:
await blob_client.get_blob_properties()
end = time.time()

assert "Invalid base64-encoded string" in e.value.message
assert end - start < 2.0

# ------------------------------------------------------------------------------