Repository: secdev/scapy

Issue:
Error with ./run_tests_py2
run_tests_py2 crashes with an error:

```
cd test ; PYTHONPATH=../ ./run_tests_py2 -n 1-5 -t regression.uts -f HTML -o /tmp/scapy.html -l
### Booting scapy...
### Starting tests...
### Loading: regression.uts
passed 97666AA5 Test module version detection
passed 19EC7768 List layers
passed FE0F029B List layers - advanced
passed B614219C List commands
passed AD124E63 List contribs
Campaign CRC=BEEF6A18  SHA=2BC3E89113B29117492B8BC0C11C8EFD1D4411D0
PASSED=5 FAILED=0
### Writing output...
Traceback (most recent call last):
  File "./../scapy/tools/UTscapy.py", line 989, in <module>
    sys.exit(main(sys.argv[1:]))
  File "./../scapy/tools/UTscapy.py", line 957, in main
    glob_output = pack_html_campaigns(runned_campaigns, glob_output, LOCAL, glob_title)
  File "./../scapy/tools/UTscapy.py", line 628, in pack_html_campaigns
    External_Files.UTscapy_js.write(os.path.dirname(test_campaign.output_file.name))  # noqa: E501
AttributeError: 'str' object has no attribute 'name'
```


Discussion:
Is that the whole error ? Seems like the bottom is missing :/
@gpotter2 I modified the output of the command. We can now see the AttributError.

Resolving patch:
diff --git a/scapy/tools/UTscapy.py b/scapy/tools/UTscapy.py
--- a/scapy/tools/UTscapy.py
+++ b/scapy/tools/UTscapy.py
@@ -24,9 +24,11 @@
 import traceback
 import warnings
 import zlib
+
 from scapy.consts import WINDOWS
 import scapy.modules.six as six
 from scapy.modules.six.moves import range
+from scapy.compat import base64_bytes
 
 
 #   Util class   #
@@ -73,7 +75,7 @@ def __init__(self, name, URL, local):
         self.URL = URL
 
     def get_local(self):
-        return bz2.decompress(base64.decodestring(self.local))
+        return bz2.decompress(base64_bytes(self.local))
 
     def get_URL(self):
         return self.URL
@@ -625,8 +627,9 @@ def pack_html_campaigns(runned_campaigns, data, local=False, title=None):
 """
     out_dict = {'data': data, 'title': title if title else "UTScapy tests"}
     if local:
-        External_Files.UTscapy_js.write(os.path.dirname(test_campaign.output_file.name))  # noqa: E501
-        External_Files.UTscapy_css.write(os.path.dirname(test_campaign.output_file.name))  # noqa: E501
+        dirname = os.path.dirname(test_campaign.output_file)
+        External_Files.UTscapy_js.write(dirname)
+        External_Files.UTscapy_css.write(dirname)
         out_dict.update(External_Files.get_local_dict())
     else:
         out_dict.update(External_Files.get_URL_dict())


Test patch:
diff --git a/test/regression.uts b/test/regression.uts
--- a/test/regression.uts
+++ b/test/regression.uts
@@ -10941,6 +10941,21 @@ parsed = RTP(raw(created))
 assert parsed.sourcesync == 0xabcdef01
 assert "RTPExtension" not in parsed
 
+= UTscapy HTML output
+
+import tempfile, os
+from scapy.tools.UTscapy import TestCampaign, pack_html_campaigns
+test_campaign = TestCampaign("test")
+test_campaign.output_file = tempfile.mktemp()
+html = pack_html_campaigns([test_campaign], None, local=True)
+dirname = os.path.dirname(test_campaign.output_file)
+filename_js = "%s/UTscapy.js" % dirname
+filename_css = "%s/UTscapy.css" % dirname
+assert os.path.isfile(filename_js)
+assert os.path.isfile(filename_css)
+os.remove(filename_js)
+os.remove(filename_css)
+
 #= Test snmpwalk()
 #
 #~ netaccess