Skip to content

Commit

Permalink
[Storage] az storage container create: Fix #13373 by adding validat…
Browse files Browse the repository at this point in the history
…or for public access (#13496)

* add validator for public access

* add public access
  • Loading branch information
Juliehzl authored May 14, 2020
1 parent 2c3097b commit 73ee5ce
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,9 @@ def pop_data_client_auth(ns):


def validate_client_auth_parameter(cmd, ns):
from .sdkutil import get_container_access_type
if ns.public_access:
ns.public_access = get_container_access_type(cmd.cli_ctx, ns.public_access.lower())
if ns.default_encryption_scope and ns.prevent_encryption_scope_override is not None:
# simply try to retrieve the remaining variables from environment variables
if not ns.account_name:
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ interactions:
Content-Length:
- '0'
User-Agent:
- Azure-Storage/2.0.0-2.0.1 (Python CPython 3.7.4; Windows 10) AZURECLI/2.5.1
- Azure-Storage/2.0.0-2.0.1 (Python CPython 3.7.7; Windows 10) AZURECLI/2.5.1
x-ms-date:
- Thu, 07 May 2020 03:48:47 GMT
- Thu, 14 May 2020 07:33:18 GMT
x-ms-version:
- '2018-11-09'
method: PUT
Expand All @@ -21,11 +21,11 @@ interactions:
content-length:
- '0'
date:
- Thu, 07 May 2020 03:48:50 GMT
- Thu, 14 May 2020 07:33:22 GMT
etag:
- '"0x8D7F2398E3ED325"'
- '"0x8D7F7D914AF306F"'
last-modified:
- Thu, 07 May 2020 03:48:50 GMT
- Thu, 14 May 2020 07:33:22 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-version:
Expand All @@ -41,11 +41,11 @@ interactions:
Content-Length:
- '1024'
User-Agent:
- Azure-Storage/2.0.0-2.0.1 (Python CPython 3.7.4; Windows 10) AZURECLI/2.5.1
- Azure-Storage/2.0.0-2.0.1 (Python CPython 3.7.7; Windows 10) AZURECLI/2.5.1
x-ms-blob-type:
- BlockBlob
x-ms-date:
- Thu, 07 May 2020 03:48:51 GMT
- Thu, 14 May 2020 07:33:22 GMT
x-ms-version:
- '2018-11-09'
method: PUT
Expand All @@ -59,11 +59,11 @@ interactions:
content-md5:
- DzQ7CTESaiDxM9Z8KwGKOw==
date:
- Thu, 07 May 2020 03:48:52 GMT
- Thu, 14 May 2020 07:33:23 GMT
etag:
- '"0x8D7F2398F0BE050"'
- '"0x8D7F7D9159AC0DF"'
last-modified:
- Thu, 07 May 2020 03:48:52 GMT
- Thu, 14 May 2020 07:33:23 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-server-encrypted:
Expand All @@ -79,9 +79,9 @@ interactions:
Connection:
- keep-alive
User-Agent:
- Azure-Storage/2.0.0-2.0.1 (Python CPython 3.7.4; Windows 10) AZURECLI/2.5.1
- Azure-Storage/2.0.0-2.0.1 (Python CPython 3.7.7; Windows 10) AZURECLI/2.5.1
x-ms-date:
- Thu, 07 May 2020 03:48:52 GMT
- Thu, 14 May 2020 07:33:24 GMT
x-ms-version:
- '2018-11-09'
method: HEAD
Expand All @@ -99,17 +99,17 @@ interactions:
content-type:
- application/octet-stream
date:
- Thu, 07 May 2020 03:48:52 GMT
- Thu, 14 May 2020 07:33:24 GMT
etag:
- '"0x8D7F2398F0BE050"'
- '"0x8D7F7D9159AC0DF"'
last-modified:
- Thu, 07 May 2020 03:48:52 GMT
- Thu, 14 May 2020 07:33:23 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-blob-type:
- BlockBlob
x-ms-creation-time:
- Thu, 07 May 2020 03:48:52 GMT
- Thu, 14 May 2020 07:33:23 GMT
x-ms-lease-state:
- available
x-ms-lease-status:
Expand All @@ -127,9 +127,9 @@ interactions:
Connection:
- keep-alive
User-Agent:
- Azure-Storage/2.0.0-2.0.1 (Python CPython 3.7.4; Windows 10) AZURECLI/2.5.1
- Azure-Storage/2.0.0-2.0.1 (Python CPython 3.7.7; Windows 10) AZURECLI/2.5.1
x-ms-date:
- Thu, 07 May 2020 03:48:54 GMT
- Thu, 14 May 2020 07:33:25 GMT
x-ms-version:
- '2018-11-09'
method: GET
Expand All @@ -138,16 +138,16 @@ interactions:
body:
string: "\uFEFF<?xml version=\"1.0\" encoding=\"utf-8\"?><EnumerationResults
ServiceEndpoint=\"https://clitest000002.blob.core.windows.net/\" ContainerName=\"container000003\"><MaxResults>5000</MaxResults><Blobs><Blob><Name>blob000004</Name><Properties><Creation-Time>Thu,
07 May 2020 03:48:52 GMT</Creation-Time><Last-Modified>Thu, 07 May 2020 03:48:52
GMT</Last-Modified><Etag>0x8D7F2398F0BE050</Etag><Content-Length>1024</Content-Length><Content-Type>application/octet-stream</Content-Type><Content-Encoding
14 May 2020 07:33:23 GMT</Creation-Time><Last-Modified>Thu, 14 May 2020 07:33:23
GMT</Last-Modified><Etag>0x8D7F7D9159AC0DF</Etag><Content-Length>1024</Content-Length><Content-Type>application/octet-stream</Content-Type><Content-Encoding
/><Content-Language /><Content-MD5>DzQ7CTESaiDxM9Z8KwGKOw==</Content-MD5><Cache-Control
/><Content-Disposition /><BlobType>BlockBlob</BlobType><LeaseStatus>unlocked</LeaseStatus><LeaseState>available</LeaseState><ServerEncrypted>true</ServerEncrypted></Properties></Blob></Blobs><NextMarker
/></EnumerationResults>"
headers:
content-type:
- application/xml
date:
- Thu, 07 May 2020 03:48:54 GMT
- Thu, 14 May 2020 07:33:26 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
transfer-encoding:
Expand All @@ -163,9 +163,9 @@ interactions:
Connection:
- keep-alive
User-Agent:
- Azure-Storage/2.0.0-2.0.1 (Python CPython 3.7.4; Windows 10) AZURECLI/2.5.1
- Azure-Storage/2.0.0-2.0.1 (Python CPython 3.7.7; Windows 10) AZURECLI/2.5.1
x-ms-date:
- Thu, 07 May 2020 03:48:55 GMT
- Thu, 14 May 2020 07:33:27 GMT
x-ms-version:
- '2018-11-09'
method: HEAD
Expand All @@ -183,17 +183,17 @@ interactions:
content-type:
- application/octet-stream
date:
- Thu, 07 May 2020 03:48:55 GMT
- Thu, 14 May 2020 07:33:28 GMT
etag:
- '"0x8D7F2398F0BE050"'
- '"0x8D7F7D9159AC0DF"'
last-modified:
- Thu, 07 May 2020 03:48:52 GMT
- Thu, 14 May 2020 07:33:23 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-blob-type:
- BlockBlob
x-ms-creation-time:
- Thu, 07 May 2020 03:48:52 GMT
- Thu, 14 May 2020 07:33:23 GMT
x-ms-lease-state:
- available
x-ms-lease-status:
Expand All @@ -211,9 +211,9 @@ interactions:
Connection:
- keep-alive
User-Agent:
- Azure-Storage/2.0.0-2.0.1 (Python CPython 3.7.4; Windows 10) AZURECLI/2.5.1
- Azure-Storage/2.0.0-2.0.1 (Python CPython 3.7.7; Windows 10) AZURECLI/2.5.1
x-ms-date:
- Thu, 07 May 2020 03:48:56 GMT
- Thu, 14 May 2020 07:33:28 GMT
x-ms-range:
- bytes=0-33554431
x-ms-version:
Expand All @@ -233,19 +233,19 @@ interactions:
content-type:
- application/octet-stream
date:
- Thu, 07 May 2020 03:48:56 GMT
- Thu, 14 May 2020 07:33:29 GMT
etag:
- '"0x8D7F2398F0BE050"'
- '"0x8D7F7D9159AC0DF"'
last-modified:
- Thu, 07 May 2020 03:48:52 GMT
- Thu, 14 May 2020 07:33:23 GMT
server:
- Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-blob-content-md5:
- DzQ7CTESaiDxM9Z8KwGKOw==
x-ms-blob-type:
- BlockBlob
x-ms-creation-time:
- Thu, 07 May 2020 03:48:52 GMT
- Thu, 14 May 2020 07:33:23 GMT
x-ms-lease-state:
- available
x-ms-lease-status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
# --------------------------------------------------------------------------------------------
from azure.cli.testsdk import (ScenarioTest, JMESPathCheck, ResourceGroupPreparer,
StorageAccountPreparer, api_version_constraint, live_only)
from azure_devtools.scenario_tests import AllowLargeResponse
from azure.cli.core.profiles import ResourceType
from knack.util import CLIError

from ..storage_test_util import StorageScenarioMixin


class StorageAccountEncryptionTests(StorageScenarioMixin, ScenarioTest):
@AllowLargeResponse()
@api_version_constraint(ResourceType.MGMT_STORAGE, min_api='2019-06-01')
@ResourceGroupPreparer(name_prefix='cli_test_storage_encryption')
@StorageAccountPreparer(name_prefix='encryption', kind="StorageV2")
Expand Down Expand Up @@ -112,7 +114,7 @@ def test_storage_account_encryption_scope(self, resource_group, storage_account)
self.cmd("storage container create -n {con} --account-name {sa} -g {rg} --prevent-encryption-scope-override False")

self.cmd(
"storage container create -n {con} --account-name {sa} -g {rg} --default-encryption-scope {encryption} --prevent-encryption-scope-override false",
"storage container create -n {con} --account-name {sa} -g {rg} --default-encryption-scope {encryption} --prevent-encryption-scope-override false --public-access off",
checks=[JMESPathCheck("created", True)])

account_info = self.get_account_info(resource_group, storage_account)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from azure.cli.testsdk import (ScenarioTest, JMESPathCheck, ResourceGroupPreparer,
StorageAccountPreparer, api_version_constraint, record_only)
from azure_devtools.scenario_tests import AllowLargeResponse
from azure.cli.core.profiles import ResourceType
from ..storage_test_util import StorageScenarioMixin

Expand All @@ -15,6 +16,7 @@ class StorageOauthTests(StorageScenarioMixin, ScenarioTest):
def oauth_cmd(self, cmd, *args, **kwargs):
return self.cmd(cmd + ' --auth-mode login', *args, **kwargs)

@AllowLargeResponse()
@ResourceGroupPreparer(name_prefix='cli_test_storage_oauth')
@StorageAccountPreparer()
def test_storage_blob_oauth(self, resource_group, storage_account):
Expand All @@ -27,7 +29,7 @@ def test_storage_blob_oauth(self, resource_group, storage_account):
'blob': self.create_random_name(prefix='blob', length=20)
})

self.oauth_cmd('storage container create -n {container} --account-name {account}', checks=[
self.oauth_cmd('storage container create -n {container} --account-name {account} --public-access off', checks=[
JMESPathCheck('created', True)])

# # upload a blob
Expand Down

0 comments on commit 73ee5ce

Please sign in to comment.