From c5ea361f6d2c836e19f22f1f127d3e5aefdb9d95 Mon Sep 17 00:00:00 2001 From: Jasper Lievisse Adriaanse Date: Thu, 6 Aug 2020 17:03:22 +0200 Subject: [PATCH] add tests for html.escape --- .../unit/returners/test_nagios_nrdp_return.py | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/pytests/unit/returners/test_nagios_nrdp_return.py b/tests/pytests/unit/returners/test_nagios_nrdp_return.py index 315590394cda..fcce315c1cc3 100644 --- a/tests/pytests/unit/returners/test_nagios_nrdp_return.py +++ b/tests/pytests/unit/returners/test_nagios_nrdp_return.py @@ -8,16 +8,33 @@ def test_prepare_xml(): service = "salt-minion" opts = { - "service": service, "hostname": hostname, + "service": service, "checktype": "active", } - prepared_xml = nagios_nrdp_return._prepare_xml(options=opts) - root = ET.fromstring(prepared_xml) + + xml_ret = nagios_nrdp_return._prepare_xml(options=opts) + root = ET.fromstring(xml_ret) checkresult = root.find("checkresult") hostname_res = checkresult.find("hostname").text servicename_res = checkresult.find("servicename").text + # Verify the regular XML format. assert servicename_res == service assert hostname_res == hostname + + +def test_escaped_xml(): + opts = { + "hostname": "s<", + "output": 'output"', + "service": "salt-", + "checktype": "active", + } + + xml_ret = nagios_nrdp_return._prepare_xml(options=opts) + + assert "s&lt" in xml_ret + assert "salt-<minion>" in xml_ret + assert "output"" in xml_ret