Port nova test_serversV21.Base64ValidationTest to Python 3

Remove unused method in ServersController and corresponding test cases:
- api/openstack/compute/servers.py
  ServersController._decode_base64
- api/openstack/compute/test_serversV21.py
  Base64ValidationTest

Partially implements: blueprint nova-python3-newton

Change-Id: If7379db5abf686dd8db6ec1d0950637552913505
This commit is contained in:
Duong Ha-Quang 2016-07-16 00:23:42 +07:00
parent 7a8f1369c5
commit a5fa5439ae
3 changed files with 0 additions and 56 deletions

View File

@ -14,9 +14,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import base64
import re
from oslo_log import log as logging
import oslo_messaging as messaging
from oslo_utils import strutils
@ -441,22 +438,6 @@ class ServersController(wsgi.Controller):
return objects.NetworkRequestList(objects=networks)
# NOTE(vish): Without this regex, b64decode will happily
# ignore illegal bytes in the base64 encoded
# data.
B64_REGEX = re.compile('^(?:[A-Za-z0-9+\/]{4})*'
'(?:[A-Za-z0-9+\/]{2}=='
'|[A-Za-z0-9+\/]{3}=)?$')
def _decode_base64(self, data):
data = re.sub(r'\s', '', data)
if not self.B64_REGEX.match(data):
return None
try:
return base64.b64decode(data)
except TypeError:
return None
@extensions.expected_errors(404)
def show(self, req, id):
"""Returns server details by server id."""

View File

@ -150,42 +150,6 @@ class MockSetAdminPassword(object):
self.password = password
class Base64ValidationTest(test.TestCase):
def setUp(self):
super(Base64ValidationTest, self).setUp()
ext_info = extension_info.LoadedExtensionInfo()
self.controller = servers.ServersController(extension_info=ext_info)
def test_decode_base64(self):
value = "A random string"
result = self.controller._decode_base64(base64.b64encode(value))
self.assertEqual(result, value)
def test_decode_base64_binary(self):
value = "\x00\x12\x75\x99"
result = self.controller._decode_base64(base64.b64encode(value))
self.assertEqual(result, value)
def test_decode_base64_whitespace(self):
value = "A random string"
encoded = base64.b64encode(value)
white = "\n \n%s\t%s\n" % (encoded[:2], encoded[2:])
result = self.controller._decode_base64(white)
self.assertEqual(result, value)
def test_decode_base64_invalid(self):
invalid = "A random string"
result = self.controller._decode_base64(invalid)
self.assertIsNone(result)
def test_decode_base64_illegal_bytes(self):
value = "A random string"
encoded = base64.b64encode(value)
white = ">\x01%s*%s()" % (encoded[:2], encoded[2:])
result = self.controller._decode_base64(white)
self.assertIsNone(result)
class ControllerTest(test.TestCase):
def setUp(self):

View File

@ -21,7 +21,6 @@ nova.tests.unit.api.openstack.compute.test_security_group_default_rules.TestSecu
nova.tests.unit.api.openstack.compute.test_security_groups.SecurityGroupsOutputTestV21
nova.tests.unit.api.openstack.compute.test_security_groups.TestSecurityGroupRulesV21
nova.tests.unit.api.openstack.compute.test_server_actions.ServerActionsControllerTestV21
nova.tests.unit.api.openstack.compute.test_serversV21.Base64ValidationTest
nova.tests.unit.api.openstack.compute.test_serversV21.ServersControllerCreateTest
nova.tests.unit.api.openstack.compute.test_serversV21.ServersControllerRebuildInstanceTest
nova.tests.unit.api.openstack.compute.test_serversV21.ServersControllerRebuildTestV219