SharedKeyLiteTest.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_WindowsAzure
  17. * @subpackage UnitTests
  18. * @version $Id: Credentials_SharedKeyTest.php 14561 2009-05-07 08:05:12Z unknown $
  19. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/TestHelper.php';
  23. if (!defined('PHPUnit_MAIN_METHOD')) {
  24. define('PHPUnit_MAIN_METHOD', 'Zend_Service_WindowsAzure_Credentials_SharedKeyLiteTest::main');
  25. }
  26. require_once 'Zend/Service/WindowsAzure/Credentials/SharedKeyLite.php';
  27. require_once 'Zend/Service/WindowsAzure/Credentials/SharedKey.php';
  28. /**
  29. * @category Zend
  30. * @package Zend_Service_WindowsAzure
  31. * @subpackage UnitTests
  32. * @group Zend_Service
  33. * @group Zend_Service_WindowsAzure
  34. * @version $Id: Credentials_SharedKeyTest.php 14561 2009-05-07 08:05:12Z unknown $
  35. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. */
  38. class Zend_Service_WindowsAzure_Credentials_SharedKeyLiteTest extends PHPUnit_Framework_TestCase
  39. {
  40. public static function main()
  41. {
  42. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  43. $result = PHPUnit_TextUI_TestRunner::run($suite);
  44. }
  45. /**
  46. * Test signing for devstore with root path
  47. */
  48. public function testSignForDevstoreWithRootPath()
  49. {
  50. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedKeyLite(Zend_Service_WindowsAzure_Credentials_SharedKey::DEVSTORE_ACCOUNT, Zend_Service_WindowsAzure_Credentials_SharedKey::DEVSTORE_KEY, true);
  51. $signedHeaders = $credentials->signRequestHeaders(
  52. 'GET',
  53. '/',
  54. '',
  55. array("x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT"),
  56. false
  57. );
  58. $this->assertType('array', $signedHeaders);
  59. $this->assertEquals(2, count($signedHeaders));
  60. $this->assertEquals("SharedKeyLite devstoreaccount1:iRQpXGzlMRb1A57bkcryX7Bg/3Uf5YOfNCG+XIingJI=", $signedHeaders["Authorization"]);
  61. }
  62. /**
  63. * Test signing for devstore with other path
  64. */
  65. public function testSignForDevstoreWithOtherPath()
  66. {
  67. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedKeyLite(Zend_Service_WindowsAzure_Credentials_SharedKey::DEVSTORE_ACCOUNT, Zend_Service_WindowsAzure_Credentials_SharedKey::DEVSTORE_KEY, true);
  68. $signedHeaders = $credentials->signRequestHeaders(
  69. 'GET',
  70. '/test',
  71. '',
  72. array("x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT"),
  73. false
  74. );
  75. $this->assertType('array', $signedHeaders);
  76. $this->assertEquals(2, count($signedHeaders));
  77. $this->assertEquals("SharedKeyLite devstoreaccount1:MsC5SIbFB4M4UZd83CiMaL8ibUhaS5H9CcJBJpsnWqo=", $signedHeaders["Authorization"]);
  78. }
  79. /**
  80. * Test signing for devstore with query string
  81. */
  82. public function testSignForDevstoreWithQueryString()
  83. {
  84. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedKeyLite(Zend_Service_WindowsAzure_Credentials_SharedKey::DEVSTORE_ACCOUNT, Zend_Service_WindowsAzure_Credentials_SharedKey::DEVSTORE_KEY, true);
  85. $signedHeaders = $credentials->signRequestHeaders(
  86. 'GET',
  87. '/',
  88. '?test=true',
  89. array("x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT"),
  90. false
  91. );
  92. $this->assertType('array', $signedHeaders);
  93. $this->assertEquals(2, count($signedHeaders));
  94. $this->assertEquals("SharedKeyLite devstoreaccount1:iRQpXGzlMRb1A57bkcryX7Bg/3Uf5YOfNCG+XIingJI=", $signedHeaders["Authorization"]);
  95. }
  96. /**
  97. * Test signing for production with root path
  98. */
  99. public function testSignForProductionWithRootPath()
  100. {
  101. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedKeyLite('testing', 'abcdefg');
  102. $signedHeaders = $credentials->signRequestHeaders(
  103. 'GET',
  104. '/',
  105. '',
  106. array("x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT"),
  107. false
  108. );
  109. $this->assertType('array', $signedHeaders);
  110. $this->assertEquals(2, count($signedHeaders));
  111. $this->assertEquals("SharedKeyLite testing:vZdOn/j0gW5FG0kAUG9NhSBO9eBjZqfe6RwALPYUtqU=", $signedHeaders["Authorization"]);
  112. }
  113. /**
  114. * Test signing for production with other path
  115. */
  116. public function testSignForProductionWithOtherPath()
  117. {
  118. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedKeyLite('testing', 'abcdefg');
  119. $signedHeaders = $credentials->signRequestHeaders(
  120. 'GET',
  121. '/test',
  122. '',
  123. array("x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT"),
  124. false
  125. );
  126. $this->assertType('array', $signedHeaders);
  127. $this->assertEquals(2, count($signedHeaders));
  128. $this->assertEquals("SharedKeyLite testing:HJTSiRDtMsQVsFVispSHkcODeFykLO+WEuOepwmh51o=", $signedHeaders["Authorization"]);
  129. }
  130. /**
  131. * Test signing for production with query string
  132. */
  133. public function testSignForProductionWithQueryString()
  134. {
  135. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedKeyLite('testing', 'abcdefg');
  136. $signedHeaders = $credentials->signRequestHeaders(
  137. 'GET',
  138. '/',
  139. '?test=true',
  140. array("x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT"),
  141. false
  142. );
  143. $this->assertType('array', $signedHeaders);
  144. $this->assertEquals(2, count($signedHeaders));
  145. $this->assertEquals("SharedKeyLite testing:vZdOn/j0gW5FG0kAUG9NhSBO9eBjZqfe6RwALPYUtqU=", $signedHeaders["Authorization"]);
  146. }
  147. }
  148. // Call Zend_Service_WindowsAzure_Credentials_SharedKeyLiteTest::main() if this source file is executed directly.
  149. if (PHPUnit_MAIN_METHOD == "Zend_Service_WindowsAzure_Credentials_SharedKeyLiteTest::main") {
  150. Zend_Service_WindowsAzure_Credentials_SharedKeyLiteTest::main();
  151. }