Skip to content
This repository was archived by the owner on Jul 18, 2024. It is now read-only.

Commit fe1a88d

Browse files
committed
Fix SAS permission derivation with leading ? char
1 parent 72e89c3 commit fe1a88d

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## [Unreleased]
44

5+
### Fixed
6+
- Fix SAS permission derivation on SAS keys with leading '?' character
7+
58
## [1.9.2] - 2019-09-09
69
### Fixed
710
- Fix default overwrite behavior on upload performing point query lookups

blobxfer/operations/azure/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ def __init__(self, name, key, endpoint, transfer_threads, timeout, proxy):
122122
self.key = key
123123
self.endpoint = endpoint
124124
self.is_sas = StorageAccount._key_is_sas(self.key)
125+
# normalize sas keys
126+
if self.is_sas and self.key[0] == '?':
127+
self.key = self.key[1:]
125128
self.can_create_containers = self._container_manipulation_allowed()
126129
self.can_list_container_objects = (
127130
self._credential_allows_container_list()
@@ -134,9 +137,6 @@ def __init__(self, name, key, endpoint, transfer_threads, timeout, proxy):
134137
raise ValueError(
135138
'the provided SAS does not allow object-level access for '
136139
'account: {}'.format(self.name))
137-
# normalize sas keys
138-
if self.key.startswith('?'):
139-
self.key = self.key[1:]
140140
else:
141141
# check if sa shared key is base64
142142
if StorageAccount._VALID_BASE64_RE.match(self.key) is None:

tests/test_blobxfer_operations_azure.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,26 @@ def test_credential_allows_object_read():
179179
assert a._credential_allows_object_read()
180180
assert a.can_read_object
181181

182+
a = azops.StorageAccount(
183+
'name', '?sp=r&sr=b&sig=2', 'core.windows.net', 10, to, None)
184+
assert a._credential_allows_object_read()
185+
assert a.can_read_object
186+
187+
a = azops.StorageAccount(
188+
'name', 'sp=r&sr=b&sig=2', 'core.windows.net', 10, to, None)
189+
assert a._credential_allows_object_read()
190+
assert a.can_read_object
191+
192+
a = azops.StorageAccount(
193+
'name', '?sr=b&sp=r&sig=2', 'core.windows.net', 10, to, None)
194+
assert a._credential_allows_object_read()
195+
assert a.can_read_object
196+
197+
a = azops.StorageAccount(
198+
'name', 'sr=b&sp=r&sig=2', 'core.windows.net', 10, to, None)
199+
assert a._credential_allows_object_read()
200+
assert a.can_read_object
201+
182202
a = azops.StorageAccount(
183203
'name', '?sv=0&si=policy&sig=2', 'core.windows.net', 10, to, None)
184204
assert a._credential_allows_object_read()

0 commit comments

Comments
 (0)