[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Add test cases for STREAM events
commit b3aca85301439fd2441d098775b9c56d7365c506
Author: Sean Robinson <seankrobinson@xxxxxxxxx>
Date: Fri Dec 14 16:28:25 2012 -0700
Add test cases for STREAM events
These test events exercise all the exceptions in StreamEvent._parse()
and the case of an empty target address:port.
Signed-off-by: Sean Robinson <seankrobinson@xxxxxxxxx>
---
test/unit/response/events.py | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/test/unit/response/events.py b/test/unit/response/events.py
index 7fb39c6..bda2d5a 100644
--- a/test/unit/response/events.py
+++ b/test/unit/response/events.py
@@ -295,6 +295,19 @@ STREAM_DNS_REQUEST = "650 STREAM 1113 NEW 0 www.google.com:0 \
SOURCE_ADDR=127.0.0.1:15297 \
PURPOSE=DNS_REQUEST"
+STREAM_SENTCONNECT_BAD_1 = "650 STREAM 18 SENTCONNECT 26"
+STREAM_SENTCONNECT_BAD_2 = "650 STREAM 18 SENTCONNECT 26 encrypted.google.com"
+STREAM_SENTCONNECT_BAD_3 = "650 STREAM 18 SENTCONNECT 26 encrypted.google.com:https"
+
+STREAM_DNS_REQUEST_BAD_1 = "650 STREAM 1113 NEW 0 www.google.com:0 \
+SOURCE_ADDR=127.0.0.1 \
+PURPOSE=DNS_REQUEST"
+
+STREAM_DNS_REQUEST_BAD_2 = "650 STREAM 1113 NEW 0 www.google.com:0 \
+SOURCE_ADDR=127.0.0.1:dns \
+PURPOSE=DNS_REQUEST"
+
+
def _get_event(content):
controller_event = mocking.get_message(content)
stem.response.convert("EVENT", controller_event, arrived_at = 25)
@@ -1023,6 +1036,29 @@ class TestEvents(unittest.TestCase):
self.assertEqual("127.0.0.1", event.source_address)
self.assertEqual(15297, event.source_port)
self.assertEqual(StreamPurpose.DNS_REQUEST, event.purpose)
+
+ event = _get_event(STREAM_SENTCONNECT_BAD_1)
+
+ self.assertTrue(isinstance(event, stem.response.events.StreamEvent))
+ self.assertEqual(STREAM_SENTCONNECT_BAD_1.lstrip("650 "), str(event))
+ self.assertEqual("18", event.id)
+ self.assertEqual(StreamStatus.SENTCONNECT, event.status)
+ self.assertEqual("26", event.circ_id)
+ self.assertEqual(None, event.target)
+ self.assertEqual(None, event.target_address)
+ self.assertEqual(None, event.target_port)
+ self.assertEqual(None, event.reason)
+ self.assertEqual(None, event.remote_reason)
+ self.assertEqual(None, event.source)
+ self.assertEqual(None, event.source_addr)
+ self.assertEqual(None, event.source_address)
+ self.assertEqual(None, event.source_port)
+ self.assertEqual(None, event.purpose)
+
+ self.assertRaises(ProtocolError, _get_event, STREAM_SENTCONNECT_BAD_2)
+ self.assertRaises(ProtocolError, _get_event, STREAM_SENTCONNECT_BAD_3)
+ self.assertRaises(ProtocolError, _get_event, STREAM_DNS_REQUEST_BAD_1)
+ self.assertRaises(ProtocolError, _get_event, STREAM_DNS_REQUEST_BAD_2)
def test_stream_bw_event(self):
event = _get_event("650 STREAM_BW 2 15 25")
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits