Exemple #1
0
    def _get_s3_auth_signature(self, params, headers):
        """Hacky wrapper to work with S3's get_auth_signature."""
        headers_copy = {}
        params_copy = copy.deepcopy(params)

        # Lowercase all headers except 'date' and Google header values
        for k, v in headers.items():
            k_lower = k.lower()
            # NOTE: It's important that the value of Content-Type header is
            # left as is and not lowercased
            if (
                k_lower in ["date", "content-type"]
                or k_lower.startswith(GoogleStorageDriver.http_vendor_prefix)
                or not isinstance(v, str)
            ):
                headers_copy[k_lower] = v
            else:
                headers_copy[k_lower] = v.lower()

        return BaseS3Connection.get_auth_signature(
            method=self.method,
            headers=headers_copy,
            params=params_copy,
            expires=None,
            secret_key=self.key,
            path=self.action,
            vendor_prefix=GoogleStorageDriver.http_vendor_prefix,
        )
Exemple #2
0
 def test_signature(self):
     secret_key = 'ssssh!'
     sig = BaseS3Connection.get_auth_signature(
         method='GET',
         headers={'foo': 'bar',
                  'content-type': 'TYPE!',
                  'x-aws-test': 'test_value'},
         params={'hello': 'world'},
         expires=None,
         secret_key=secret_key,
         path='/',
         vendor_prefix='x-aws'
     )
     string_to_sign = 'GET\n\nTYPE!\n\nx-aws-test:test_value\n/'
     b64_hmac = base64.b64encode(
         hmac.new(b(secret_key), b(string_to_sign), digestmod=sha1).digest()
     )
     expected_sig = b64_hmac.decode('utf-8')
     self.assertEqual(sig, expected_sig)
Exemple #3
0
 def test_signature(self):
     secret_key = 'ssssh!'
     sig = BaseS3Connection.get_auth_signature(
         method='GET',
         headers={'foo': 'bar',
                  'content-type': 'TYPE!',
                  'x-aws-test': 'test_value'},
         params={'hello': 'world'},
         expires=None,
         secret_key=secret_key,
         path='/',
         vendor_prefix='x-aws'
     )
     string_to_sign = 'GET\n\nTYPE!\n\nx-aws-test:test_value\n/'
     b64_hmac = base64.b64encode(
         hmac.new(b(secret_key), b(string_to_sign), digestmod=sha1).digest()
     )
     expected_sig = b64_hmac.decode('utf-8')
     self.assertEqual(sig, expected_sig)
    def _get_s3_auth_signature(self, params, headers):
        """Hacky wrapper to work with S3's get_auth_signature."""
        headers_copy = {}
        params_copy = copy.deepcopy(params)

        # Lowercase all headers except 'date' and Google header values
        for k, v in headers.items():
            k_lower = k.lower()
            if (k_lower == 'date' or k_lower.startswith(
                    GoogleStorageDriver.http_vendor_prefix) or
                    not isinstance(v, str)):
                headers_copy[k_lower] = v
            else:
                headers_copy[k_lower] = v.lower()

        return BaseS3Connection.get_auth_signature(
            method=self.method,
            headers=headers_copy,
            params=params_copy,
            expires=None,
            secret_key=self.key,
            path=self.action,
            vendor_prefix=GoogleStorageDriver.http_vendor_prefix)