S3Test.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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_Amazon_Authentication
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: AllTests.php 11973 2008-10-15 16:00:56Z matthew $
  21. */
  22. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  23. require_once 'Zend/Service/Amazon/Authentication/S3.php';
  24. /**
  25. * S3 authentication test case
  26. *
  27. * @category Zend
  28. * @package Zend_Service_Amazon_Authentication
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Service_Amazon_Authentication_S3Test extends PHPUnit_Framework_TestCase
  34. {
  35. /**
  36. * @var Zend_Service_Amazon_Authentication_S3
  37. */
  38. private $Zend_Service_Amazon_Authentication_S3;
  39. /**
  40. * Prepares the environment before running a test.
  41. */
  42. protected function setUp()
  43. {
  44. parent::setUp();
  45. // TODO Auto-generated Zend_Service_Amazon_Authentication_S3Test::setUp()
  46. $this->Zend_Service_Amazon_Authentication_S3 = new Zend_Service_Amazon_Authentication_S3('0PN5J17HBGZHT7JJ3X82', 'uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o', '2006-03-01');
  47. }
  48. /**
  49. * Cleans up the environment after running a test.
  50. */
  51. protected function tearDown()
  52. {
  53. // TODO Auto-generated Zend_Service_Amazon_Authentication_S3Test::tearDown()
  54. $this->Zend_Service_Amazon_Authentication_S3 = null;
  55. parent::tearDown();
  56. }
  57. public function testGetGeneratesCorrectSignature()
  58. {
  59. $headers = array();
  60. $headers['Date'] = "Tue, 27 Mar 2007 19:36:42 +0000";
  61. $ret = $this->Zend_Service_Amazon_Authentication_S3->generateSignature('GET', 'http://s3.amazonaws.com/johnsmith/photos/puppy.jpg', $headers);
  62. $this->assertEquals('AWS 0PN5J17HBGZHT7JJ3X82:soqB4L9flQ6AHG4d5FVnKj26D2s=', $headers['Authorization']);
  63. $this->assertEquals($ret, "GET
  64. Tue, 27 Mar 2007 19:36:42 +0000
  65. //johnsmith/photos/puppy.jpg");
  66. }
  67. public function testPutGeneratesCorrectSignature()
  68. {
  69. $headers = array();
  70. $headers['Date'] = "Tue, 27 Mar 2007 21:15:45 +0000";
  71. $headers['Content-Type'] = "image/jpeg";
  72. $headers['Content-Length'] = 94328;
  73. $ret = $this->Zend_Service_Amazon_Authentication_S3->generateSignature('PUT', 'http://s3.amazonaws.com/johnsmith/photos/puppy.jpg', $headers);
  74. $this->assertEquals('AWS 0PN5J17HBGZHT7JJ3X82:88cf7BdpjrBlCsIiWWLn8wLpWzI=', $headers['Authorization']);
  75. $this->assertEquals($ret, "PUT
  76. image/jpeg
  77. Tue, 27 Mar 2007 21:15:45 +0000
  78. //johnsmith/photos/puppy.jpg");
  79. }
  80. public function testListGeneratesCorrectSignature()
  81. {
  82. $headers = array();
  83. $headers['Date'] = "Tue, 27 Mar 2007 19:42:41 +0000";
  84. $ret = $this->Zend_Service_Amazon_Authentication_S3->generateSignature('GET', 'http://s3.amazonaws.com/johnsmith/?prefix=photos&max-keys=50&marker=puppy', $headers);
  85. $this->assertEquals('AWS 0PN5J17HBGZHT7JJ3X82:pm3Adv2BIFCCJiUSikcLcGYFtiA=', $headers['Authorization']);
  86. $this->assertEquals($ret, "GET
  87. Tue, 27 Mar 2007 19:42:41 +0000
  88. //johnsmith/");
  89. }
  90. public function testFetchGeneratesCorrectSignature()
  91. {
  92. $headers = array();
  93. $headers['Date'] = "Tue, 27 Mar 2007 19:44:46 +0000";
  94. $ret = $this->Zend_Service_Amazon_Authentication_S3->generateSignature('GET', 'http://s3.amazonaws.com/johnsmith/?acl', $headers);
  95. $this->assertEquals('AWS 0PN5J17HBGZHT7JJ3X82:TCNlZPuxY41veihZbxjnjw8P93w=', $headers['Authorization']);
  96. $this->assertEquals($ret, "GET
  97. Tue, 27 Mar 2007 19:44:46 +0000
  98. //johnsmith/?acl");
  99. }
  100. public function testDeleteGeneratesCorrectSignature()
  101. {
  102. $headers = array();
  103. $headers['x-amz-date'] = "Tue, 27 Mar 2007 21:20:26 +0000";
  104. $ret = $this->Zend_Service_Amazon_Authentication_S3->generateSignature('DELETE', 'http://s3.amazonaws.com/johnsmith/photos/puppy.jpg', $headers);
  105. $this->assertEquals('AWS 0PN5J17HBGZHT7JJ3X82:O9AsSXUIowhjTiJC5escAqjsAyk=', $headers['Authorization']);
  106. $this->assertEquals($ret, "DELETE
  107. x-amz-date:Tue, 27 Mar 2007 21:20:26 +0000
  108. //johnsmith/photos/puppy.jpg");
  109. }
  110. public function testUploadGeneratesCorrectSignature()
  111. {
  112. $headers = array();
  113. $headers['Date'] = "Tue, 27 Mar 2007 21:06:08 +0000";
  114. $headers['x-amz-acl'] = "public-read";
  115. $headers['content-type'] = "application/x-download";
  116. $headers['Content-MD5'] = "4gJE4saaMU4BqNR0kLY+lw==";
  117. $headers['X-Amz-Meta-ReviewedBy'][] = "joe@johnsmith.net";
  118. $headers['X-Amz-Meta-ReviewedBy'][] = "jane@johnsmith.net";
  119. $headers['X-Amz-Meta-FileChecksum'] = "0x02661779";
  120. $headers['X-Amz-Meta-ChecksumAlgorithm'] = "crc32";
  121. $headers['Content-Disposition'] = "attachment; filename=database.dat";
  122. $headers['Content-Encoding'] = "gzip";
  123. $headers['Content-Length'] = "5913339";
  124. $ret = $this->Zend_Service_Amazon_Authentication_S3->generateSignature('PUT', 'http://s3.amazonaws.com/static.johnsmith.net/db-backup.dat.gz', $headers);
  125. $this->assertEquals('AWS 0PN5J17HBGZHT7JJ3X82:IQh2zwCpX2xqRgP2rbIkXL/GVbA=', $headers['Authorization']);
  126. $this->assertEquals($ret, "PUT
  127. 4gJE4saaMU4BqNR0kLY+lw==
  128. application/x-download
  129. Tue, 27 Mar 2007 21:06:08 +0000
  130. x-amz-acl:public-read
  131. x-amz-meta-checksumalgorithm:crc32
  132. x-amz-meta-filechecksum:0x02661779
  133. x-amz-meta-reviewedby:joe@johnsmith.net,jane@johnsmith.net
  134. //static.johnsmith.net/db-backup.dat.gz");
  135. }
  136. }