SharedKeyLiteTest.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Service_WindowsAzure_Credentials_SharedKeyLiteTest::main');
  24. }
  25. /**
  26. * Test helpers
  27. */
  28. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  29. require_once dirname(__FILE__) . '/../../../../TestConfiguration.php.dist';
  30. require_once 'PHPUnit/Framework/TestCase.php';
  31. /** Zend_Service_WindowsAzure_Credentials_SharedKeyLite */
  32. require_once 'Zend/Service/WindowsAzure/Credentials/SharedKeyLite.php';
  33. /** Zend_Service_WindowsAzure_Credentials_SharedKey */
  34. require_once 'Zend/Service/WindowsAzure/Credentials/SharedKey.php';
  35. /**
  36. * @category Zend
  37. * @package Zend_Service_WindowsAzure
  38. * @subpackage UnitTests
  39. * @version $Id: Credentials_SharedKeyTest.php 14561 2009-05-07 08:05:12Z unknown $
  40. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  41. * @license http://framework.zend.com/license/new-bsd New BSD License
  42. */
  43. class Zend_Service_WindowsAzure_Credentials_SharedKeyLiteTest extends PHPUnit_Framework_TestCase
  44. {
  45. public static function main()
  46. {
  47. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  48. $result = PHPUnit_TextUI_TestRunner::run($suite);
  49. }
  50. /**
  51. * Test signing for devstore with root path
  52. */
  53. public function testSignForDevstoreWithRootPath()
  54. {
  55. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedKeyLite(Zend_Service_WindowsAzure_Credentials_SharedKey::DEVSTORE_ACCOUNT, Zend_Service_WindowsAzure_Credentials_SharedKey::DEVSTORE_KEY, true);
  56. $signedHeaders = $credentials->signRequestHeaders(
  57. 'GET',
  58. '/',
  59. '',
  60. array("x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT"),
  61. false
  62. );
  63. $this->assertType('array', $signedHeaders);
  64. $this->assertEquals(2, count($signedHeaders));
  65. $this->assertEquals("SharedKeyLite devstoreaccount1:iRQpXGzlMRb1A57bkcryX7Bg/3Uf5YOfNCG+XIingJI=", $signedHeaders["Authorization"]);
  66. }
  67. /**
  68. * Test signing for devstore with other path
  69. */
  70. public function testSignForDevstoreWithOtherPath()
  71. {
  72. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedKeyLite(Zend_Service_WindowsAzure_Credentials_SharedKey::DEVSTORE_ACCOUNT, Zend_Service_WindowsAzure_Credentials_SharedKey::DEVSTORE_KEY, true);
  73. $signedHeaders = $credentials->signRequestHeaders(
  74. 'GET',
  75. '/test',
  76. '',
  77. array("x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT"),
  78. false
  79. );
  80. $this->assertType('array', $signedHeaders);
  81. $this->assertEquals(2, count($signedHeaders));
  82. $this->assertEquals("SharedKeyLite devstoreaccount1:MsC5SIbFB4M4UZd83CiMaL8ibUhaS5H9CcJBJpsnWqo=", $signedHeaders["Authorization"]);
  83. }
  84. /**
  85. * Test signing for devstore with query string
  86. */
  87. public function testSignForDevstoreWithQueryString()
  88. {
  89. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedKeyLite(Zend_Service_WindowsAzure_Credentials_SharedKey::DEVSTORE_ACCOUNT, Zend_Service_WindowsAzure_Credentials_SharedKey::DEVSTORE_KEY, true);
  90. $signedHeaders = $credentials->signRequestHeaders(
  91. 'GET',
  92. '/',
  93. '?test=true',
  94. array("x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT"),
  95. false
  96. );
  97. $this->assertType('array', $signedHeaders);
  98. $this->assertEquals(2, count($signedHeaders));
  99. $this->assertEquals("SharedKeyLite devstoreaccount1:iRQpXGzlMRb1A57bkcryX7Bg/3Uf5YOfNCG+XIingJI=", $signedHeaders["Authorization"]);
  100. }
  101. /**
  102. * Test signing for production with root path
  103. */
  104. public function testSignForProductionWithRootPath()
  105. {
  106. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedKeyLite('testing', 'abcdefg');
  107. $signedHeaders = $credentials->signRequestHeaders(
  108. 'GET',
  109. '/',
  110. '',
  111. array("x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT"),
  112. false
  113. );
  114. $this->assertType('array', $signedHeaders);
  115. $this->assertEquals(2, count($signedHeaders));
  116. $this->assertEquals("SharedKeyLite testing:vZdOn/j0gW5FG0kAUG9NhSBO9eBjZqfe6RwALPYUtqU=", $signedHeaders["Authorization"]);
  117. }
  118. /**
  119. * Test signing for production with other path
  120. */
  121. public function testSignForProductionWithOtherPath()
  122. {
  123. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedKeyLite('testing', 'abcdefg');
  124. $signedHeaders = $credentials->signRequestHeaders(
  125. 'GET',
  126. '/test',
  127. '',
  128. array("x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT"),
  129. false
  130. );
  131. $this->assertType('array', $signedHeaders);
  132. $this->assertEquals(2, count($signedHeaders));
  133. $this->assertEquals("SharedKeyLite testing:HJTSiRDtMsQVsFVispSHkcODeFykLO+WEuOepwmh51o=", $signedHeaders["Authorization"]);
  134. }
  135. /**
  136. * Test signing for production with query string
  137. */
  138. public function testSignForProductionWithQueryString()
  139. {
  140. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedKeyLite('testing', 'abcdefg');
  141. $signedHeaders = $credentials->signRequestHeaders(
  142. 'GET',
  143. '/',
  144. '?test=true',
  145. array("x-ms-date" => "Wed, 29 Apr 2009 13:12:47 GMT"),
  146. false
  147. );
  148. $this->assertType('array', $signedHeaders);
  149. $this->assertEquals(2, count($signedHeaders));
  150. $this->assertEquals("SharedKeyLite testing:vZdOn/j0gW5FG0kAUG9NhSBO9eBjZqfe6RwALPYUtqU=", $signedHeaders["Authorization"]);
  151. }
  152. }
  153. // Call Zend_Service_WindowsAzure_Credentials_SharedKeyLiteTest::main() if this source file is executed directly.
  154. if (PHPUnit_MAIN_METHOD == "Zend_Service_WindowsAzure_Credentials_SharedKeyLiteTest::main") {
  155. Zend_Service_WindowsAzure_Credentials_SharedKeyLiteTest::main();
  156. }