def test_make_request(self, *args, **kvargs): headers = {} params = { 'method': 'GET', 'service': 'ec2', 'region': 'region', 'uri': 'https://*****:*****@host:123/path/?a=b&c=d', 'headers': headers, 'data': '', 'access_key': '', 'secret_key': '', 'security_token': '', 'data_binary': False } make_request(**params) expected = { 'x-amz-date': '19700101T000000Z', 'Authorization': 'AWS4-HMAC-SHA256 Credential=/19700101/region/ec2/aws4_request, SignedHeaders=host;x-amz-date, Signature=de2b9ea384c10b03314afa10532adac358f8c93e3f3dd5bd724eda24a367a7ef', 'x-amz-content-sha256': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'x-amz-security-token': '' } self.assertEqual(expected, headers) pass
def test_make_request(self, *args, **kvargs): headers = {'host': 'some.other.host.address.com'} params = { 'method': 'GET', 'service': 'ec2', 'region': 'region', 'uri': 'https://*****:*****@host:123/path/?a=b&c=d', 'headers': headers, 'data': '', 'access_key': 'ABC', 'secret_key': 'DEF', 'security_token': 'GHI', 'data_binary': False } make_request(**params) expected = { 'host': 'some.other.host.address.com', 'x-amz-date': '19700101T000000Z', 'x-amz-content-sha256': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'Authorization': 'AWS4-HMAC-SHA256 Credential=ABC/19700101/region/ec2/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token, Signature=9cba1c499417655c170f5018b577b9f89154cf9b9827273df54bfa182e5f4273', 'x-amz-security-token': 'GHI' } self.assertEqual(expected, headers) pass
def test_make_request(self, *args, **kvargs): headers = {} params = { 'method': 'GET', 'service': 'ec2', 'region': 'region', 'uri': 'https://*****:*****@host:123/path/?a=b&c=d', 'headers': headers, 'data': '', 'access_key': 'ABC', 'secret_key': 'DEF', 'security_token': 'GHI', 'data_binary': False } make_request(**params) expected = { 'x-amz-date': '19700101T000000Z', 'x-amz-content-sha256': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'Authorization': 'AWS4-HMAC-SHA256 Credential=ABC/19700101/region/ec2/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token, Signature=e767448ca06e8f3a17548d4193ea29afa759b84f957a71d0a051815f5ebfedfa', 'x-amz-security-token': 'GHI' } self.assertEqual(expected, headers) pass
def test_make_request(self, *args, **kvargs): headers = {} params = { 'method': 'GET', 'service': 'ec2', 'region': 'region', 'uri': 'https://*****:*****@host:123/path/?a=b&c=d', 'headers': headers, 'data': b'C\xcfI\x91\xc1\xd0\tw<\xa8\x13\x06{=\x9b\xb3\x1c\xfcl\xfe\xb9\xb18zS\xf4%i*Q\xc9v', 'access_key': 'ABC', 'secret_key': 'DEF', 'security_token': 'GHI', 'data_binary': True } make_request(**params) expected = { 'x-amz-date': '19700101T000000Z', 'x-amz-content-sha256': '3f514228bd64bbff67daaa80e482aee0e0b0c51891d3a64e4abfa145f4364b99', 'Authorization': 'AWS4-HMAC-SHA256 Credential=ABC/19700101/region/ec2/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token, Signature=edcee42e10d5a4cec5414ebe938edcf292a9a33261809523e2df16281d452c5f', 'x-amz-security-token': 'GHI' } self.assertEqual(expected, headers) pass
def test_make_request(self, *args, **kvargs): headers = {} params = { 'method': 'GET', 'service': 'ec2', 'region': 'region', 'uri': 'https://*****:*****@host:123/path/?a=b&c=d', 'headers': headers, 'data': '', 'access_key': '', 'secret_key': '', 'security_token': '' } make_request(**params) expected = { 'x-amz-date': '19700101T000000Z', 'Authorization': 'AWS4-HMAC-SHA256 Credential=/19700101/region/ec2/aws4_request, SignedHeaders=host;x-amz-date, Signature=cabc851aa1139c804beabf1ae27961845d8f6b10b333a996254369bfc526ba21', 'x-amz-security-token': '' } self.assertEqual(expected, headers) pass
def test_make_request(self, *args, **kvargs): headers = {} params = { 'method': 'GET', 'service': 'ec2', 'region': 'region', 'uri': 'https://*****:*****@host:123/path/?a=b&c=d', 'headers': headers, 'data': b'C\xcfI\x91\xc1\xd0\tw<\xa8\x13\x06{=\x9b\xb3\x1c\xfcl\xfe\xb9\xb18zS\xf4%i*Q\xc9v', 'access_key': '', 'secret_key': '', 'security_token': '', 'data_binary': True } make_request(**params) expected = { 'x-amz-date': '19700101T000000Z', 'Authorization': 'AWS4-HMAC-SHA256 Credential=/19700101/region/ec2/aws4_request, SignedHeaders=host;x-amz-date, Signature=6ebcf316c9bb50bb7b2bbabf128dddde3babbf16badfd31ddc40838e7592d5df', 'x-amz-content-sha256': '3f514228bd64bbff67daaa80e482aee0e0b0c51891d3a64e4abfa145f4364b99', 'x-amz-security-token': '' } self.assertEqual(expected, headers) pass
def test_make_request(self, *args, **kvargs): headers = {} access_key = base64.b64decode('QUtJQUkyNkxPQU5NSlpLNVNQWUE=').decode( "utf-8") secret_key = base64.b64decode( 'ekVQbE9URjU0Mys5M0l6UlNnNEVCOEd4cjFQV2NVa1p0TERWSmY4ag==').decode( "utf-8") params = { 'method': 'GET', 'service': 's3', 'region': 'us-east-1', 'uri': 'https://awscurl-sample-bucket.s3.amazonaws.com/awscurl-sample-file:.txt?a=b', 'headers': headers, 'data': b'C\xcfI\x91\xc1\xd0\tw<\xa8\x13\x06{=\x9b\xb3\x1c\xfcl\xfe\xb9\xb18zS\xf4%i*Q\xc9v', 'access_key': access_key, 'secret_key': secret_key, 'security_token': None, 'data_binary': True } r = make_request(**params) self.assertEqual(r.status_code, 200)
def test_make_request(self, *args, **kvargs): headers = {} params = {'method': 'GET', 'service': 's3', 'region': 'us-east-1', 'uri': 'https://awscurl-sample-bucket.s3.amazonaws.com?a=b', 'headers': headers, 'data': '', 'profile': '', 'access_key': 'AKIAIKDYYMAAECYXKVZQ', 'secret_key': 'PMtMJuWzSGFppCpdyKIOF4L8GSiIHaCRRs8rk/Tg', 'security_token': None} make_request(**params) pass
def test_make_request(self, *args, **kvargs): headers = {} params = { 'method': 'GET', 'service': 'ec2', 'region': 'region', 'uri': 'https://*****:*****@host:123/path/?a=b&c=d', 'headers': headers, 'data': '', 'access_key': '', 'secret_key': '', 'security_token': '', 'data_binary': False, 'verify': False } with pytest.raises(SSLError): make_request(**params) pass
def test_make_request(self, *args, **kvargs): headers = {} params = {'method': 'GET', 'service': 'ec2', 'region': 'region', 'uri': 'https://*****:*****@host:123/path/?a=b&c=d', 'headers': headers, 'data': '', 'profile': '', 'access_key': 'ABC', 'secret_key': 'DEF', 'security_token': 'GHI'} make_request(**params) expected = {'x-amz-date': '19700101T000000Z', 'x-amz-content-sha256': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'Authorization': 'AWS4-HMAC-SHA256 Credential=ABC/19700101/region/ec2/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token, Signature=e767448ca06e8f3a17548d4193ea29afa759b84f957a71d0a051815f5ebfedfa', 'x-amz-security-token': 'GHI'} self.assertEqual(expected, headers) pass
def test_make_request(self, *args, **kvargs): headers = {} params = {'method': 'GET', 'service': 'ec2', 'region': 'region', 'uri': 'https://*****:*****@host:123/path/?a=b&c=d', 'headers': headers, 'data': '', 'profile': '', 'access_key': '', 'secret_key': '', 'security_token': ''} make_request(**params) expected = {'x-amz-date': '19700101T000000Z', 'Authorization': 'AWS4-HMAC-SHA256 Credential=/19700101/region/ec2/aws4_request, SignedHeaders=host;x-amz-date, Signature=de2b9ea384c10b03314afa10532adac358f8c93e3f3dd5bd724eda24a367a7ef', 'x-amz-content-sha256': 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'x-amz-security-token': ''} self.assertEqual(expected, headers) pass
def test_make_request(self, mocked_resp): resp = Response() resp.status_code = 200 resp._content = b'{"file_name": "test.yml", "env": "staging", "hash": "\xe5\xad\x97"}' resp.encoding = 'UTF-8' mocked_resp.return_value = resp headers = {} params = { 'method': 'GET', 'service': 'ec2', 'region': 'region', 'uri': 'https://*****:*****@host:123/path/?a=b&c=d', 'headers': headers, 'data': b'C\xcfI\x91\xc1\xd0\tw<\xa8\x13\x06{=\x9b\xb3\x1c\xfcl\xfe\xb9\xb18zS\xf4%i*Q\xc9v', 'access_key': '', 'secret_key': '', 'security_token': '', 'data_binary': True } r = make_request(**params) expected = u'\u5b57' ### assert that the unicode character is in the response.text output self.assertTrue(expected in r.text) ### assert that the unicode character is _not_ in the response.text.encode('utf-8') ### which has been converted to 8-bit string with unicode characters escaped ### in py2 this raises an exception on the assertion (`expected in x` below) ### in py3 we can compare the two directly, and the assertion should be false if sys.version_info[0] == 2: with self.assertRaises(UnicodeDecodeError): x = str(r.text.encode('utf-8')) expected in x else: self.assertFalse(expected in str(r.text.encode('utf-8'))) pass