PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/WindowsAzure/azure-sdk-for-php
PHP | 111 lines | 56 code | 13 blank | 42 comment | 0 complexity | 3c3cf6a03b02eb01bf1c722b17e9f6c8 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. *
  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. *
  22. * @link https://github.com/windowsazure/azure-sdk-for-php
  23. */
  24. namespace Tests\unit\WindowsAzure\Common\Internal\Authentication;
  25. use Tests\mock\WindowsAzure\Common\Internal\Authentication\SharedKeyAuthSchemeMock;
  26. use WindowsAzure\Common\Internal\Resources;
  27. use Tests\framework\TestResources;
  28. use PHPUnit\Framework\TestCase;
  29. /**
  30. * Unit tests for SharedKeyAuthScheme class.
  31. *
  32. * @author Azure PHP SDK <azurephpsdk@microsoft.com>
  33. * @copyright 2012 Microsoft Corporation
  34. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
  35. *
  36. * @version Release: 0.5.0_2016-11
  37. *
  38. * @link https://github.com/windowsazure/azure-sdk-for-php
  39. */
  40. class SharedKeyAuthSchemeTest extends TestCase
  41. {
  42. /**
  43. * @covers \WindowsAzure\Common\Internal\Authentication\SharedKeyAuthScheme::__construct
  44. */
  45. public function test__construct()
  46. {
  47. $expected = [];
  48. $expected[] = Resources::CONTENT_ENCODING;
  49. $expected[] = Resources::CONTENT_LANGUAGE;
  50. $expected[] = Resources::CONTENT_LENGTH;
  51. $expected[] = Resources::CONTENT_MD5;
  52. $expected[] = Resources::CONTENT_TYPE;
  53. $expected[] = Resources::DATE;
  54. $expected[] = Resources::IF_MODIFIED_SINCE;
  55. $expected[] = Resources::IF_MATCH;
  56. $expected[] = Resources::IF_NONE_MATCH;
  57. $expected[] = Resources::IF_UNMODIFIED_SINCE;
  58. $expected[] = Resources::RANGE;
  59. $mock = new SharedKeyAuthSchemeMock(TestResources::ACCOUNT_NAME, TestResources::KEY4);
  60. $this->assertEquals($expected, $mock->getIncludedHeaders());
  61. }
  62. /**
  63. * @covers \WindowsAzure\Common\Internal\Authentication\SharedKeyAuthScheme::computeSignature
  64. */
  65. public function testComputeSignatureSimple()
  66. {
  67. $httpMethod = 'GET';
  68. $queryParams = [Resources::QP_COMP => 'list'];
  69. $url = TestResources::URI1;
  70. $date = TestResources::DATE1;
  71. $apiVersion = Resources::STORAGE_API_LATEST_VERSION;
  72. $accountName = TestResources::ACCOUNT_NAME;
  73. $headers = [Resources::X_MS_DATE => $date, Resources::X_MS_VERSION => $apiVersion];
  74. $expected = "GET\n\n\n\n\n\n\n\n\n\n\n\n".Resources::X_MS_DATE.":$date\n".Resources::X_MS_VERSION.
  75. ":$apiVersion\n/$accountName".parse_url($url, PHP_URL_PATH)."\ncomp:list";
  76. $mock = new SharedKeyAuthSchemeMock($accountName, TestResources::KEY4);
  77. $actual = $mock->computeSignatureMock($headers, $url, $queryParams, $httpMethod);
  78. $this->assertEquals($expected, $actual);
  79. }
  80. /**
  81. * @covers \WindowsAzure\Common\Internal\Authentication\SharedKeyAuthScheme::getAuthorizationHeader
  82. */
  83. public function testGetAuthorizationHeaderSimple()
  84. {
  85. $accountName = TestResources::ACCOUNT_NAME;
  86. $apiVersion = Resources::STORAGE_API_LATEST_VERSION;
  87. $accountKey = TestResources::KEY4;
  88. $url = TestResources::URI2;
  89. $date1 = TestResources::DATE2;
  90. $headers = [Resources::X_MS_VERSION => $apiVersion, Resources::X_MS_DATE => $date1];
  91. $queryParams = [Resources::QP_COMP => 'list'];
  92. $httpMethod = 'GET';
  93. $expected = 'SharedKey '.$accountName.':7O9UOMTnAEF+cuwZzo1BlDj2qJm8yNywajta5he6Qig=';
  94. $mock = new SharedKeyAuthSchemeMock($accountName, $accountKey);
  95. $actual = $mock->getAuthorizationHeader($headers, $url, $queryParams, $httpMethod);
  96. $this->assertEquals($expected, $actual);
  97. }
  98. }