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

Commit 98b99fb

Browse files
authored
Merge pull request #34 from dluces/fix_prefix_issue
Fix prefix issue
2 parents e6c77de + d5385c8 commit 98b99fb

File tree

6 files changed

+38
-18
lines changed

6 files changed

+38
-18
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ MicrosoftAzure\Storage\Queue\Models\GetQueueMetadataResult.setMetadata
2323
MicrosoftAzure\Storage\Queue\Models\Queue.setMetadata
2424
```
2525
* Removed test code from composer package.
26+
* `StorageAuthScheme::computeCanonicalizedResource` assumes that the query parameters are already grouped. That is, multi-value query parameters must be assembled using `ServiceRestProxy::groupQueryValues`. This fixes an issue with other single-value query parameters that might contain the separator character in the value.
2627

2728
Blob
2829
* Added support for user to upload large files with minimum memory usage.

src/Blob/BlobRestProxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ public function listBlobs($container, $options = null)
11731173
$includeSnapshots = $options->getIncludeSnapshots();
11741174
$includeUncommittedBlobs = $options->getIncludeUncommittedBlobs();
11751175

1176-
$includeValue = $this->groupQueryValues(
1176+
$includeValue = static::groupQueryValues(
11771177
array(
11781178
$includeMetadata ? 'metadata' : null,
11791179
$includeSnapshots ? 'snapshots' : null,

src/Common/Internal/Authentication/StorageAuthScheme.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,9 @@ protected function computeCanonicalizedResource($url, $queryParams)
181181
// 9. Group query parameters
182182
// 10. Append a new line character (\n) after each name-value pair.
183183
foreach ($queryParams as $key => $value) {
184-
// Grouping query parameters
185-
$values = explode(Resources::SEPARATOR, $value);
186-
sort($values);
187-
$separated = implode(Resources::SEPARATOR, $values);
188-
189-
$canonicalizedResource .= "\n" . $key . ':' . $separated;
184+
// $value must already be ordered lexicographically
185+
// See: ServiceRestProxy::groupQueryValues
186+
$canonicalizedResource .= "\n" . $key . ':' . $value;
190187
}
191188

192189
return $canonicalizedResource;

src/Common/Internal/ServiceRestProxy.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,13 @@ public function addPostParameter(
503503
*
504504
* @return string
505505
*/
506-
public function groupQueryValues($values)
506+
public static function groupQueryValues($values)
507507
{
508508
Validate::isArray($values, 'values');
509509
$joined = Resources::EMPTY_STRING;
510510

511+
sort($values);
512+
511513
foreach ($values as $value) {
512514
if (!is_null($value) && !empty($value)) {
513515
$joined .= $value . Resources::SEPARATOR;

tests/unit/Common/Internal/Authentication/StorageAuthSchemeTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
namespace MicrosoftAzure\Storage\Tests\Unit\Common\Internal\Authentication;
2626
use MicrosoftAzure\Storage\Common\Internal\Authentication\StorageAuthScheme;
27+
use MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy;
2728
use MicrosoftAzure\Storage\Tests\Unit\Utilities;
2829
use MicrosoftAzure\Storage\Tests\Mock\Common\Internal\Authentication\StorageAuthSchemeMock;
2930
use MicrosoftAzure\Storage\Tests\Framework\TestResources;
@@ -94,7 +95,13 @@ public function testComputeCanonicalizedResourceMockMultipleValues()
9495
{
9596
$queryVariables = array();
9697
$queryVariables['COMP'] = 'list';
97-
$queryVariables[Resources::QP_INCLUDE] = 'snapshots,metadata,uncommittedblobs';
98+
$queryVariables[Resources::QP_INCLUDE] = ServiceRestProxy::groupQueryValues(
99+
array(
100+
'snapshots',
101+
'metadata',
102+
'uncommittedblobs'
103+
)
104+
);
98105
$expectedQueryPart = "comp:list\ninclude:metadata,snapshots,uncommittedblobs";
99106
$accountName = TestResources::ACCOUNT_NAME;
100107
$url = TestResources::URI1;

tests/unit/Common/Internal/ServiceRestProxyTest.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,49 +147,62 @@ public function testAddOptionalSourceAccessContitionHeader($restRestProxy)
147147

148148
/**
149149
* @covers MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::groupQueryValues
150-
* @depends test__construct
151150
*/
152-
public function testGroupQueryValues($restRestProxy)
151+
public function testGroupQueryValues()
153152
{
154153
// Setup
155154
$values = array('A', 'B', 'C');
156155
$expected = 'A,B,C';
157156

158157
// Test
159-
$actual = $restRestProxy->groupQueryValues($values);
158+
$actual = ServiceRestProxy::groupQueryValues($values);
159+
160+
// Assert
161+
$this->assertEquals($expected, $actual);
162+
}
163+
164+
/**
165+
* @covers MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::groupQueryValues
166+
*/
167+
public function testGroupQueryValuesWithUnorderedValues()
168+
{
169+
// Setup
170+
$values = array('B', 'C', 'A');
171+
$expected = 'A,B,C';
172+
173+
// Test
174+
$actual = ServiceRestProxy::groupQueryValues($values);
160175

161176
// Assert
162177
$this->assertEquals($expected, $actual);
163178
}
164179

165180
/**
166181
* @covers MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::groupQueryValues
167-
* @depends test__construct
168182
*/
169-
public function testGroupQueryValuesWithNulls($restRestProxy)
183+
public function testGroupQueryValuesWithNulls()
170184
{
171185
// Setup
172186
$values = array(null, '', null);
173187

174188
// Test
175-
$actual = $restRestProxy->groupQueryValues($values);
189+
$actual = ServiceRestProxy::groupQueryValues($values);
176190

177191
// Assert
178192
$this->assertTrue(empty($actual));
179193
}
180194

181195
/**
182196
* @covers MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::groupQueryValues
183-
* @depends test__construct
184197
*/
185-
public function testGroupQueryValuesWithMix($restRestProxy)
198+
public function testGroupQueryValuesWithMix()
186199
{
187200
// Setup
188201
$values = array(null, 'B', 'C', '');
189202
$expected = 'B,C';
190203

191204
// Test
192-
$actual = $restRestProxy->groupQueryValues($values);
205+
$actual = ServiceRestProxy::groupQueryValues($values);
193206

194207
// Assert
195208
$this->assertEquals($expected, $actual);

0 commit comments

Comments
 (0)