def test_amz1(self):
        """
        Using example data selected from:
        http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html

        """
        req_text = [
            'POST https://iam.amazonaws.com/ HTTP/1.1',
            'Host: iam.amazonaws.com', 'Content-Length: 54',
            'Content-Type: application/x-www-form-urlencoded',
            'X-Amz-Date: 20110909T233600Z', '',
            'Action=ListUsers&Version=2010-05-08'
        ]
        req = request_from_text('\n'.join(req_text))
        AWS4Auth.encode_body(req)
        hsh = hashlib.sha256(req.body)
        req.headers['x-amz-content-sha256'] = hsh.hexdigest()
        include_hdrs = ['host', 'content-type', 'x-amz-date']
        result = AWS4Auth.get_canonical_headers(req, include=include_hdrs)
        cano_headers, signed_headers = result
        expected = [
            'POST', '/', '', 'content-type:application/x-www-form-urlencoded',
            'host:iam.amazonaws.com', 'x-amz-date:20110909T233600Z', '',
            'content-type;host;x-amz-date',
            'b6359072c78d70ebee1e81adcbab4f01bf2c23245fa365ef83fe8f1f95'
            '5085e2'
        ]
        expected = '\n'.join(expected)
        cano_req = AWS4Auth.get_canonical_request(req, cano_headers,
                                                  signed_headers)
        self.assertEqual(cano_req, expected)
 def _test_amz_test_suite_item(self, group_name, group):
     req = request_from_text(group['.req'])
     if 'content-length' in req.headers:
         del req.headers['content-length']
     include_hdrs = list(req.headers)
     AWS4Auth.encode_body(req)
     hsh = hashlib.sha256(req.body or b'')
     req.headers['x-amz-content-sha256'] = hsh.hexdigest()
     result = AWS4Auth.get_canonical_headers(req, include_hdrs)
     cano_headers, signed_headers = result
     cano_req = AWS4Auth.get_canonical_request(req, cano_headers,
                                               signed_headers)
     msg = 'Group: ' + group_name
     self.assertEqual(cano_req, group['.creq'], msg=msg)
 def _test_amz_test_suite_item(self, group_name, group):
     req = request_from_text(group['.req'])
     if 'content-length' in req.headers:
         del req.headers['content-length']
     include_hdrs = list(req.headers)
     AWS4Auth.encode_body(req)
     hsh = hashlib.sha256(req.body or b'')
     req.headers['x-amz-content-sha256'] = hsh.hexdigest()
     result = AWS4Auth.get_canonical_headers(req, include_hdrs)
     cano_headers, signed_headers = result
     cano_req = AWS4Auth.get_canonical_request(req, cano_headers,
                                               signed_headers)
     msg = 'Group: ' + group_name
     self.assertEqual(cano_req, group['.creq'], msg=msg)
    def test_amz1(self):
        """
        Using example data selected from:
        http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html

        """
        req_text = [
            'POST https://iam.amazonaws.com/ HTTP/1.1',
            'Host: iam.amazonaws.com',
            'Content-Length: 54',
            'Content-Type: application/x-www-form-urlencoded',
            'X-Amz-Date: 20110909T233600Z',
            '',
            'Action=ListUsers&Version=2010-05-08']
        req = request_from_text('\n'.join(req_text))
        AWS4Auth.encode_body(req)
        hsh = hashlib.sha256(req.body)
        req.headers['x-amz-content-sha256'] = hsh.hexdigest()
        include_hdrs = ['host', 'content-type', 'x-amz-date']
        result = AWS4Auth.get_canonical_headers(req, include=include_hdrs)
        cano_headers, signed_headers = result
        expected = [
            'POST',
            '/',
            '',
            'content-type:application/x-www-form-urlencoded',
            'host:iam.amazonaws.com',
            'x-amz-date:20110909T233600Z',
            '',
            'content-type;host;x-amz-date',
            'b6359072c78d70ebee1e81adcbab4f01bf2c23245fa365ef83fe8f1f95'
            '5085e2']
        expected = '\n'.join(expected)
        cano_req = AWS4Auth.get_canonical_request(req, cano_headers,
                                                  signed_headers)
        self.assertEqual(cano_req, expected)