Skip to content

Commit

Permalink
config: escape any quotes in name of resource on ifmap write.
Browse files Browse the repository at this point in the history
Define a version of escape/unescape that invokes the sax library
based ones with additional escapes for single and double-quotes.

A 'patch' to do the same on already deployed systems is at
https://gist.github.com/ajayhn/603c3f8168132aba6e5d

Change-Id: Ifcae17e80ffc1528908f37f79c3215887487ca14
Partial-Bug: #1449156
(cherry picked from commit 7370c30)
  • Loading branch information
Hampapur Ajay committed Apr 28, 2015
1 parent 27470f9 commit ad33aeb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/config/api-server/tests/test_crud_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,21 +916,21 @@ def test_floatingip_as_instanceip(self):
# end test_floatingip_as_instanceip

def test_name_with_reserved_xml_char(self):
vn_name = self.id()+'-&vn<1>'
vn_name = self.id()+'-&vn<1>"2\''
vn_obj = VirtualNetwork(vn_name)
# fq_name, fq_name_str has non-escape val, ifmap-id has escaped val
ifmap_id = cfgm_common.imid.get_ifmap_id_from_fq_name(vn_obj.get_type(),
vn_obj.get_fq_name())
self.assertIsNot(re.search("&amp;vn&lt;1&gt;", ifmap_id), None)
self.assertIsNot(re.search("&amp;vn&lt;1&gt;&quot;2&apos;", ifmap_id), None)
fq_name_str = cfgm_common.imid.get_fq_name_str_from_ifmap_id(ifmap_id)
self.assertIsNone(re.search("&amp;vn&lt;1&gt;", fq_name_str))
self.assertIsNone(re.search("&amp;vn&lt;1&gt;&quot;2&apos;", fq_name_str))

self._add_detail('Creating network with name %s expecting success' %(vn_name))
self._vnc_lib.virtual_network_create(vn_obj)
self.assertTill(self.ifmap_has_ident, obj=vn_obj)
ident_elem = FakeIfmapClient._graph[ifmap_id]['ident']
ident_str = etree.tostring(ident_elem)
mch = re.search("&amp;vn&lt;1&gt;", ident_str)
mch = re.search("&amp;vn&lt;1&gt;&quot;2&apos;", ident_str)
self.assertIsNot(mch, None)
self._vnc_lib.virtual_network_delete(id=vn_obj.uuid)

Expand Down
10 changes: 9 additions & 1 deletion src/config/common/imid.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from ifmap.util import attr, link_ids
from ifmap.response import Response, newSessionResult
from ifmap.metadata import Metadata
from xml.sax.saxutils import escape, unescape
from xml.sax.saxutils import escape as s_esc, unescape as s_unesc


_TENANT_GRP = "(?P<tenant_uuid>.*)"
Expand Down Expand Up @@ -242,3 +242,11 @@ def parse_poll_result(poll_result_str):
result_list.append((result_type, idents, meta))
return result_list
# end parse_poll_result

def escape(string):
return s_esc(string, entities={'"':'&quot;', "'": "&apos;"})
# end escape

def unescape(string):
return s_unesc(string, entities={'&quot;':'"', "&apos;": "'"})
# end unescape
2 changes: 1 addition & 1 deletion src/config/common/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import re
import copy
from lxml import etree
from xml.sax.saxutils import escape, unescape
try:
from collections import OrderedDict
except ImportError:
Expand All @@ -35,6 +34,7 @@
from novaclient import exceptions as nc_exc

from cfgm_common.exceptions import ResourceExistsError
from cfgm_common.imid import escape, unescape

def stub(*args, **kwargs):
pass
Expand Down

0 comments on commit ad33aeb

Please sign in to comment.