Exemplo n.º 1
0
 public function testConstructStringToSign()
 {
     $http_method = "GET";
     $headers = NULL;
     $uri = "/fds/bucket/test.txt?uploads&uploadId=xx&partNumber=1";
     // No headers
     $this->assertEquals($http_method . "\n" . "\n" . "\n" . "\n" . "" . "/fds/bucket/test.txt?partNumber=1&uploadId=xx&uploads", Signer::constructStringToSign($http_method, $uri, $headers));
     // Normal headers
     $headers = array();
     $headers[Common::CONTENT_TYPE] = "application/json";
     $headers[Common::CONTENT_MD5] = "123131331313231";
     $headers[Common::DATE] = "Tue, 27 Mar 2007 21:20:26+0000";
     $this->assertEquals($http_method . "\n" . $headers[Common::CONTENT_MD5] . "\n" . $headers[Common::CONTENT_TYPE] . "\n" . $headers[Common::DATE] . "\n" . "" . "/fds/bucket/test.txt?partNumber=1&uploadId=xx&uploads", Signer::constructStringToSign($http_method, $uri, $headers));
     // Xiaomi date overrides default 'Date'
     $headers[Common::XIAOMI_HEADER_PREFIX . "date"] = "Tue, 28 Mar 2007 21:20:26+0000";
     $this->assertEquals($http_method . "\n" . $headers[Common::CONTENT_MD5] . "\n" . $headers[Common::CONTENT_TYPE] . "\n" . "\n" . Common::XIAOMI_HEADER_PREFIX . "date:Tue, 28 Mar 2007 21:20:26+0000\n" . "/fds/bucket/test.txt?partNumber=1&uploadId=xx&uploads", Signer::constructStringToSign($http_method, $uri, $headers));
     // Pre-signed uri
     $uri = "/fds/bucket/test.txt?GalaxyAccessKeyId=AKIAIOSFODNN7EXAMPLE" . "&Expires=1141889120&Signature=vjbyPxybdZaNmGa%2ByT272YEAiv4%3D";
     $this->assertEquals($http_method . "\n" . $headers[Common::CONTENT_MD5] . "\n" . $headers[Common::CONTENT_TYPE] . "\n" . "1141889120\n" . Common::XIAOMI_HEADER_PREFIX . "date:Tue, 28 Mar 2007 21:20:26+0000\n" . "/fds/bucket/test.txt", Signer::constructStringToSign($http_method, $uri, $headers));
 }
Exemplo n.º 2
0
 private function parseObjectMetadataFromHeaders($headers)
 {
     $metadata = new FDSObjectMetadata();
     foreach (FDSObjectMetadata::$PRE_DEFINED_METADATA as $value) {
         if (array_key_exists($value, $headers)) {
             $metadata->addHeader($value, $headers[$value]);
         }
     }
     foreach ($headers as $key => $value) {
         if (Signer::stringStartsWith($key, FDSObjectMetadata::USER_DEFINED_METADATA_PREFIX)) {
             $metadata->addUserMetadata($key, $value);
         }
     }
     return $metadata;
 }
Exemplo n.º 3
0
    }
    static function getHeaderValue($headers, $name)
    {
        if ($headers != NULL && array_key_exists($name, $headers)) {
            if (is_array($headers[$name])) {
                return $headers[$name][0];
            } else {
                return $headers[$name];
            }
        }
        return "";
    }
    static function getExpires($uri)
    {
        $query = parse_url($uri, PHP_URL_QUERY);
        if ($query != NULL and !empty($query)) {
            $params = array();
            parse_str($query, $params);
            if (array_key_exists(Common::EXPIRES, $params)) {
                return intval($params[Common::EXPIRES]);
            }
        }
        return 0;
    }
    static function stringStartsWith($haystack, $needle)
    {
        return $needle == "" || strpos($haystack, $needle) === 0;
    }
}
Signer::$s_sub_resources = SubResource::getAllSubresources();