diff --git a/faraday_plugins/plugins/repo/burp/plugin.py b/faraday_plugins/plugins/repo/burp/plugin.py index 0fafd7f4..6c67ba7e 100644 --- a/faraday_plugins/plugins/repo/burp/plugin.py +++ b/faraday_plugins/plugins/repo/burp/plugin.py @@ -7,7 +7,6 @@ import binascii import re import base64 -import distutils.util # pylint: disable=import-error from urllib.parse import urlsplit import lxml.etree as ET @@ -26,6 +25,15 @@ __status__ = "Development" +def strtobool(value): + normalized = value.lower() + if normalized in ("y", "yes", "t", "true", "on", "1"): + return 1 + if normalized in ("n", "no", "f", "false", "off", "0"): + return 0 + raise ValueError(f"invalid truth value {value!r}") + + class BurpXmlParser: """ The objective of this class is to parse an xml file generated by the burp tool. @@ -158,7 +166,7 @@ def decode_binary_node(self, node): it has it. """ if node is not None: - encoded = distutils.util.strtobool(node.get('base64', 'false')) + encoded = strtobool(node.get('base64', 'false')) if encoded: text = node.text or "" text += "=" * (-len(text) % 4) diff --git a/tests/test_burp.py b/tests/test_burp.py new file mode 100644 index 00000000..c74b39b6 --- /dev/null +++ b/tests/test_burp.py @@ -0,0 +1,26 @@ +import lxml.etree as ET + +from faraday_plugins.plugins.repo.burp.plugin import Item, strtobool + + +def test_decode_binary_node_keeps_plain_text(): + node = ET.fromstring("plain text") + item = Item.__new__(Item) + + assert item.decode_binary_node(node) == "plain text" + + +def test_decode_binary_node_decodes_base64_text(): + node = ET.fromstring("cGxhaW4gdGV4dA==") + item = Item.__new__(Item) + + assert item.decode_binary_node(node) == "plain text" + + +def test_strtobool_rejects_invalid_values(): + try: + strtobool("maybe") + except ValueError as exc: + assert "invalid truth value 'maybe'" == str(exc) + else: + raise AssertionError("ValueError was not raised")