From 0294836d9b800de860e36699986f4de0fb1d2141 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Fri, 29 Mar 2019 14:50:06 -0700 Subject: [PATCH] py3: test/unit/common/middleware/s3api/test_s3token.py Change-Id: Ibbff151703395d517452c3d6927652506a9eab66 --- swift/common/middleware/s3api/s3token.py | 4 +++- test/unit/common/middleware/s3api/test_s3token.py | 8 ++++---- tox.ini | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/swift/common/middleware/s3api/s3token.py b/swift/common/middleware/s3api/s3token.py index 210f7b66f3..503f276922 100644 --- a/swift/common/middleware/s3api/s3token.py +++ b/swift/common/middleware/s3api/s3token.py @@ -275,7 +275,9 @@ class S3Token(object): string_to_sign = s3_auth_details['string_to_sign'] if isinstance(string_to_sign, six.text_type): string_to_sign = string_to_sign.encode('utf-8') - token = base64.urlsafe_b64encode(string_to_sign).encode('ascii') + token = base64.urlsafe_b64encode(string_to_sign) + if isinstance(token, six.binary_type): + token = token.decode('ascii') # NOTE(chmou): This is to handle the special case with nova # when we have the option s3_affix_tenant. We will force it to diff --git a/test/unit/common/middleware/s3api/test_s3token.py b/test/unit/common/middleware/s3api/test_s3token.py index 9ea49fa16a..aaf15cba6e 100644 --- a/test/unit/common/middleware/s3api/test_s3token.py +++ b/test/unit/common/middleware/s3api/test_s3token.py @@ -465,12 +465,12 @@ class S3TokenMiddlewareTestGood(S3TokenMiddlewareTestBase): with self.assertRaises(ConfigFileError) as cm: s3token.filter_factory({'auth_uri': auth_uri})(self.app) self.assertEqual('Invalid auth_uri; must include scheme and host', - cm.exception.message) + cm.exception.args[0]) with self.assertRaises(ConfigFileError) as cm: s3token.filter_factory({ 'auth_uri': 'nonhttp://example.com'})(self.app) self.assertEqual('Invalid auth_uri; scheme must be http or https', - cm.exception.message) + cm.exception.args[0]) for auth_uri in [ 'http://user@example.com/', 'http://example.com/?with=query', @@ -478,7 +478,7 @@ class S3TokenMiddlewareTestGood(S3TokenMiddlewareTestBase): with self.assertRaises(ConfigFileError) as cm: s3token.filter_factory({'auth_uri': auth_uri})(self.app) self.assertEqual('Invalid auth_uri; must not include username, ' - 'query, or fragment', cm.exception.message) + 'query, or fragment', cm.exception.args[0]) def test_unicode_path(self): url = u'/v1/AUTH_cfa/c/euro\u20ac'.encode('utf8') @@ -577,7 +577,7 @@ class S3TokenMiddlewareTestGood(S3TokenMiddlewareTestBase): MOCK_REQUEST.return_value = TestResponse({ 'status_code': 201, - 'text': json.dumps(GOOD_RESPONSE_V2)}) + 'text': json.dumps(GOOD_RESPONSE_V2).encode('ascii')}) req = Request.blank('/v1/AUTH_cfa/c/o') req.environ['s3api.auth_details'] = { diff --git a/tox.ini b/tox.ini index 787f30ce37..4f4e19edf1 100644 --- a/tox.ini +++ b/tox.ini @@ -38,6 +38,7 @@ commands = test/unit/account \ test/unit/cli \ test/unit/common/middleware/crypto \ + test/unit/common/middleware/s3api/test_s3token.py \ test/unit/common/middleware/test_account_quotas.py \ test/unit/common/middleware/test_acl.py \ test/unit/common/middleware/test_catch_errors.py \