commit 2b688756d9417d1c7279e8b4054fd739e5ca5c35
Author: Arturo Filastò <art...@filasto.net>
Date:   Sun Jul 24 23:46:36 2016 +0200

    Add backend to required options to show error when it's not provided
    
    * Use same function to represent packets in traceroute test
---
 ooni/nettests/manipulation/traceroute.py |  5 +++--
 ooni/templates/scapyt.py                 | 10 +++++-----
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/ooni/nettests/manipulation/traceroute.py 
b/ooni/nettests/manipulation/traceroute.py
index d6f1ddf..3553bfd 100644
--- a/ooni/nettests/manipulation/traceroute.py
+++ b/ooni/nettests/manipulation/traceroute.py
@@ -31,6 +31,7 @@ class Traceroute(scapyt.BaseScapyTest):
                   "set to 0, 22, 23, 53, 80, 123, 443, 8080 and 65535."
 
     requiredTestHelpers = {'backend': 'traceroute'}
+    requiredOptions = ['backend']
     requiresRoot = True
     requiresTor = False
 
@@ -63,9 +64,9 @@ class Traceroute(scapyt.BaseScapyTest):
         st.stopListening()
         st.matchResponses()
         for packet in st.sent_packets:
-            self.report['sent_packets'].append(packet)
+            self.report['sent_packets'].append(scapyt.representPacket(packet))
         for packet in st.matched_packets.values():
-            self.report['answered_packets'].extend(packet)
+            
self.report['answered_packets'].append(scapyt.representPacket(packet))
 
         for ttl in xrange(st.ttl_min, st.ttl_max):
             matchedPackets = filter(
diff --git a/ooni/templates/scapyt.py b/ooni/templates/scapyt.py
index 1c726d8..e122525 100644
--- a/ooni/templates/scapyt.py
+++ b/ooni/templates/scapyt.py
@@ -7,13 +7,13 @@ from ooni.utils.net import hasRawSocketPermission
 from ooni.utils.txscapy import ScapySender, ScapyFactory
 
 
-def _representPacket(packet):
+def representPacket(packet):
     return {
         "raw_packet": {
             'data': b64encode(str(packet)),
             'format': 'base64'
         },
-        "summary": repr(packet)
+        "summary": str(repr(packet))
     }
 
 class BaseScapyTest(NetTestCase):
@@ -98,8 +98,8 @@ class BaseScapyTest(NetTestCase):
                 sent_packet.src = '127.0.0.1'
                 received_packet.dst = '127.0.0.1'
 
-            self.report['sent_packets'].append(_representPacket(sent_packet))
-            
self.report['answered_packets'].append(_representPacket(received_packet))
+            self.report['sent_packets'].append(representPacket(sent_packet))
+            
self.report['answered_packets'].append(representPacket(received_packet))
         return packets
 
     def sr(self, packets, timeout=None, *arg, **kw):
@@ -152,7 +152,7 @@ class BaseScapyTest(NetTestCase):
 
         scapySender.stopSending()
         for sent_packet in packets:
-            self.report['sent_packets'].append(_representPacket(sent_packet))
+            self.report['sent_packets'].append(representPacket(sent_packet))
 
 
 ScapyTest = BaseScapyTest



_______________________________________________
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to