From 52473ea39277f6b3d8e7d77564189da6b1aec7c3 Mon Sep 17 00:00:00 2001 From: Hanxi Liu Date: Wed, 28 Sep 2016 10:58:30 +0800 Subject: [PATCH] Use six.moves.urllib.parse instead of urllib Six urllib parse contains py3's urllib.parse and py2's urllib. Replace urllib with six.moves.urllib.parse to keep compatibility. Change-Id: Ie67987e4ffb981c2ee70360f7fa9b3fe873c2a96 Closes-bug: 1280105 --- .../middleware/crypto/test_encrypter.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/unit/common/middleware/crypto/test_encrypter.py b/test/unit/common/middleware/crypto/test_encrypter.py index c269e5d007..db30486a06 100644 --- a/test/unit/common/middleware/crypto/test_encrypter.py +++ b/test/unit/common/middleware/crypto/test_encrypter.py @@ -18,10 +18,10 @@ import hmac import json import os import unittest -import urllib import mock +from six.moves.urllib import parse as urlparse from swift.common.middleware.crypto import encrypter from swift.common.middleware.crypto.crypto_utils import ( CRYPTO_KEY_CALLBACK, Crypto) @@ -52,7 +52,7 @@ class TestEncrypter(unittest.TestCase): param = param.strip() self.assertTrue(param.startswith('swift_meta=')) actual_meta = json.loads( - urllib.unquote_plus(param[len('swift_meta='):])) + urlparse.unquote_plus(param[len('swift_meta='):])) self.assertEqual(Crypto.cipher, actual_meta['cipher']) meta_iv = base64.b64decode(actual_meta['iv']) self.assertEqual(FAKE_IV, meta_iv) @@ -61,7 +61,7 @@ class TestEncrypter(unittest.TestCase): enc_val) # if there is any encrypted user metadata then this header should exist self.assertIn('X-Object-Transient-Sysmeta-Crypto-Meta', req_hdrs) - common_meta = json.loads(urllib.unquote_plus( + common_meta = json.loads(urlparse.unquote_plus( req_hdrs['X-Object-Transient-Sysmeta-Crypto-Meta'])) self.assertDictEqual({'cipher': Crypto.cipher, 'key_id': {'v': 'fake', 'path': '/a/c/fake'}}, @@ -101,7 +101,7 @@ class TestEncrypter(unittest.TestCase): # verify body crypto meta actual = req_hdrs['X-Object-Sysmeta-Crypto-Body-Meta'] - actual = json.loads(urllib.unquote_plus(actual)) + actual = json.loads(urlparse.unquote_plus(actual)) self.assertEqual(Crypto().cipher, actual['cipher']) self.assertEqual(FAKE_IV, base64.b64decode(actual['iv'])) @@ -120,7 +120,7 @@ class TestEncrypter(unittest.TestCase): req_hdrs['X-Object-Sysmeta-Crypto-Etag'].partition('; swift_meta=') # verify crypto_meta was appended to this etag self.assertTrue(etag_meta) - actual_meta = json.loads(urllib.unquote_plus(etag_meta)) + actual_meta = json.loads(urlparse.unquote_plus(etag_meta)) self.assertEqual(Crypto().cipher, actual_meta['cipher']) # verify encrypted version of plaintext etag @@ -147,7 +147,7 @@ class TestEncrypter(unittest.TestCase): crypto_meta_tag = 'swift_meta=' self.assertTrue(param.startswith(crypto_meta_tag), param) actual_meta = json.loads( - urllib.unquote_plus(param[len(crypto_meta_tag):])) + urlparse.unquote_plus(param[len(crypto_meta_tag):])) self.assertEqual(Crypto().cipher, actual_meta['cipher']) self.assertEqual(fetch_crypto_keys()['id'], actual_meta['key_id']) @@ -278,7 +278,7 @@ class TestEncrypter(unittest.TestCase): encrypted_etag, _junk, etag_meta = \ req_hdrs['X-Object-Sysmeta-Crypto-Etag'].partition('; swift_meta=') self.assertTrue(etag_meta) - actual_meta = json.loads(urllib.unquote_plus(etag_meta)) + actual_meta = json.loads(urlparse.unquote_plus(etag_meta)) self.assertEqual(Crypto().cipher, actual_meta['cipher']) self.assertEqual(ciphertext_etag, req_hdrs['Etag']) @@ -298,7 +298,7 @@ class TestEncrypter(unittest.TestCase): crypto_meta_tag = 'swift_meta=' self.assertTrue(param.startswith(crypto_meta_tag), param) actual_meta = json.loads( - urllib.unquote_plus(param[len(crypto_meta_tag):])) + urlparse.unquote_plus(param[len(crypto_meta_tag):])) self.assertEqual(Crypto().cipher, actual_meta['cipher']) cont_key = fetch_crypto_keys()['container'] @@ -309,7 +309,7 @@ class TestEncrypter(unittest.TestCase): # verify body crypto meta actual = req_hdrs['X-Object-Sysmeta-Crypto-Body-Meta'] - actual = json.loads(urllib.unquote_plus(actual)) + actual = json.loads(urlparse.unquote_plus(actual)) self.assertEqual(Crypto().cipher, actual['cipher']) self.assertEqual(FAKE_IV, base64.b64decode(actual['iv'])) @@ -368,7 +368,7 @@ class TestEncrypter(unittest.TestCase): crypto_meta_tag = 'swift_meta=' self.assertTrue(param.startswith(crypto_meta_tag), param) actual_meta = json.loads( - urllib.unquote_plus(param[len(crypto_meta_tag):])) + urlparse.unquote_plus(param[len(crypto_meta_tag):])) self.assertEqual(Crypto().cipher, actual_meta['cipher']) self.assertEqual(fetch_crypto_keys()['id'], actual_meta['key_id']) @@ -491,7 +491,7 @@ class TestEncrypter(unittest.TestCase): crypto_meta_tag = 'swift_meta=' self.assertTrue(param.startswith(crypto_meta_tag), param) actual_meta = json.loads( - urllib.unquote_plus(param[len(crypto_meta_tag):])) + urlparse.unquote_plus(param[len(crypto_meta_tag):])) self.assertEqual(Crypto().cipher, actual_meta['cipher']) self.assertEqual(fetch_crypto_keys()['id'], actual_meta['key_id'])