You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
python-boto/boto-2.40.0-sigv4-protocol....

69 lines
2.5 KiB

From b856be32c4daf4d223efec85ef48b2cd80388713 Mon Sep 17 00:00:00 2001
From: Tim Burke <tim.burke@gmail.com>
Date: Mon, 6 Jun 2016 15:44:01 -0700
Subject: [PATCH] Respect is_secure parameter in generate_url_sigv4
Previously, the protocol was hardcoded to https.
---
boto/auth.py | 4 ++--
tests/unit/s3/test_connection.py | 31 +++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 2 deletions(-)
Index: boto-2.40.0/boto/auth.py
===================================================================
--- boto-2.40.0.orig/boto/auth.py
+++ boto-2.40.0/boto/auth.py
@@ -771,8 +771,8 @@ class S3HmacAuthV4Handler(HmacAuthV4Hand
# Add signature to params now that we have it
req.params['X-Amz-Signature'] = signature
- return 'https://%s%s?%s' % (req.host, req.path,
- urllib.parse.urlencode(req.params))
+ return '%s://%s%s?%s' % (req.protocol, req.host, req.path,
+ urllib.parse.urlencode(req.params))
class STSAnonHandler(AuthHandler):
Index: boto-2.40.0/tests/unit/s3/test_connection.py
===================================================================
--- boto-2.40.0.orig/tests/unit/s3/test_connection.py
+++ boto-2.40.0/tests/unit/s3/test_connection.py
@@ -141,6 +141,37 @@ class TestSigV4Presigned(MockServiceWith
'a937f5fbc125d98ac8f04c49e0204ea1526a7b8ca058000a54c192457be05b7d',
url)
+ def test_sigv4_presign_respects_is_secure(self):
+ self.config = {
+ 's3': {
+ 'use-sigv4': True,
+ }
+ }
+
+ conn = self.connection_class(
+ aws_access_key_id='less',
+ aws_secret_access_key='more',
+ host='s3.amazonaws.com',
+ is_secure=True,
+ )
+
+ url = conn.generate_url_sigv4(86400, 'GET', bucket='examplebucket',
+ key='test.txt')
+ self.assertTrue(url.startswith(
+ 'https://examplebucket.s3.amazonaws.com/test.txt?'))
+
+ conn = self.connection_class(
+ aws_access_key_id='less',
+ aws_secret_access_key='more',
+ host='s3.amazonaws.com',
+ is_secure=False,
+ )
+
+ url = conn.generate_url_sigv4(86400, 'GET', bucket='examplebucket',
+ key='test.txt')
+ self.assertTrue(url.startswith(
+ 'http://examplebucket.s3.amazonaws.com/test.txt?'))
+
def test_sigv4_presign_optional_params(self):
self.config = {
's3': {