Skip to content

Commit

Permalink
Service\Amazon: Authentication S3 tests ported
Browse files Browse the repository at this point in the history
  • Loading branch information
farazdagi committed Oct 29, 2010
1 parent d587193 commit 9f510cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion library/Zend/Service/Amazon/Authentication/S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function generateSignature($method, $path, &$headers)
$sig_str .= '?torrent';
}

$signature = base64_encode(Crypt\HMAC::compute($this->_secretKey, 'sha1', utf8_encode($sig_str), Crypt\HMAC::BINARY));
$signature = base64_encode(Crypt\Hmac::compute($this->_secretKey, 'sha1', utf8_encode($sig_str), Crypt\Hmac::BINARY));
$headers['Authorization'] = 'AWS ' . $this->_accessKey . ':' . $signature;

return $sig_str;
Expand Down
31 changes: 17 additions & 14 deletions tests/Zend/Service/Amazon/Authentication/S3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
* @version $Id: AllTests.php 11973 2008-10-15 16:00:56Z matthew $
*/

require_once dirname(__FILE__) . '/../../../../TestHelper.php';
/**
* @namespace
*/
namespace ZendTest\Service\Amazon\Authentication;

require_once 'Zend/Service/Amazon/Authentication/S3.php';
use Zend\Service\Amazon\Authentication,
Zend\Service\Amazon\Authentication\Exception;

/**
* S3 authentication test case
Expand All @@ -33,13 +37,13 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Service_Amazon_Authentication_S3Test extends PHPUnit_Framework_TestCase
class S3Test extends \PHPUnit_Framework_TestCase
{

/**
* @var Zend_Service_Amazon_Authentication_S3
* @var Zend\Service\Amazon\Authentication\S3
*/
private $Zend_Service_Amazon_Authentication_S3;
private $_amazon;

/**
* Prepares the environment before running a test.
Expand All @@ -51,7 +55,7 @@ protected function setUp()
// TODO Auto-generated Zend_Service_Amazon_Authentication_S3Test::setUp()


$this->Zend_Service_Amazon_Authentication_S3 = new Zend_Service_Amazon_Authentication_S3('0PN5J17HBGZHT7JJ3X82', 'uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o', '2006-03-01');
$this->_amazon = new Authentication\S3('0PN5J17HBGZHT7JJ3X82', 'uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o', '2006-03-01');

}

Expand All @@ -61,9 +65,8 @@ protected function setUp()
protected function tearDown()
{
// TODO Auto-generated Zend_Service_Amazon_Authentication_S3Test::tearDown()


$this->Zend_Service_Amazon_Authentication_S3 = null;
$this->_amazon = null;

parent::tearDown();
}
Expand All @@ -74,7 +77,7 @@ public function testGetGeneratesCorrectSignature()
$headers = array();
$headers['Date'] = "Tue, 27 Mar 2007 19:36:42 +0000";

$ret = $this->Zend_Service_Amazon_Authentication_S3->generateSignature('GET', 'http://s3.amazonaws.com/johnsmith/photos/puppy.jpg', $headers);
$ret = $this->_amazon->generateSignature('GET', 'http://s3.amazonaws.com/johnsmith/photos/puppy.jpg', $headers);

$this->assertEquals('AWS 0PN5J17HBGZHT7JJ3X82:soqB4L9flQ6AHG4d5FVnKj26D2s=', $headers['Authorization']);
$this->assertEquals($ret, "GET
Expand All @@ -91,7 +94,7 @@ public function testPutGeneratesCorrectSignature()
$headers['Content-Type'] = "image/jpeg";
$headers['Content-Length'] = 94328;

$ret = $this->Zend_Service_Amazon_Authentication_S3->generateSignature('PUT', 'http://s3.amazonaws.com/johnsmith/photos/puppy.jpg', $headers);
$ret = $this->_amazon->generateSignature('PUT', 'http://s3.amazonaws.com/johnsmith/photos/puppy.jpg', $headers);

$this->assertEquals('AWS 0PN5J17HBGZHT7JJ3X82:88cf7BdpjrBlCsIiWWLn8wLpWzI=', $headers['Authorization']);
$this->assertEquals($ret, "PUT
Expand All @@ -106,7 +109,7 @@ public function testListGeneratesCorrectSignature()
$headers = array();
$headers['Date'] = "Tue, 27 Mar 2007 19:42:41 +0000";

$ret = $this->Zend_Service_Amazon_Authentication_S3->generateSignature('GET', 'http://s3.amazonaws.com/johnsmith/?prefix=photos&max-keys=50&marker=puppy', $headers);
$ret = $this->_amazon->generateSignature('GET', 'http://s3.amazonaws.com/johnsmith/?prefix=photos&max-keys=50&marker=puppy', $headers);

$this->assertEquals('AWS 0PN5J17HBGZHT7JJ3X82:pm3Adv2BIFCCJiUSikcLcGYFtiA=', $headers['Authorization']);
$this->assertEquals($ret, "GET
Expand All @@ -121,7 +124,7 @@ public function testFetchGeneratesCorrectSignature()
$headers = array();
$headers['Date'] = "Tue, 27 Mar 2007 19:44:46 +0000";

$ret = $this->Zend_Service_Amazon_Authentication_S3->generateSignature('GET', 'http://s3.amazonaws.com/johnsmith/?acl', $headers);
$ret = $this->_amazon->generateSignature('GET', 'http://s3.amazonaws.com/johnsmith/?acl', $headers);

$this->assertEquals('AWS 0PN5J17HBGZHT7JJ3X82:TCNlZPuxY41veihZbxjnjw8P93w=', $headers['Authorization']);
$this->assertEquals($ret, "GET
Expand All @@ -137,7 +140,7 @@ public function testDeleteGeneratesCorrectSignature()
$headers = array();
$headers['x-amz-date'] = "Tue, 27 Mar 2007 21:20:26 +0000";

$ret = $this->Zend_Service_Amazon_Authentication_S3->generateSignature('DELETE', 'http://s3.amazonaws.com/johnsmith/photos/puppy.jpg', $headers);
$ret = $this->_amazon->generateSignature('DELETE', 'http://s3.amazonaws.com/johnsmith/photos/puppy.jpg', $headers);

$this->assertEquals('AWS 0PN5J17HBGZHT7JJ3X82:O9AsSXUIowhjTiJC5escAqjsAyk=', $headers['Authorization']);
$this->assertEquals($ret, "DELETE
Expand All @@ -164,7 +167,7 @@ public function testUploadGeneratesCorrectSignature()
$headers['Content-Length'] = "5913339";


$ret = $this->Zend_Service_Amazon_Authentication_S3->generateSignature('PUT', 'http://s3.amazonaws.com/static.johnsmith.net/db-backup.dat.gz', $headers);
$ret = $this->_amazon->generateSignature('PUT', 'http://s3.amazonaws.com/static.johnsmith.net/db-backup.dat.gz', $headers);

$this->assertEquals('AWS 0PN5J17HBGZHT7JJ3X82:IQh2zwCpX2xqRgP2rbIkXL/GVbA=', $headers['Authorization']);
$this->assertEquals($ret, "PUT
Expand Down

0 comments on commit 9f510cb

Please sign in to comment.