PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/unit/WindowsAzure/Common/Internal/Authentication/SharedKeyAuthSchemeTest.php

https://bitbucket.org/skudatech/azure-sdk-for-php
PHP | 109 lines | 55 code | 14 blank | 40 comment | 0 complexity | 803498fd8aad6339184b26f3eb5ed3ff MD5 | raw file
  1. <?php
  2. /**
  3. * LICENSE: Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. *
  14. * PHP version 5
  15. *
  16. * @category Microsoft
  17. * @package Tests\Unit\WindowsAzure\Common\Internal\Authentication
  18. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  19. * @copyright 2012 Microsoft Corporation
  20. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  21. * @link https://github.com/windowsazure/azure-sdk-for-php
  22. */
  23. namespace Tests\Unit\WindowsAzure\Common\Internal\Authentication;
  24. use Tests\Mock\WindowsAzure\Common\Internal\Authentication\SharedKeyAuthSchemeMock;
  25. use WindowsAzure\Common\Internal\Resources;
  26. use Tests\Framework\TestResources;
  27. /**
  28. * Unit tests for SharedKeyAuthScheme class.
  29. *
  30. * @package Tests\Unit\WindowsAzure\Common\Internal\Authentication
  31. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  32. * @copyright 2012 Microsoft Corporation
  33. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  34. * @version Release: @package_version@
  35. * @link https://github.com/windowsazure/azure-sdk-for-php
  36. */
  37. class SharedKeyAuthSchemeTest extends \PHPUnit_Framework_TestCase
  38. {
  39. /**
  40. * @covers WindowsAzure\Common\Internal\Authentication\SharedKeyAuthScheme::__construct
  41. */
  42. public function test__construct()
  43. {
  44. $expected = array();
  45. $expected[] = Resources::CONTENT_ENCODING;
  46. $expected[] = Resources::CONTENT_LANGUAGE;
  47. $expected[] = Resources::CONTENT_LENGTH;
  48. $expected[] = Resources::CONTENT_MD5;
  49. $expected[] = Resources::CONTENT_TYPE;
  50. $expected[] = Resources::DATE;
  51. $expected[] = Resources::IF_MODIFIED_SINCE;
  52. $expected[] = Resources::IF_MATCH;
  53. $expected[] = Resources::IF_NONE_MATCH;
  54. $expected[] = Resources::IF_UNMODIFIED_SINCE;
  55. $expected[] = Resources::RANGE;
  56. $mock = new SharedKeyAuthSchemeMock(TestResources::ACCOUNT_NAME, TestResources::KEY4);
  57. $this->assertEquals($expected, $mock->getIncludedHeaders());
  58. }
  59. /**
  60. * @covers WindowsAzure\Common\Internal\Authentication\SharedKeyAuthScheme::computeSignature
  61. */
  62. public function testComputeSignatureSimple()
  63. {
  64. $httpMethod = 'GET';
  65. $queryParams = array(Resources::QP_COMP => 'list');
  66. $url = TestResources::URI1;
  67. $date = TestResources::DATE1;
  68. $apiVersion = Resources::STORAGE_API_LATEST_VERSION;
  69. $accountName = TestResources::ACCOUNT_NAME;
  70. $headers = array(Resources::X_MS_DATE => $date, Resources::X_MS_VERSION => $apiVersion);
  71. $expected = "GET\n\n\n\n\n\n\n\n\n\n\n\n" . Resources::X_MS_DATE . ":$date\n" . Resources::X_MS_VERSION .
  72. ":$apiVersion\n/$accountName" . parse_url($url, PHP_URL_PATH) . "\ncomp:list";
  73. $mock = new SharedKeyAuthSchemeMock($accountName, TestResources::KEY4);
  74. $actual = $mock->computeSignatureMock($headers, $url, $queryParams, $httpMethod);
  75. $this->assertEquals($expected, $actual);
  76. }
  77. /**
  78. * @covers WindowsAzure\Common\Internal\Authentication\SharedKeyAuthScheme::getAuthorizationHeader
  79. */
  80. public function testGetAuthorizationHeaderSimple()
  81. {
  82. $accountName = TestResources::ACCOUNT_NAME;
  83. $apiVersion = Resources::STORAGE_API_LATEST_VERSION;
  84. $accountKey = TestResources::KEY4;
  85. $url = TestResources::URI2;
  86. $date1 = TestResources::DATE2;
  87. $headers = array(Resources::X_MS_VERSION => $apiVersion, Resources::X_MS_DATE => $date1);
  88. $queryParams = array(Resources::QP_COMP => 'list');
  89. $httpMethod = 'GET';
  90. $expected = 'SharedKey ' . $accountName . ':tPIT33PrvWHsSXTbzvT93R4YmP13c5H6WB7lGKO3E2M=';
  91. $mock = new SharedKeyAuthSchemeMock($accountName, $accountKey);
  92. $actual = $mock->getAuthorizationHeader($headers, $url, $queryParams, $httpMethod);
  93. $this->assertEquals($expected, $actual);
  94. }
  95. }