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 @@ -7,10 +7,6 @@
STORAGE_ACCOUNT_NAME = "fakename"
STORAGE_ACCOUNT_KEY = "fakekey"

TENANT_ID = "00000000-0000-0000-0000-000000000000"
CLIENT_ID = "00000000-0000-0000-0000-000000000000"
CLIENT_SECRET = "00000000-0000-0000-0000-000000000000"

ACCOUNT_URL_SUFFIX = 'core.windows.net'
RUN_IN_LIVE = "False"
SKIP_LIVE_RECORDING = "True"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
os.environ['PROTOCOL'] = PROTOCOL
os.environ['ACCOUNT_URL_SUFFIX'] = ACCOUNT_URL_SUFFIX

os.environ['STORAGE_TENANT_ID'] = os.environ.get('STORAGE_TENANT_ID', None) or TENANT_ID
os.environ['STORAGE_CLIENT_ID'] = os.environ.get('STORAGE_CLIENT_ID', None) or CLIENT_ID
os.environ['STORAGE_CLIENT_SECRET'] = os.environ.get('STORAGE_CLIENT_SECRET', None) or CLIENT_SECRET

ChangeFeedPreparer = functools.partial(
PowerShellPreparer, "storage",
storage_account_name="storagename",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
SOFT_DELETE_STORAGE_ACCOUNT_KEY = "fakekey"
STORAGE_RESOURCE_GROUP_NAME = "fakename"

TENANT_ID = "00000000-0000-0000-0000-000000000000"
CLIENT_ID = "00000000-0000-0000-0000-000000000000"
CLIENT_SECRET = "00000000-0000-0000-0000-000000000000"

ACCOUNT_URL_SUFFIX = 'core.windows.net'
RUN_IN_LIVE = "False"
SKIP_LIVE_RECORDING = "True"
Expand Down
4 changes: 0 additions & 4 deletions sdk/storage/azure-storage-blob/tests/settings/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
os.environ['PROTOCOL'] = PROTOCOL
os.environ['ACCOUNT_URL_SUFFIX'] = ACCOUNT_URL_SUFFIX

os.environ['STORAGE_TENANT_ID'] = os.environ.get('STORAGE_TENANT_ID', None) or TENANT_ID
os.environ['STORAGE_CLIENT_ID'] = os.environ.get('STORAGE_CLIENT_ID', None) or CLIENT_ID
os.environ['STORAGE_CLIENT_SECRET'] = os.environ.get('STORAGE_CLIENT_SECRET', None) or CLIENT_SECRET

BlobPreparer = functools.partial(
PowerShellPreparer, "storage",
storage_account_name="storagename",
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/azure-storage-blob/tests/test_append_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def test_append_block_from_url_with_oauth(self, **kwargs):
source_blob_data = self.get_random_bytes(LARGE_BLOB_SIZE)
source_blob_client = self._create_source_blob(source_blob_data, bsc)
destination_blob_client = self._create_blob(bsc)
token = "Bearer {}".format(self.generate_oauth_token().get_token("https://storage.azure.com/.default").token)
token = "Bearer {}".format(self.get_credential(BlobServiceClient).get_token("https://storage.azure.com/.default").token)

# Assert this operation fails without a credential
with pytest.raises(HttpResponseError):
Expand Down Expand Up @@ -1529,7 +1529,7 @@ def test_create_append_blob_with_immutability_policy(self, **kwargs):

container_name = self.get_resource_name('vlwcontainer')
if self.is_live:
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)
subscription_id = self.get_settings_value("SUBSCRIPTION_ID")
mgmt_client = StorageManagementClient(token_credential, subscription_id, '2021-04-01')
property = mgmt_client.models().BlobContainer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def test_append_block_from_url_with_oauth(self, **kwargs):
source_blob_data = self.get_random_bytes(LARGE_BLOB_SIZE)
source_blob_client = await self._create_source_blob(source_blob_data, bsc)
destination_blob_client = await self._create_blob(bsc)
access_token = await self.generate_oauth_token().get_token("https://storage.azure.com/.default")
access_token = await self.get_credential(BlobServiceClient, is_async=True).get_token("https://storage.azure.com/.default")
token = "Bearer {}".format(access_token.token)

# Assert this operation fails without a credential
Expand Down Expand Up @@ -1521,7 +1521,7 @@ async def test_create_append_blob_with_immutability_policy(self, **kwargs):

container_name = self.get_resource_name('vlwcontainerasync')
if self.is_live:
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient, is_async=True)
subscription_id = self.get_settings_value("SUBSCRIPTION_ID")
mgmt_client = StorageManagementClient(token_credential, subscription_id, '2021-04-01')
property = mgmt_client.models().BlobContainer(
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/azure-storage-blob/tests/test_blob_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_create_service_with_sas_credential_url_raises_if_sas_is_in_uri(self, **
def test_create_service_with_token(self, **kwargs):
storage_account_name = kwargs.pop("storage_account_name")

token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)
for service_type in SERVICES:
# Act
service = service_type(
Expand All @@ -173,7 +173,7 @@ def test_create_service_with_token(self, **kwargs):
def test_create_service_with_token_and_http(self, **kwargs):
storage_account_name = kwargs.pop("storage_account_name")

token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)
for service_type in SERVICES:
# Act
with pytest.raises(ValueError):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
BlobServiceClient
)

from devtools_testutils.fake_credentials_async import AsyncFakeCredential
from devtools_testutils.aio import recorded_by_proxy_async
from devtools_testutils.storage.aio import AsyncStorageRecordedTestCase
from settings.testcase import BlobPreparer
Expand Down Expand Up @@ -144,7 +145,7 @@ def test_create_service_with_sas_credential_url_raises_if_sas_is_in_uri(self, **
async def test_create_service_with_token(self, **kwargs):
storage_account_name = kwargs.pop("storage_account_name")

token_credential = self.generate_fake_token()
token_credential = AsyncFakeCredential()
for service_type in SERVICES:
# Act
service = service_type(
Expand All @@ -160,7 +161,7 @@ async def test_create_service_with_token(self, **kwargs):
async def test_create_service_with_token_and_http(self, **kwargs):
storage_account_name = kwargs.pop("storage_account_name")

token_credential = self.generate_fake_token()
token_credential = AsyncFakeCredential()
for service_type in SERVICES:
# Act
with pytest.raises(ValueError):
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/azure-storage-blob/tests/test_block_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_upload_blob_from_url_with_oauth(self, **kwargs):
source_blob_data = self.get_random_bytes(LARGE_BLOB_SIZE)
source_blob_client = self._create_source_blob(data=source_blob_data)
destination_blob_client = self._create_blob()
token = "Bearer {}".format(self.generate_oauth_token().get_token("https://storage.azure.com/.default").token)
token = "Bearer {}".format(self.get_credential(BlobServiceClient).get_token("https://storage.azure.com/.default").token)

# Assert this operation fails without a credential
with pytest.raises(HttpResponseError):
Expand Down Expand Up @@ -583,7 +583,7 @@ def test_put_block_with_immutability_policy(self, **kwargs):
container_name = self.get_resource_name('vlwcontainer')

if self.is_live:
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)
subscription_id = self.get_settings_value("SUBSCRIPTION_ID")

mgmt_client = StorageManagementClient(token_credential, subscription_id, '2021-04-01')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async def test_upload_blob_from_url_with_oauth(self, **kwargs):
source_blob_data = self.get_random_bytes(LARGE_BLOB_SIZE)
source_blob_client = await self._create_source_blob(data=source_blob_data)
destination_blob_client = await self._create_blob()
access_token = await self.generate_oauth_token().get_token("https://storage.azure.com/.default")
access_token = await self.get_credential(BlobServiceClient, is_async=True).get_token("https://storage.azure.com/.default")
token = "Bearer {}".format(access_token.token)

# Assert this operation fails without a credential
Expand Down Expand Up @@ -665,7 +665,7 @@ async def test_put_block_with_immutability_policy(self, **kwargs):
container_name = self.get_resource_name('vlwcontainer')

if self.is_live:
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient, is_async=True)
subscription_id = self.get_settings_value("SUBSCRIPTION_ID")

mgmt_client = StorageManagementClient(token_credential, subscription_id, '2021-04-01')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_put_block_from_url_with_oauth(self, **kwargs):
split = 4 * 1024
destination_blob_name = self.get_resource_name('destblob')
destination_blob_client = self.bsc.get_blob_client(self.container_name, destination_blob_name)
token = "Bearer {}".format(self.generate_oauth_token().get_token("https://storage.azure.com/.default").token)
token = "Bearer {}".format(self.get_credential(BlobServiceClient).get_token("https://storage.azure.com/.default").token)

# Assert this operation fails without a credential
with pytest.raises(HttpResponseError):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async def test_put_block_from_url_with_oauth(self, **kwargs):
split = 4 * 1024
destination_blob_name = self.get_resource_name('destblob')
destination_blob_client = self.bsc.get_blob_client(self.container_name, destination_blob_name)
access_token = await self.generate_oauth_token().get_token("https://storage.azure.com/.default")
access_token = await self.get_credential(BlobServiceClient, is_async=True).get_token("https://storage.azure.com/.default")
token = "Bearer {}".format(access_token.token)

# Assert this operation fails without a credential
Expand Down
40 changes: 20 additions & 20 deletions sdk/storage/azure-storage-blob/tests/test_common_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
upload_blob_to_url)
from azure.storage.blob._generated.models import RehydratePriority

from devtools_testutils import recorded_by_proxy
from devtools_testutils import FakeTokenCredential, recorded_by_proxy
from devtools_testutils.storage import StorageRecordedTestCase
from settings.testcase import BlobPreparer

Expand Down Expand Up @@ -1367,7 +1367,7 @@ def test_start_copy_from_url_with_oauth(self, **kwargs):
source_blob_client = self._create_source_blob(data=source_blob_data)
# Create destination blob
destination_blob_client = self._create_blob()
token = "Bearer {}".format(self.generate_oauth_token().get_token("https://storage.azure.com/.default").token)
token = "Bearer {}".format(self.get_credential(BlobServiceClient).get_token("https://storage.azure.com/.default").token)

with pytest.raises(HttpResponseError):
destination_blob_client.start_copy_from_url(source_blob_client.url, requires_sync=True)
Expand Down Expand Up @@ -1418,7 +1418,7 @@ def test_copy_blob_with_immutability_policy(self, **kwargs):

container_name = self.get_resource_name('vlwcontainer')
if self.is_live:
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)
subscription_id = self.get_settings_value("SUBSCRIPTION_ID")
mgmt_client = StorageManagementClient(token_credential, subscription_id, '2021-04-01')
property = mgmt_client.models().BlobContainer(
Expand Down Expand Up @@ -2171,7 +2171,7 @@ def test_set_immutability_policy_using_sas(self, **kwargs):

container_name = self.get_resource_name('vlwcontainer')
if self.is_live:
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)
subscription_id = self.get_settings_value("SUBSCRIPTION_ID")
mgmt_client = StorageManagementClient(token_credential, subscription_id, '2021-04-01')
property = mgmt_client.models().BlobContainer(
Expand Down Expand Up @@ -2314,7 +2314,7 @@ def test_get_user_delegation_key(self, **kwargs):

# Act
self._setup(storage_account_name, storage_account_key)
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)

# Action 1: make sure token works
service = BlobServiceClient(self.account_url(storage_account_name, "blob"), credential=token_credential)
Expand Down Expand Up @@ -2351,7 +2351,7 @@ def test_user_delegation_sas_for_blob(self, **kwargs):
variables = kwargs.pop("variables", {})
byte_data = self.get_random_bytes(1024)
# Arrange
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)
service_client = BlobServiceClient(self.account_url(storage_account_name, "blob"), credential=token_credential)

start = self.get_datetime_variable(variables, 'start', datetime.utcnow())
Expand Down Expand Up @@ -2390,15 +2390,15 @@ def test_token_credential(self, **kwargs):
storage_account_key = kwargs.pop("storage_account_key")

self._setup(storage_account_name, storage_account_key)
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)

# Action 1: make sure token works
service = BlobServiceClient(self.account_url(storage_account_name, "blob"), credential=token_credential)
result = service.get_service_properties()
assert result is not None

# Action 2: change token value to make request fail
fake_credential = self.generate_fake_token()
fake_credential = FakeTokenCredential()
service = BlobServiceClient(self.account_url(storage_account_name, "blob"), credential=fake_credential)
with pytest.raises(ClientAuthenticationError):
service.get_service_properties()
Expand All @@ -2417,7 +2417,7 @@ def test_token_credential_blob(self, **kwargs):
container_name = self._get_container_reference()
blob_name = self._get_blob_reference()
blob_data = b'Helloworld'
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)

service = BlobServiceClient(self.account_url(storage_account_name, "blob"), credential=token_credential)
container = service.get_container_client(container_name)
Expand All @@ -2442,7 +2442,7 @@ def test_token_credential_with_batch_operation(self, **kwargs):
# Setup
container_name = self._get_container_reference()
blob_name = self._get_blob_reference()
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)
service = BlobServiceClient(self.account_url(storage_account_name, "blob"), credential=token_credential)
container = service.get_container_client(container_name)
try:
Expand Down Expand Up @@ -3097,7 +3097,7 @@ def test_access_token_refresh_after_retry(self, **kwargs):

def fail_response(response):
response.http_response.status_code = 408
token_credential = self.generate_fake_token()
token_credential = FakeTokenCredential()
retry = LinearRetry(backoff=2, random_jitter_range=1, retry_total=4)

bsc = BlobServiceClient(self.account_url(storage_account_name, "blob"), credential=token_credential, retry_policy=retry)
Expand All @@ -3120,7 +3120,7 @@ def test_blob_immutability_policy(self, **kwargs):

container_name = self.get_resource_name('vlwcontainer')
if self.is_live:
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)
subscription_id = self.get_settings_value("SUBSCRIPTION_ID")
mgmt_client = StorageManagementClient(token_credential, subscription_id, '2021-04-01')
property = mgmt_client.models().BlobContainer(
Expand Down Expand Up @@ -3171,7 +3171,7 @@ def test_blob_legal_hold(self, **kwargs):

container_name = self.get_resource_name('vlwcontainer')
if self.is_live:
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)
subscription_id = self.get_settings_value("SUBSCRIPTION_ID")
mgmt_client = StorageManagementClient(token_credential, subscription_id, '2021-04-01')
property = mgmt_client.models().BlobContainer(
Expand Down Expand Up @@ -3214,7 +3214,7 @@ def test_download_blob_with_immutability_policy(self, **kwargs):
self._setup(versioned_storage_account_name, versioned_storage_account_key)
container_name = self.get_resource_name('vlwcontainer')
if self.is_live:
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)
subscription_id = self.get_settings_value("SUBSCRIPTION_ID")
mgmt_client = StorageManagementClient(token_credential, subscription_id, '2021-04-01')
property = mgmt_client.models().BlobContainer(
Expand Down Expand Up @@ -3263,7 +3263,7 @@ def test_list_blobs_with_immutability_policy(self, **kwargs):
self._setup(versioned_storage_account_name, versioned_storage_account_key)
container_name = self.get_resource_name('vlwcontainer')
if self.is_live:
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)
subscription_id = self.get_settings_value("SUBSCRIPTION_ID")
mgmt_client = StorageManagementClient(token_credential, subscription_id, '2021-04-01')
property = mgmt_client.models().BlobContainer(
Expand Down Expand Up @@ -3396,7 +3396,7 @@ def test_storage_account_audience_blob_service_client(self, **kwargs):
self.bsc.list_containers()

# Act
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobServiceClient)
bsc = BlobServiceClient(
self.account_url(storage_account_name, "blob"), credential=token_credential,
audience=f'https://{storage_account_name}.blob.core.windows.net'
Expand All @@ -3419,7 +3419,7 @@ def test_storage_account_audience_blob_client(self, **kwargs):
blob.exists()

# Act
token_credential = self.generate_oauth_token()
token_credential = self.get_credential(BlobClient)
blob = BlobClient(
self.bsc.url, container_name=self.container_name, blob_name=blob_name,
credential=token_credential, audience=f'https://{storage_account_name}.blob.core.windows.net'
Expand All @@ -3439,9 +3439,9 @@ def test_oauth_error_handling(self, **kwargs):

# Generate an invalid credential
creds = ClientSecretCredential(
self.get_settings_value("TENANT_ID"),
self.get_settings_value("CLIENT_ID"),
self.get_settings_value("CLIENT_SECRET") + 'a'
"00000000-0000-0000-0000-000000000000",
"00000000-0000-0000-0000-000000000000",
"00000000-0000-0000-0000-000000000000" + 'a'
)

bsc = BlobServiceClient(self.account_url(storage_account_name, "blob"), credential=creds, retry_total=0)
Expand Down
Loading