Merge "[Py34] api.openstack.compute.legacy_v2.test_servers.Base64ValidationTest"
This commit is contained in:
commit
4c195f20de
@ -364,6 +364,11 @@ class Controller(wsgi.Controller):
|
||||
'|[A-Za-z0-9+\/]{3}=)?$')
|
||||
|
||||
def _decode_base64(self, data):
|
||||
if isinstance(data, six.binary_type) and hasattr(data, "decode"):
|
||||
try:
|
||||
data = data.decode("utf-8")
|
||||
except UnicodeDecodeError:
|
||||
return None
|
||||
data = re.sub(r'\s', '', data)
|
||||
if not self.B64_REGEX.match(data):
|
||||
return None
|
||||
|
@ -126,18 +126,18 @@ class Base64ValidationTest(test.TestCase):
|
||||
self.controller = servers.Controller(self.ext_mgr)
|
||||
|
||||
def test_decode_base64(self):
|
||||
value = "A random string"
|
||||
value = b"A random string"
|
||||
result = self.controller._decode_base64(base64.b64encode(value))
|
||||
self.assertEqual(value, result)
|
||||
|
||||
def test_decode_base64_binary(self):
|
||||
value = "\x00\x12\x75\x99"
|
||||
value = b"\x00\x12\x75\x99"
|
||||
result = self.controller._decode_base64(base64.b64encode(value))
|
||||
self.assertEqual(value, result)
|
||||
|
||||
def test_decode_base64_whitespace(self):
|
||||
value = "A random string"
|
||||
encoded = base64.b64encode(value)
|
||||
value = b"A random string"
|
||||
encoded = base64.b64encode(value).decode("ascii")
|
||||
white = "\n \n%s\t%s\n" % (encoded[:2], encoded[2:])
|
||||
result = self.controller._decode_base64(white)
|
||||
self.assertEqual(value, result)
|
||||
@ -148,8 +148,8 @@ class Base64ValidationTest(test.TestCase):
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_decode_base64_illegal_bytes(self):
|
||||
value = "A random string"
|
||||
encoded = base64.b64encode(value)
|
||||
value = b"A random string"
|
||||
encoded = base64.b64encode(value).decode("ascii")
|
||||
white = ">\x01%s*%s()" % (encoded[:2], encoded[2:])
|
||||
result = self.controller._decode_base64(white)
|
||||
self.assertIsNone(result)
|
||||
|
@ -14,7 +14,6 @@ nova.tests.unit.api.openstack.compute.legacy_v2.test_extensions.ExtensionControl
|
||||
nova.tests.unit.api.openstack.compute.legacy_v2.test_extensions.ExtensionManagerTest
|
||||
nova.tests.unit.api.openstack.compute.legacy_v2.test_extensions.RequestExtensionTest
|
||||
nova.tests.unit.api.openstack.compute.legacy_v2.test_extensions.ResourceExtensionTest
|
||||
nova.tests.unit.api.openstack.compute.legacy_v2.test_servers.Base64ValidationTest
|
||||
nova.tests.unit.api.openstack.compute.legacy_v2.test_servers.ServersControllerCreateTest
|
||||
nova.tests.unit.api.openstack.compute.legacy_v2.test_servers.ServersControllerCreateTestWithMock
|
||||
nova.tests.unit.api.openstack.compute.legacy_v2.test_servers.ServersControllerRebuildInstanceTest
|
||||
|
Loading…
Reference in New Issue
Block a user