S3Test.php 6.0 KB

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