Esempio n. 1
0
    def _sign(self, instant, credentials, service, region, request):
        """
        Sign this query using its built in credentials.

        @param instant: The time to sign into the request.
        @type instant: L{datetime.datetime}

        @param credentials: The credentials to use to sign the request.
        @type credentials: L{AWSCredentials}

        @param service: The AWS service name the request is for.
        @type service: L{bytes}

        @param region: The AWS region name the request is for.
        @type region: L{bytes}

        @param request: The request to sign.
        @type request: L{_CanonicalRequest}

        @return: A value for the I{Authorization} header of the
            request.
        @rtype: L{bytes}
        """
        return _auth_v4._make_authorization_header(
            region=region,
            service=service,
            canonical_request=request,
            credentials=credentials,
            instant=instant,
        )
Esempio n. 2
0
    def sign(self, headers, data, url_context, instant, method,
             region=REGION_US_EAST_1):
        """Sign this query using its built in credentials."""
        headers["host"] = url_context.get_encoded_host()

        if data is None:
            request = _auth_v4._CanonicalRequest.from_request_components(
                method=method,
                url=url_context.get_encoded_path(),
                headers=headers,
                headers_to_sign=('host', 'x-amz-date'),
                payload_hash=None,
            )
        else:
            request = _auth_v4._CanonicalRequest.from_request_components_and_payload(
                method=method,
                url=url_context.get_encoded_path(),
                headers=headers,
                headers_to_sign=('host', 'x-amz-date'),
                payload=data,
            )

        return _auth_v4._make_authorization_header(
            region=region,
            service="s3",
            canonical_request=request,
            credentials=self.creds,
            instant=instant)
Esempio n. 3
0
    def sign(self, headers, data, url_context, instant, method,
             region=REGION_US_EAST_1):
        """Sign this query using its built in credentials."""
        headers["host"] = url_context.get_encoded_host()

        if data is None:
            request = _auth_v4._CanonicalRequest.from_request_components(
                method=method,
                url=url_context.get_encoded_path(),
                headers=headers,
                headers_to_sign=('host', 'x-amz-date'),
                payload_hash=None,
            )
        else:
            request = _auth_v4._CanonicalRequest.from_request_components_and_payload(
                method=method,
                url=url_context.get_encoded_path(),
                headers=headers,
                headers_to_sign=('host', 'x-amz-date'),
                payload=data,
            )

        return _auth_v4._make_authorization_header(
            region=region,
            service="s3",
            canonical_request=request,
            credentials=self.creds,
            instant=instant)
Esempio n. 4
0
    def _sign(self, instant, credentials, service, region, request):
        """
        Sign this query using its built in credentials.

        @param instant: The time to sign into the request.
        @type instant: L{datetime.datetime}

        @param credentials: The credentials to use to sign the request.
        @type credentials: L{AWSCredentials}

        @param service: The AWS service name the request is for.
        @type service: L{bytes}

        @param region: The AWS region name the request is for.
        @type region: L{bytes}

        @param request: The request to sign.
        @type request: L{_CanonicalRequest}

        @return: A value for the I{Authorization} header of the
            request.
        @rtype: L{bytes}
        """
        return _auth_v4._make_authorization_header(
            region=region,
            service=service,
            canonical_request=request,
            credentials=credentials,
            instant=instant,
        )
Esempio n. 5
0
    def test_value(self):
        """
        An authorization header string is generated from the headers,
        payload, and current time.
        """
        header_value = _make_authorization_header(self.region, self.service,
                                                  self.request,
                                                  self.credentials,
                                                  self.instant)
        expected = (
            'AWS4-HMAC-SHA256 '
            'Credential=access key/20161111/us-east-1/dynamodb/aws4_request, '
            'SignedHeaders=content-type;host;x-amz-date;x-amz-target, '
            'Signature=bf627437be9417f488eacc5c2bb0636229c80af5ed3c45d6e40688f'
            '3cdcf4247')

        self.assertEqual(header_value, expected)
Esempio n. 6
0
    def _test_authorization(self, path, canonical_request):
        """
        Extract an AWS authorization fixture from C{path} and compare
        it to the value returned from L{_make_authorization_header},
        constructed from the provided canonical request.
        """

        authorization_path = self._globOne(path, '*.authz')

        with authorization_path.open() as f:
            expected_authorization = f.read()

        signed = _make_authorization_header(self.region, self.service,
                                            canonical_request,
                                            self.credentials, self.instant)

        self.assertEqual(signed, expected_authorization)
Esempio n. 7
0
    def test_value(self):
        """
        An authorization header string is generated from the headers,
        payload, and current time.
        """
        header_value = _make_authorization_header(self.region,
                                                  self.service,
                                                  self.request,
                                                  self.credentials,
                                                  self.instant)
        expected = (
            'AWS4-HMAC-SHA256 '
            'Credential=access key/20161111/us-east-1/dynamodb/aws4_request, '
            'SignedHeaders=content-type;host;x-amz-date;x-amz-target, '
            'Signature=bf627437be9417f488eacc5c2bb0636229c80af5ed3c45d6e40688f'
            '3cdcf4247'
        )

        self.assertEqual(header_value, expected)