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

Commit

Permalink
Merge pull request #34 from dluces/fix_prefix_issue
Browse files Browse the repository at this point in the history
Fix prefix issue
  • Loading branch information
vinjiang authored Nov 11, 2016
2 parents e6c77de + d5385c8 commit 98b99fb
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 18 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ MicrosoftAzure\Storage\Queue\Models\GetQueueMetadataResult.setMetadata
MicrosoftAzure\Storage\Queue\Models\Queue.setMetadata
```
* Removed test code from composer package.
* `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.

Blob
* Added support for user to upload large files with minimum memory usage.
Expand Down
2 changes: 1 addition & 1 deletion src/Blob/BlobRestProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ public function listBlobs($container, $options = null)
$includeSnapshots = $options->getIncludeSnapshots();
$includeUncommittedBlobs = $options->getIncludeUncommittedBlobs();

$includeValue = $this->groupQueryValues(
$includeValue = static::groupQueryValues(
array(
$includeMetadata ? 'metadata' : null,
$includeSnapshots ? 'snapshots' : null,
Expand Down
9 changes: 3 additions & 6 deletions src/Common/Internal/Authentication/StorageAuthScheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,9 @@ protected function computeCanonicalizedResource($url, $queryParams)
// 9. Group query parameters
// 10. Append a new line character (\n) after each name-value pair.
foreach ($queryParams as $key => $value) {
// Grouping query parameters
$values = explode(Resources::SEPARATOR, $value);
sort($values);
$separated = implode(Resources::SEPARATOR, $values);

$canonicalizedResource .= "\n" . $key . ':' . $separated;
// $value must already be ordered lexicographically
// See: ServiceRestProxy::groupQueryValues
$canonicalizedResource .= "\n" . $key . ':' . $value;
}

return $canonicalizedResource;
Expand Down
4 changes: 3 additions & 1 deletion src/Common/Internal/ServiceRestProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,13 @@ public function addPostParameter(
*
* @return string
*/
public function groupQueryValues($values)
public static function groupQueryValues($values)
{
Validate::isArray($values, 'values');
$joined = Resources::EMPTY_STRING;

sort($values);

foreach ($values as $value) {
if (!is_null($value) && !empty($value)) {
$joined .= $value . Resources::SEPARATOR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace MicrosoftAzure\Storage\Tests\Unit\Common\Internal\Authentication;
use MicrosoftAzure\Storage\Common\Internal\Authentication\StorageAuthScheme;
use MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy;
use MicrosoftAzure\Storage\Tests\Unit\Utilities;
use MicrosoftAzure\Storage\Tests\Mock\Common\Internal\Authentication\StorageAuthSchemeMock;
use MicrosoftAzure\Storage\Tests\Framework\TestResources;
Expand Down Expand Up @@ -94,7 +95,13 @@ public function testComputeCanonicalizedResourceMockMultipleValues()
{
$queryVariables = array();
$queryVariables['COMP'] = 'list';
$queryVariables[Resources::QP_INCLUDE] = 'snapshots,metadata,uncommittedblobs';
$queryVariables[Resources::QP_INCLUDE] = ServiceRestProxy::groupQueryValues(
array(
'snapshots',
'metadata',
'uncommittedblobs'
)
);
$expectedQueryPart = "comp:list\ninclude:metadata,snapshots,uncommittedblobs";
$accountName = TestResources::ACCOUNT_NAME;
$url = TestResources::URI1;
Expand Down
31 changes: 22 additions & 9 deletions tests/unit/Common/Internal/ServiceRestProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,49 +147,62 @@ public function testAddOptionalSourceAccessContitionHeader($restRestProxy)

/**
* @covers MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::groupQueryValues
* @depends test__construct
*/
public function testGroupQueryValues($restRestProxy)
public function testGroupQueryValues()
{
// Setup
$values = array('A', 'B', 'C');
$expected = 'A,B,C';

// Test
$actual = $restRestProxy->groupQueryValues($values);
$actual = ServiceRestProxy::groupQueryValues($values);

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

/**
* @covers MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::groupQueryValues
*/
public function testGroupQueryValuesWithUnorderedValues()
{
// Setup
$values = array('B', 'C', 'A');
$expected = 'A,B,C';

// Test
$actual = ServiceRestProxy::groupQueryValues($values);

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

/**
* @covers MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::groupQueryValues
* @depends test__construct
*/
public function testGroupQueryValuesWithNulls($restRestProxy)
public function testGroupQueryValuesWithNulls()
{
// Setup
$values = array(null, '', null);

// Test
$actual = $restRestProxy->groupQueryValues($values);
$actual = ServiceRestProxy::groupQueryValues($values);

// Assert
$this->assertTrue(empty($actual));
}

/**
* @covers MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::groupQueryValues
* @depends test__construct
*/
public function testGroupQueryValuesWithMix($restRestProxy)
public function testGroupQueryValuesWithMix()
{
// Setup
$values = array(null, 'B', 'C', '');
$expected = 'B,C';

// Test
$actual = $restRestProxy->groupQueryValues($values);
$actual = ServiceRestProxy::groupQueryValues($values);

// Assert
$this->assertEquals($expected, $actual);
Expand Down

0 comments on commit 98b99fb

Please sign in to comment.