commit f1b81e062c2b1ec646f99b346b98dd3d4ec38057 Author: Sean Robinson seankrobinson@gmail.com Date: Fri Dec 14 14:30:40 2012 -0700
Test error conditions for ADDRMAP events
Add tests for missing quotes before (ADDRMAP_BAD_1) and after (ADDRMAP_BAD_2) the expiry positional argument. Add a test for an error event (ADDRMAP_BAD_3), constructed from control-spec.txt. Also, move the sample event lines to their alphabetic position in the list of other event samples.
Signed-off-by: Sean Robinson seankrobinson@gmail.com --- test/unit/response/events.py | 30 ++++++++++++++++++++++++------ 1 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/test/unit/response/events.py b/test/unit/response/events.py index 91eaa18..5422f50 100644 --- a/test/unit/response/events.py +++ b/test/unit/response/events.py @@ -13,6 +13,17 @@ import stem.util.log from stem import * # enums and exceptions from test import mocking
+# ADDRMAP event + +ADDRMAP = '650 ADDRMAP www.atagar.com 75.119.206.243 "2012-11-19 00:50:13" \ +EXPIRES="2012-11-19 08:50:13"' +ADDRMAP_BAD_1 = '650 ADDRMAP www.atagar.com 75.119.206.243 2012-11-19 00:50:13" \ +EXPIRES="2012-11-19 08:50:13"' +ADDRMAP_BAD_2 = '650 ADDRMAP www.atagar.com 75.119.206.243 "2012-11-19 00:50:13 \ +EXPIRES="2012-11-19 08:50:13"' +ADDRMAP_BAD_3 = '650 ADDRMAP www.atagar.com <error> "2012-11-19 00:50:13" \ +error=yes EXPIRES="2012-11-19 08:50:13"' + # BUILDTIMEOUT_SET event from tor 0.2.3.16.
BUILD_TIMEOUT_EVENT = "650 BUILDTIMEOUT_SET COMPUTED \ @@ -193,12 +204,6 @@ NEWDESC_SINGLE = "650 NEWDESC $B3FA3110CC6F42443F039220C134CBD2FC4F0493=Sakura" NEWDESC_MULTIPLE = "650 NEWDESC $BE938957B2CA5F804B3AFC2C1EE6673170CDBBF8=Moonshine \ $B4BE08B22D4D2923EDC3970FD1B93D0448C6D8FF~Unnamed"
-# ADDRMAP event -# TODO: it would be nice to have an example of an error event - -ADDRMAP = '650 ADDRMAP www.atagar.com 75.119.206.243 "2012-11-19 00:50:13" \ -EXPIRES="2012-11-19 08:50:13"' - def _get_event(content): controller_event = mocking.get_message(content) stem.response.convert("EVENT", controller_event, arrived_at = 25) @@ -274,6 +279,19 @@ class TestEvents(unittest.TestCase): self.assertEqual(datetime.datetime(2012, 11, 19, 0, 50, 13), event.expiry) self.assertEqual(None, event.error) self.assertEqual(datetime.datetime(2012, 11, 19, 8, 50, 13), event.utc_expiry) + + self.assertRaises(ProtocolError, _get_event, ADDRMAP_BAD_1) + self.assertRaises(ProtocolError, _get_event, ADDRMAP_BAD_2) + + event = _get_event(ADDRMAP_BAD_3) + + self.assertTrue(isinstance(event, stem.response.events.AddrMapEvent)) + self.assertEqual(ADDRMAP_BAD_3.lstrip("650 "), str(event)) + self.assertEqual("www.atagar.com", event.hostname) + self.assertEqual(None, event.destination) + self.assertEqual(datetime.datetime(2012, 11, 19, 0, 50, 13), event.expiry) + self.assertEqual("yes", event.error) + self.assertEqual(datetime.datetime(2012, 11, 19, 8, 50, 13), event.utc_expiry)
def test_authdir_newdesc_event(self): # TODO: awaiting test data - https://trac.torproject.org/7534