Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: third_party/gsutil/boto/tests/unit/auth/test_sigv4.py

Issue 12042069: Scripts to download files from google storage based on sha1 sums (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Review fixes, updated gsutil Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis-
7 # tribute, sublicense, and/or sell copies of the Software, and to permit
8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions:
10 #
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
21 #
22 from mock import Mock
23 from tests.unit import unittest
24
25 from boto.auth import HmacAuthV4Handler
26 from boto.connection import HTTPRequest
27
28
29 class TestSigV4Handler(unittest.TestCase):
30 def setUp(self):
31 self.provider = Mock()
32 self.provider.access_key = 'access_key'
33 self.provider.secret_key = 'secret_key'
34 self.request = HTTPRequest(
35 'POST', 'https', 'glacier.us-east-1.amazonaws.com', 443,
36 '/-/vaults/foo/archives', None, {},
37 {'x-amz-glacier-version': '2012-06-01'}, '')
38
39 def test_inner_whitespace_is_collapsed(self):
40 auth = HmacAuthV4Handler('glacier.us-east-1.amazonaws.com',
41 Mock(), self.provider)
42 self.request.headers['x-amz-archive-description'] = 'two spaces'
43 headers = auth.headers_to_sign(self.request)
44 self.assertEqual(headers, {'Host': 'glacier.us-east-1.amazonaws.com',
45 'x-amz-archive-description': 'two spaces',
46 'x-amz-glacier-version': '2012-06-01'})
47 # Note the single space between the "two spaces".
48 self.assertEqual(auth.canonical_headers(headers),
49 'host:glacier.us-east-1.amazonaws.com\n'
50 'x-amz-archive-description:two spaces\n'
51 'x-amz-glacier-version:2012-06-01')
52
53 def test_canonical_query_string(self):
54 auth = HmacAuthV4Handler('glacier.us-east-1.amazonaws.com',
55 Mock(), self.provider)
56 request = HTTPRequest(
57 'GET', 'https', 'glacier.us-east-1.amazonaws.com', 443,
58 '/-/vaults/foo/archives', None, {},
59 {'x-amz-glacier-version': '2012-06-01'}, '')
60 request.params['Foo.1'] = 'aaa'
61 request.params['Foo.10'] = 'zzz'
62 query_string = auth.canonical_query_string(request)
63 self.assertEqual(query_string, 'Foo.1=aaa&Foo.10=zzz')
64
65 def test_region_and_service_can_be_overriden(self):
66 auth = HmacAuthV4Handler('queue.amazonaws.com',
67 Mock(), self.provider)
68 self.request.headers['X-Amz-Date'] = '20121121000000'
69
70 auth.region_name = 'us-west-2'
71 auth.service_name = 'sqs'
72 scope = auth.credential_scope(self.request)
73 self.assertEqual(scope, '20121121/us-west-2/sqs/aws4_request')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698