Browse Source

ZF-10219: added the ?versions support

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24082 44c647ce-9c0f-0410-b52a-842ac1e357ba
ezimuel 14 years ago
parent
commit
9dc56696d3
2 changed files with 23 additions and 10 deletions
  1. 8 6
      library/Zend/Service/Amazon/S3.php
  2. 15 4
      tests/Zend/Service/Amazon/S3/OnlineTest.php

+ 8 - 6
library/Zend/Service/Amazon/S3.php

@@ -162,8 +162,7 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
             $data = '<CreateBucketConfiguration><LocationConstraint>'.$location.'</LocationConstraint></CreateBucketConfiguration>';
             $headers['Content-type']= 'text/plain';
             $headers['Contne-size']= strlen($data);
-        }
-        else {
+        } else {
             $data = null;
         }
         $response = $this->_makeRequest('PUT', $bucket, null, $headers, $data);
@@ -611,16 +610,16 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
                 $path = $parts[0].'/';
             }
         }
-
         self::addSignature($method, $path, $headers);
 
         $client = self::getHttpClient();
 
-        $client->resetParameters();
+        $client->resetParameters(true);
         $client->setUri($endpoint);
         $client->setAuth(false);
         // Work around buglet in HTTP client - it doesn't clean headers
         // Remove when ZHC is fixed
+        /*
         $client->setHeaders(array('Content-MD5'              => null,
                                   'Content-Encoding'         => null,
                                   'Expect'                   => null,
@@ -628,7 +627,7 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
                                   'x-amz-acl'                => null,
                                   'x-amz-copy-source'        => null,
                                   'x-amz-metadata-directive' => null));
-
+        */
         $client->setHeaders($headers);
 
         if (is_array($params)) {
@@ -642,7 +641,7 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
                  $headers['Content-type'] = self::getMimeType($path);
              }
              $client->setRawData($data, $headers['Content-type']);
-         }
+         } 
          do {
             $retry = false;
 
@@ -733,6 +732,9 @@ class Zend_Service_Amazon_S3 extends Zend_Service_Amazon_Abstract
         else if (strpos($path, '?torrent') !== false) {
             $sig_str .= '?torrent';
         }
+        else if (strpos($path, '?versions') !== false) {
+            $sig_str .= '?versions';
+        }
 
         $signature = base64_encode(Zend_Crypt_Hmac::compute($this->_getSecretKey(), 'sha1', utf8_encode($sig_str), Zend_Crypt_Hmac::BINARY));
         $headers['Authorization'] = 'AWS '.$this->_getAccessKey().':'.$signature;

+ 15 - 4
tests/Zend/Service/Amazon/S3/OnlineTest.php

@@ -71,7 +71,7 @@ class Zend_Service_Amazon_S3_OnlineTest extends PHPUnit_Framework_TestCase
         $this->_httpClientAdapterSocket = new Zend_Http_Client_Adapter_Socket();
 
         $this->_bucket = constant('TESTS_ZEND_SERVICE_AMAZON_S3_BUCKET');
-        $this->_bucketEu = $this->_bucket.'-EU';
+        $this->_bucketEu = $this->_bucket.'-eu';
 
         $this->_amazon->getHttpClient()
                       ->setAdapter($this->_httpClientAdapterSocket);
@@ -400,6 +400,8 @@ class Zend_Service_Amazon_S3_OnlineTest extends PHPUnit_Framework_TestCase
         $this->assertTrue($this->_amazon->isBucketAvailable($this->_bucketEu));
         $list = $this->_amazon->getBuckets();
         $this->assertContains($this->_bucketEu, $list);
+        $this->_amazon->cleanBucket($this->_bucketEu);
+        $this->_amazon->removeBucket($this->_bucketEu);
     }
     /**
      * Test bucket name with /'s and encoding
@@ -483,14 +485,23 @@ class Zend_Service_Amazon_S3_OnlineTest extends PHPUnit_Framework_TestCase
         $this->_amazon->removeObject("testgetobjectparams1/zftest2", "testdata");
         $this->_amazon->removeBucket("testgetobjectparams1");
     }
-
+    /**
+     * @see ZF-10219
+     */
+    public function testVersionBucket()
+    {
+        $this->_amazon->createBucket($this->_bucket);
+        $response= $this->_amazon->_makeRequest('GET', $this->_bucket.'/?versions', array('versions'=>''));
+        $this->assertNotNull($response,'The response for the ?versions is empty');
+        $xml = new SimpleXMLElement($response->getBody());
+        $this->assertEquals((string) $xml->Name,$this->_bucket,'The bucket name in XML response is not valid');
+    }
     public function tearDown()
     {
         unset($this->_amazon->debug);
         $this->_amazon->cleanBucket($this->_bucket);
         $this->_amazon->removeBucket($this->_bucket);
-        $this->_amazon->cleanBucket($this->_bucketEu);
-        $this->_amazon->removeBucket($this->_bucketEu);
+        sleep(1);
     }
 }