Removed unused code from cinder.utils
Removed unused safe_minidom_parse_string() method from cinder.utils and it's related test case. TrivialFix Change-Id: I6c2cde126bd65930596e42b4a63dfc6b16aab839
This commit is contained in:
parent
d172a170a4
commit
fcda064f7e
@ -241,36 +241,6 @@ class GenericUtilsTestCase(test.TestCase):
|
|||||||
result = utils.service_is_up(service)
|
result = utils.service_is_up(service)
|
||||||
self.assertFalse(result)
|
self.assertFalse(result)
|
||||||
|
|
||||||
def test_safe_parse_xml(self):
|
|
||||||
|
|
||||||
normal_body = ('<?xml version="1.0" ?>'
|
|
||||||
'<foo><bar><v1>hey</v1><v2>there</v2></bar></foo>')
|
|
||||||
|
|
||||||
def killer_body():
|
|
||||||
return (("""<!DOCTYPE x [
|
|
||||||
<!ENTITY a "%(a)s">
|
|
||||||
<!ENTITY b "%(b)s">
|
|
||||||
<!ENTITY c "%(c)s">]>
|
|
||||||
<foo>
|
|
||||||
<bar>
|
|
||||||
<v1>%(d)s</v1>
|
|
||||||
</bar>
|
|
||||||
</foo>""") % {
|
|
||||||
'a': 'A' * 10,
|
|
||||||
'b': '&a;' * 10,
|
|
||||||
'c': '&b;' * 10,
|
|
||||||
'd': '&c;' * 9999,
|
|
||||||
}).strip()
|
|
||||||
|
|
||||||
dom = utils.safe_minidom_parse_string(normal_body)
|
|
||||||
# Some versions of minidom inject extra newlines so we ignore them
|
|
||||||
result = str(dom.toxml()).replace('\n', '')
|
|
||||||
self.assertEqual(normal_body, result)
|
|
||||||
|
|
||||||
self.assertRaises(ValueError,
|
|
||||||
utils.safe_minidom_parse_string,
|
|
||||||
killer_body())
|
|
||||||
|
|
||||||
def test_check_ssh_injection(self):
|
def test_check_ssh_injection(self):
|
||||||
cmd_list = ['ssh', '-D', 'my_name@name_of_remote_computer']
|
cmd_list = ['ssh', '-D', 'my_name@name_of_remote_computer']
|
||||||
self.assertIsNone(utils.check_ssh_injection(cmd_list))
|
self.assertIsNone(utils.check_ssh_injection(cmd_list))
|
||||||
|
@ -36,9 +36,6 @@ import sys
|
|||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import types
|
import types
|
||||||
from xml.dom import minidom
|
|
||||||
from xml.parsers import expat
|
|
||||||
from xml import sax
|
|
||||||
from xml.sax import expatreader
|
from xml.sax import expatreader
|
||||||
|
|
||||||
from os_brick.initiator import connector
|
from os_brick.initiator import connector
|
||||||
@ -300,22 +297,6 @@ class ProtectedExpatParser(expatreader.ExpatParser):
|
|||||||
self._parser.UnparsedEntityDeclHandler = self.unparsed_entity_decl
|
self._parser.UnparsedEntityDeclHandler = self.unparsed_entity_decl
|
||||||
|
|
||||||
|
|
||||||
def safe_minidom_parse_string(xml_string):
|
|
||||||
"""Parse an XML string using minidom safely.
|
|
||||||
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
if six.PY3 and isinstance(xml_string, bytes):
|
|
||||||
# On Python 3, minidom.parseString() requires Unicode when
|
|
||||||
# the parser parameter is used.
|
|
||||||
#
|
|
||||||
# Bet that XML used in Cinder is always encoded to UTF-8.
|
|
||||||
xml_string = xml_string.decode('utf-8')
|
|
||||||
return minidom.parseString(xml_string, parser=ProtectedExpatParser())
|
|
||||||
except sax.SAXParseException:
|
|
||||||
raise expat.ExpatError()
|
|
||||||
|
|
||||||
|
|
||||||
def is_valid_boolstr(val):
|
def is_valid_boolstr(val):
|
||||||
"""Check if the provided string is a valid bool string or not."""
|
"""Check if the provided string is a valid bool string or not."""
|
||||||
val = str(val).lower()
|
val = str(val).lower()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user