27
27
self.secret = '89cdf9e94e2643cab35b8b8ac5a51f83'
28
28
self.signer = Ec2Signer(self.secret)
31
super(Ec2SignerTest, self).tearDown()
33
def test_v4_creds_header(self):
34
auth_str = 'AWS4-HMAC-SHA256 blah'
35
credentials = {'host': '127.0.0.1',
39
'headers': {'Authorization': auth_str}}
40
self.assertTrue(self.signer._v4_creds(credentials))
42
def test_v4_creds_param(self):
43
credentials = {'host': '127.0.0.1',
46
'params': {'X-Amz-Algorithm': 'AWS4-HMAC-SHA256'},
48
self.assertTrue(self.signer._v4_creds(credentials))
50
def test_v4_creds_false(self):
51
credentials = {'host': '127.0.0.1',
54
'params': {'SignatureVersion': '0',
55
'AWSAccessKeyId': self.access,
56
'Timestamp': '2012-11-27T11:47:02Z',
58
self.assertFalse(self.signer._v4_creds(credentials))
30
60
def test_generate_0(self):
31
61
"""Test generate function for v0 signature"""
32
62
credentials = {'host': '127.0.0.1',
40
70
expected = 'SmXQEZAUdQw5glv5mX8mmixBtas='
41
71
self.assertEqual(signature, expected)
45
73
def test_generate_1(self):
46
74
"""Test generate function for v1 signature"""
47
75
credentials = {'host': '127.0.0.1',
75
103
signature = self.signer.generate(credentials)
76
104
expected = 'ZqCxMI4ZtTXWI175743mJ0hy/Gc='
77
105
self.assertEqual(signature, expected)
107
def test_generate_v4(self):
109
Test v4 generator with data from AWS docs example, see:
110
http://docs.aws.amazon.com/general/latest/gr/
111
sigv4-create-canonical-request.html
113
http://docs.aws.amazon.com/general/latest/gr/
114
sigv4-signed-request-examples.html
116
# Create a new signer object with the AWS example key
117
secret = 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY'
118
signer = Ec2Signer(secret)
120
body_hash = ('b6359072c78d70ebee1e81adcbab4f0'
121
'1bf2c23245fa365ef83fe8f1f955085e2')
122
auth_str = ('AWS4-HMAC-SHA256 '
123
'Credential=AKIAIOSFODNN7EXAMPLE/20110909/'
124
'us-east-1/iam/aws4_request,'
125
'SignedHeaders=content-type;host;x-amz-date,')
126
headers = {'Content-type':
127
'application/x-www-form-urlencoded; charset=utf-8',
128
'X-Amz-Date': '20110909T233600Z',
129
'Host': 'iam.amazonaws.com',
130
'Authorization': auth_str}
131
# Note the example in the AWS docs is inconsistent, previous
132
# examples specify no query string, but the final POST example
133
# does, apparently incorrectly since an empty parameter list
134
# aligns all steps and the final signature with the examples
136
credentials = {'host': 'iam.amazonaws.com',
141
'body_hash': body_hash}
142
signature = signer.generate(credentials)
143
expected = ('ced6826de92d2bdeed8f846f0bf508e8'
144
'559e98e4b0199114b84c54174deb456c')
145
self.assertEqual(signature, expected)