~ubuntu-branches/ubuntu/trusty/python-keystoneclient/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/test_ec2utils.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-05-29 13:07:56 UTC
  • mfrom: (1.1.19)
  • Revision ID: package-import@ubuntu.com-20130529130756-3h7dh05a39n9uvq5
Tags: 1:0.2.4-0ubuntu1
* New upstream release. 
* debian/control: Add python-d2to1 and python-pbr
* debian/control: Add testrepository, dropped python-nose
* debian/control: Add python-six

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
        self.secret = '89cdf9e94e2643cab35b8b8ac5a51f83'
28
28
        self.signer = Ec2Signer(self.secret)
29
29
 
 
30
    def tearDown(self):
 
31
        super(Ec2SignerTest, self).tearDown()
 
32
 
 
33
    def test_v4_creds_header(self):
 
34
        auth_str = 'AWS4-HMAC-SHA256 blah'
 
35
        credentials = {'host': '127.0.0.1',
 
36
                       'verb': 'GET',
 
37
                       'path': '/v1/',
 
38
                       'params': {},
 
39
                       'headers': {'Authorization': auth_str}}
 
40
        self.assertTrue(self.signer._v4_creds(credentials))
 
41
 
 
42
    def test_v4_creds_param(self):
 
43
        credentials = {'host': '127.0.0.1',
 
44
                       'verb': 'GET',
 
45
                       'path': '/v1/',
 
46
                       'params': {'X-Amz-Algorithm': 'AWS4-HMAC-SHA256'},
 
47
                       'headers': {}}
 
48
        self.assertTrue(self.signer._v4_creds(credentials))
 
49
 
 
50
    def test_v4_creds_false(self):
 
51
        credentials = {'host': '127.0.0.1',
 
52
                       'verb': 'GET',
 
53
                       'path': '/v1/',
 
54
                       'params': {'SignatureVersion': '0',
 
55
                                  'AWSAccessKeyId': self.access,
 
56
                                  'Timestamp': '2012-11-27T11:47:02Z',
 
57
                                  'Action': 'Foo'}}
 
58
        self.assertFalse(self.signer._v4_creds(credentials))
 
59
 
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)
42
72
 
43
 
        pass
44
 
 
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)
 
106
 
 
107
    def test_generate_v4(self):
 
108
        """
 
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
 
112
        and
 
113
        http://docs.aws.amazon.com/general/latest/gr/
 
114
        sigv4-signed-request-examples.html
 
115
        """
 
116
        # Create a new signer object with the AWS example key
 
117
        secret = 'wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY'
 
118
        signer = Ec2Signer(secret)
 
119
 
 
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
 
135
        params = {}
 
136
        credentials = {'host': 'iam.amazonaws.com',
 
137
                       'verb': 'POST',
 
138
                       'path': '/',
 
139
                       'params': params,
 
140
                       'headers': headers,
 
141
                       'body_hash': body_hash}
 
142
        signature = signer.generate(credentials)
 
143
        expected = ('ced6826de92d2bdeed8f846f0bf508e8'
 
144
                    '559e98e4b0199114b84c54174deb456c')
 
145
        self.assertEqual(signature, expected)