[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Support CIRC event's new SOCKS_USERNAME and SOCKS_PASSWORD attributes



commit 4b8825482e0fd3dd4061a2b57473a4622e34d120
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Feb 23 12:19:40 2015 -0800

    Support CIRC event's new SOCKS_USERNAME and SOCKS_PASSWORD attributes
    
    Adding support for the new controller attributes discussed in #14555.
---
 docs/change_log.rst          |    1 +
 stem/response/events.py      |   11 ++++++++++-
 test/unit/response/events.py |   23 +++++++++++++++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/docs/change_log.rst b/docs/change_log.rst
index af883ce..7143655 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -52,6 +52,7 @@ conversion (:trac:`14075`).
  * **Controller**
 
   * :func:`~stem.process.launch_tor_with_config` avoids writing a temporary torrc to disk if able (:trac:`13865`)
+  * :class:`~stem.response.events.CircuitEvent` support for the new SOCKS_USERNAME and SOCKS_PASSWORD arguments (:trac:`14555`, :spec:`2975974`)
   * The 'strict' argument of :func:`~stem.exit_policy.ExitPolicy.can_exit_to` didn't behave as documented (:trac:`14314`)
 
  * **Descriptors**
diff --git a/stem/response/events.py b/stem/response/events.py
index af205bd..cdf0ba7 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -326,6 +326,11 @@ class CircuitEvent(Event):
   The CIRC event was one of the first Control Protocol V1 events and was
   introduced in tor version 0.1.1.1-alpha.
 
+  .. versionchanged:: 1.4.0
+     Added the socks_username and socks_password attributes which is used for
+     `stream isolation
+     <https://gitweb.torproject.org/torspec.git/tree/proposals/171-separate-streams.txt>`_.
+
   :var str id: circuit identifier
   :var stem.CircStatus status: reported status for the circuit
   :var tuple path: relays involved in the circuit, these are
@@ -338,6 +343,8 @@ class CircuitEvent(Event):
   :var datetime created: time when the circuit was created or cannibalized
   :var stem.CircClosureReason reason: reason for the circuit to be closed
   :var stem.CircClosureReason remote_reason: remote side's reason for the circuit to be closed
+  :var str socks_username: username for using this circuit
+  :var str socks_password: password for using this circuit
   """
 
   _POSITIONAL_ARGS = ('id', 'status', 'path')
@@ -349,6 +356,8 @@ class CircuitEvent(Event):
     'TIME_CREATED': 'created',
     'REASON': 'reason',
     'REMOTE_REASON': 'remote_reason',
+    'SOCKS_USERNAME': 'socks_username',
+    'SOCKS_PASSWORD': 'socks_password',
   }
 
   def _parse(self):
@@ -377,7 +386,7 @@ class CircuitEvent(Event):
     if not isinstance(other, CircuitEvent):
       return False
 
-    for attr in ('id', 'status', 'path', 'build_flags', 'purpose', 'hs_state', 'rend_query', 'created', 'reason', 'remote_reason'):
+    for attr in ('id', 'status', 'path', 'build_flags', 'purpose', 'hs_state', 'rend_query', 'created', 'reason', 'remote_reason', 'socks_username', 'socks_port'):
       my_attr = getattr(self, attr)
       other_attr = getattr(other, attr)
 
diff --git a/test/unit/response/events.py b/test/unit/response/events.py
index 2e5ef50..c4d0ac8 100644
--- a/test/unit/response/events.py
+++ b/test/unit/response/events.py
@@ -109,6 +109,10 @@ TIME_CREATED=2012-11-08T16:48:36.400959 \
 REASON=DESTROYED \
 REMOTE_REASON=OR_CONN_CLOSED'
 
+CIRC_WITH_CREDENTIALS = '650 CIRC 7 LAUNCHED \
+SOCKS_USERNAME="It\'s a me, Mario!" \
+SOCKS_PASSWORD="your princess is in another castle"'
+
 # CIRC events from tor v0.2.1.30 without the VERBOSE_NAMES feature
 
 CIRC_LAUNCHED_OLD = '650 CIRC 4 LAUNCHED'
@@ -561,6 +565,8 @@ class TestEvents(unittest.TestCase):
     self.assertEqual(datetime.datetime(2012, 11, 8, 16, 48, 38, 417238), event.created)
     self.assertEqual(None, event.reason)
     self.assertEqual(None, event.remote_reason)
+    self.assertEqual(None, event.socks_username)
+    self.assertEqual(None, event.socks_password)
 
     event = _get_event(CIRC_EXTENDED)
 
@@ -592,6 +598,23 @@ class TestEvents(unittest.TestCase):
     self.assertEqual(CircClosureReason.DESTROYED, event.reason)
     self.assertEqual(CircClosureReason.OR_CONN_CLOSED, event.remote_reason)
 
+    event = _get_event(CIRC_WITH_CREDENTIALS)
+
+    self.assertTrue(isinstance(event, stem.response.events.CircuitEvent))
+    self.assertEqual(CIRC_WITH_CREDENTIALS.lstrip('650 '), str(event))
+    self.assertEqual('7', event.id)
+    self.assertEqual(CircStatus.LAUNCHED, event.status)
+    self.assertEqual((), event.path)
+    self.assertEqual(None, event.build_flags)
+    self.assertEqual(None, event.purpose)
+    self.assertEqual(None, event.hs_state)
+    self.assertEqual(None, event.rend_query)
+    self.assertEqual(None, event.created)
+    self.assertEqual(None, event.reason)
+    self.assertEqual(None, event.remote_reason)
+    self.assertEqual("It's a me, Mario!", event.socks_username)
+    self.assertEqual('your princess is in another castle', event.socks_password)
+
     event = _get_event(CIRC_LAUNCHED_OLD)
 
     self.assertTrue(isinstance(event, stem.response.events.CircuitEvent))

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