/Frontend/barca/vendor/microsoft/windowsazure/tests/unit/WindowsAzure/Common/Internal/Authentication/SharedKeyAuthSchemeTest.php
PHP | 109 lines | 55 code | 14 blank | 40 comment | 0 complexity | dbae3638a3d41d2607a6dc38aa5f4080 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-2.0
- <?php
- /**
- * LICENSE: Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * PHP version 5
- *
- * @category Microsoft
- * @package Tests\Unit\WindowsAzure\Common\Internal\Authentication
- * @author Azure PHP SDK <azurephpsdk@microsoft.com>
- * @copyright 2012 Microsoft Corporation
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
- * @link https://github.com/windowsazure/azure-sdk-for-php
- */
- namespace Tests\Unit\WindowsAzure\Common\Internal\Authentication;
- use Tests\Mock\WindowsAzure\Common\Internal\Authentication\SharedKeyAuthSchemeMock;
- use WindowsAzure\Common\Internal\Resources;
- use Tests\Framework\TestResources;
- /**
- * Unit tests for SharedKeyAuthScheme class.
- *
- * @package Tests\Unit\WindowsAzure\Common\Internal\Authentication
- * @author Azure PHP SDK <azurephpsdk@microsoft.com>
- * @copyright 2012 Microsoft Corporation
- * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
- * @version Release: 0.3.1_2011-08
- * @link https://github.com/windowsazure/azure-sdk-for-php
- */
- class SharedKeyAuthSchemeTest extends \PHPUnit_Framework_TestCase
- {
- /**
- * @covers WindowsAzure\Common\Internal\Authentication\SharedKeyAuthScheme::__construct
- */
- public function test__construct()
- {
- $expected = array();
- $expected[] = Resources::CONTENT_ENCODING;
- $expected[] = Resources::CONTENT_LANGUAGE;
- $expected[] = Resources::CONTENT_LENGTH;
- $expected[] = Resources::CONTENT_MD5;
- $expected[] = Resources::CONTENT_TYPE;
- $expected[] = Resources::DATE;
- $expected[] = Resources::IF_MODIFIED_SINCE;
- $expected[] = Resources::IF_MATCH;
- $expected[] = Resources::IF_NONE_MATCH;
- $expected[] = Resources::IF_UNMODIFIED_SINCE;
- $expected[] = Resources::RANGE;
- $mock = new SharedKeyAuthSchemeMock(TestResources::ACCOUNT_NAME, TestResources::KEY4);
- $this->assertEquals($expected, $mock->getIncludedHeaders());
- }
- /**
- * @covers WindowsAzure\Common\Internal\Authentication\SharedKeyAuthScheme::computeSignature
- */
- public function testComputeSignatureSimple()
- {
- $httpMethod = 'GET';
- $queryParams = array(Resources::QP_COMP => 'list');
- $url = TestResources::URI1;
- $date = TestResources::DATE1;
- $apiVersion = Resources::STORAGE_API_LATEST_VERSION;
- $accountName = TestResources::ACCOUNT_NAME;
- $headers = array(Resources::X_MS_DATE => $date, Resources::X_MS_VERSION => $apiVersion);
- $expected = "GET\n\n\n\n\n\n\n\n\n\n\n\n" . Resources::X_MS_DATE . ":$date\n" . Resources::X_MS_VERSION .
- ":$apiVersion\n/$accountName" . parse_url($url, PHP_URL_PATH) . "\ncomp:list";
- $mock = new SharedKeyAuthSchemeMock($accountName, TestResources::KEY4);
- $actual = $mock->computeSignatureMock($headers, $url, $queryParams, $httpMethod);
- $this->assertEquals($expected, $actual);
- }
- /**
- * @covers WindowsAzure\Common\Internal\Authentication\SharedKeyAuthScheme::getAuthorizationHeader
- */
- public function testGetAuthorizationHeaderSimple()
- {
- $accountName = TestResources::ACCOUNT_NAME;
- $apiVersion = Resources::STORAGE_API_LATEST_VERSION;
- $accountKey = TestResources::KEY4;
- $url = TestResources::URI2;
- $date1 = TestResources::DATE2;
- $headers = array(Resources::X_MS_VERSION => $apiVersion, Resources::X_MS_DATE => $date1);
- $queryParams = array(Resources::QP_COMP => 'list');
- $httpMethod = 'GET';
- $expected = 'SharedKey ' . $accountName . ':tPIT33PrvWHsSXTbzvT93R4YmP13c5H6WB7lGKO3E2M=';
- $mock = new SharedKeyAuthSchemeMock($accountName, $accountKey);
- $actual = $mock->getAuthorizationHeader($headers, $url, $queryParams, $httpMethod);
- $this->assertEquals($expected, $actual);
- }
- }