[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Allowing zero Terget port in STREAM events
commit 4959378f9aa83d96bc1431d72bea6fa7a1b6e2c7
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sun Dec 2 11:51:34 2012 -0800
Allowing zero Terget port in STREAM events
The STREAM event's target port can be zero in DNS_REQUEST requests. Caught
thanks to robinson on...
https://trac.torproject.org/7598
---
stem/response/events.py | 2 +-
test/unit/response/events.py | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/stem/response/events.py b/stem/response/events.py
index 96764a0..598f8d1 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -497,7 +497,7 @@ class StreamEvent(Event):
address, port = self.target.split(':', 1)
- if not connection.is_valid_port(port):
+ if not connection.is_valid_port(port, allow_zero = True):
raise stem.ProtocolError("Target location's port is invalid: %s" % self)
self.target_address = address
diff --git a/test/unit/response/events.py b/test/unit/response/events.py
index 54d4777..57a3f58 100644
--- a/test/unit/response/events.py
+++ b/test/unit/response/events.py
@@ -113,6 +113,10 @@ STREAM_DIR_FETCH = "650 STREAM 14 NEW 0 \
176.28.51.238.$649F2D0ACF418F7CFC6539AB2257EB2D5297BAFA.exit:443 \
SOURCE_ADDR=(Tor_internal):0 PURPOSE=DIR_FETCH"
+STREAM_DNS_REQUEST = "650 STREAM 1113 NEW 0 www.google.com:0 \
+SOURCE_ADDR=127.0.0.1:15297 \
+PURPOSE=DNS_REQUEST"
+
# ORCONN events from starting tor 0.2.2.39 via TBB
ORCONN_CONNECTED = "650 ORCONN $7ED90E2833EE38A75795BA9237B0A4560E51E1A0=GreenDragon CONNECTED"
@@ -670,4 +674,22 @@ class TestEvents(unittest.TestCase):
self.assertEqual("(Tor_internal)", event.source_address)
self.assertEqual(0, event.source_port)
self.assertEqual(StreamPurpose.DIR_FETCH, event.purpose)
+
+ event = _get_event(STREAM_DNS_REQUEST)
+
+ self.assertTrue(isinstance(event, stem.response.events.StreamEvent))
+ self.assertEqual(STREAM_DNS_REQUEST.lstrip("650 "), str(event))
+ self.assertEqual("1113", event.id)
+ self.assertEqual(StreamStatus.NEW, event.status)
+ self.assertEqual(None, event.circ_id)
+ self.assertEqual("www.google.com:0", event.target)
+ self.assertEqual("www.google.com", event.target_address)
+ self.assertEqual(0, event.target_port)
+ self.assertEqual(None, event.reason)
+ self.assertEqual(None, event.remote_reason)
+ self.assertEqual(None, event.source)
+ self.assertEqual("127.0.0.1:15297", event.source_addr)
+ self.assertEqual("127.0.0.1", event.source_address)
+ self.assertEqual(15297, event.source_port)
+ self.assertEqual(StreamPurpose.DNS_REQUEST, event.purpose)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits