Skip to content

Commit

Permalink
Merge branch 'Andrey-mp-develop' into develop
Browse files Browse the repository at this point in the history
* Andrey-mp-develop:
  add test for #308
  fix V2 auth timestamp
  • Loading branch information
jamesls committed Jun 24, 2014
2 parents 607c24c + df95375 commit ceca77c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion botocore/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from email.utils import formatdate
from operator import itemgetter
import functools
import time

from botocore.exceptions import NoCredentialsError
from botocore.utils import normalize_url_path
Expand All @@ -37,6 +38,7 @@
# Experimenting with various buffer sizes showed that this value generally
# gave the best result (in terms of performance).
PAYLOAD_BUFFER = 1024 * 1024
ISO8601 = '%Y-%m-%dT%H:%M:%SZ'


class BaseSigner(object):
Expand Down Expand Up @@ -94,7 +96,7 @@ def add_auth(self, request):
params['AWSAccessKeyId'] = self.credentials.access_key
params['SignatureVersion'] = '2'
params['SignatureMethod'] = 'HmacSHA256'
params['Timestamp'] = datetime.datetime.utcnow().isoformat()
params['Timestamp'] = time.strftime(ISO8601, time.gmtime())
if self.credentials.token:
params['SecurityToken'] = self.credentials.token
qs, signature = self.calc_signature(request, params)
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/auth/test_signers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# language governing permissions and limitations under the License.
from tests import unittest
import datetime
import time

import mock
import six
Expand All @@ -22,6 +23,7 @@
import botocore.credentials
from botocore.compat import HTTPHeaders, urlsplit, parse_qs
from botocore.awsrequest import AWSRequest
from botocore.vendored.requests.models import Request


class TestHMACV1(unittest.TestCase):
Expand Down Expand Up @@ -92,6 +94,16 @@ def setUp(self):
self.credentials = botocore.credentials.Credentials(access_key,
secret_key)
self.signer = botocore.auth.SigV2Auth(self.credentials)
self.time_patcher = mock.patch.object(
botocore.auth.time, 'gmtime',
mock.Mock(wraps=time.gmtime)
)
mocked_time = self.time_patcher.start()
mocked_time.return_value = time.struct_time(
[2014, 6, 20, 8, 40, 23, 4, 171, 0])

def tearDown(self):
self.time_patcher.stop()

def test_put(self):
request = mock.Mock()
Expand All @@ -103,6 +115,20 @@ def test_put(self):
result, ('Foo=%E2%9C%93',
u'VCtWuwaOL0yMffAT8W4y0AFW3W4KUykBqah9S40rB+Q='))

def test_fields(self):
request = Request()
request.url = '/'
request.method = 'POST'
request.data = {'Foo': u'\u2713'}
self.signer.add_auth(request)
self.assertEqual(request.data['AWSAccessKeyId'], 'foo')
self.assertEqual(request.data['Foo'], u'\u2713')
self.assertEqual(request.data['Timestamp'], '2014-06-20T08:40:23Z')
self.assertEqual(request.data['Signature'],
u'Tiecw+t51tok4dTT8B4bg47zxHEM/KcD55f2/x6K22o=')
self.assertEqual(request.data['SignatureMethod'], 'HmacSHA256')
self.assertEqual(request.data['SignatureVersion'], '2')


class TestSigV3(unittest.TestCase):

Expand Down

0 comments on commit ceca77c

Please sign in to comment.