SharedAccessSignatureTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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$
  19. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. /** Zend_Service_WindowsAzure_Credentials_SharedAccessSignature */
  23. require_once 'Zend/Service/WindowsAzure/Credentials/SharedAccessSignature.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Service_WindowsAzure
  27. * @subpackage UnitTests
  28. * @version $Id$
  29. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Service_WindowsAzure_Credentials_SharedAccessSignatureTest extends PHPUnit_Framework_TestCase
  33. {
  34. /**
  35. * Test signing a container
  36. */
  37. public function testGenerateSignatureContainer()
  38. {
  39. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedAccessSignature('myaccount', 'WXuEUKMijV/pxUu5/RhDn1bYRuFlLSbmLUJJWRqYQ/uxbMpEx+7S/jo9sT3ZIkEucZGbEafDuxD1kwFOXf3xyw==', false);
  40. $result = $credentials->createSignature(
  41. 'pictures',
  42. 'c',
  43. 'r',
  44. '2009-02-09',
  45. '2009-02-10',
  46. 'YWJjZGVmZw=='
  47. );
  48. $this->assertEquals('TEfqYYiY9Qrb7fH7nhiRCP9o5BzfO/VL8oYgfVpUl6s=', $result);
  49. }
  50. /**
  51. * Test signing a blob
  52. */
  53. public function testGenerateSignatureBlob()
  54. {
  55. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedAccessSignature('myaccount', 'WXuEUKMijV/pxUu5/RhDn1bYRuFlLSbmLUJJWRqYQ/uxbMpEx+7S/jo9sT3ZIkEucZGbEafDuxD1kwFOXf3xyw==', false);
  56. $result = $credentials->createSignature(
  57. 'pictures/blob.txt',
  58. 'b',
  59. 'r',
  60. '2009-08-14T11:03:40Z',
  61. '2009-08-14T11:53:40Z'
  62. );
  63. $this->assertEquals('hk78uZGGWd8B2NYoBwKSPs5gen3xYqsd3DPO8BQhgTU=', $result);
  64. }
  65. /**
  66. * Test container signed query string
  67. */
  68. public function testContainerSignedQueryString()
  69. {
  70. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedAccessSignature('myaccount', '', false);
  71. $result = $credentials->createSignedQueryString(
  72. 'pictures',
  73. '',
  74. 'c',
  75. 'r',
  76. '2009-02-09',
  77. '2009-02-10',
  78. 'YWJjZGVmZw=='
  79. );
  80. $this->assertEquals('st=2009-02-09&se=2009-02-10&sr=c&sp=r&si=YWJjZGVmZw%3D%3D&sig=iLe%2BC%2Be85l8%2BMneC9psdTCg7hJxKh314aRq3SnqPuyM%3D', $result);
  81. }
  82. /**
  83. * Test blob signed query string
  84. */
  85. public function testBlobSignedQueryString()
  86. {
  87. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedAccessSignature('myaccount', '', false);
  88. $result = $credentials->createSignedQueryString(
  89. 'pictures/blob.txt',
  90. '',
  91. 'b',
  92. 'w',
  93. '2009-02-09',
  94. '2009-02-10'
  95. );
  96. $this->assertEquals('st=2009-02-09&se=2009-02-10&sr=b&sp=w&sig=MUrHltHOJkj4425gorWWKr%2FO6mHC3XeRQ2MD6jn8jI8%3D', $result);
  97. }
  98. /**
  99. * Test sign request URL
  100. */
  101. public function testSignRequestUrl()
  102. {
  103. $credentials = new Zend_Service_WindowsAzure_Credentials_SharedAccessSignature('myaccount', '', false);
  104. $queryString = $credentials->createSignedQueryString('pictures/blob.txt', '', 'b', 'r', '2009-02-09', '2009-02-10');
  105. $credentials->setPermissionSet(array(
  106. 'http://blob.core.windows.net/myaccount/pictures/blob.txt?' . $queryString
  107. ));
  108. $requestUrl = 'http://blob.core.windows.net/myaccount/pictures/blob.txt?comp=metadata';
  109. $result = $credentials->signRequestUrl($requestUrl, Zend_Service_WindowsAzure_Storage::RESOURCE_BLOB);
  110. $this->assertEquals('http://blob.core.windows.net/myaccount/pictures/blob.txt?comp=metadata&' . $queryString, $result);
  111. }
  112. }