[tor-commits] [stem/master] Integ test for general auth's password arg
atagar at torproject.org
atagar at torproject.org
Wed Dec 21 18:02:41 UTC 2011
commit 22e64d083ee9a7f15e3f7333477c9c9dde7609cc
Author: Damian Johnson <atagar at torproject.org>
Date: Wed Dec 21 09:37:52 2011 -0800
Integ test for general auth's password arg
Testing the various use cases for a password argument (missing argument,
incorrect password, and correct password). When we're running connection tests
with something other than password auth this is a very dull test (since we
succeed without raising a password exception), but when we just have a
HashedControlPassword this is a decent test.
---
test/integ/connection/authentication.py | 42 +++++++++++++++++++++++++++++++
1 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/test/integ/connection/authentication.py b/test/integ/connection/authentication.py
index 282a377..a79cbb0 100644
--- a/test/integ/connection/authentication.py
+++ b/test/integ/connection/authentication.py
@@ -81,6 +81,48 @@ class TestAuthenticate(unittest.TestCase):
finally:
control_socket.close()
+ def test_authenticate_general_password(self):
+ """
+ Tests the authenticate function's password argument.
+ """
+
+ # this is a much better test if we're just using password auth, since
+ # authenticate will work reguardless if there's something else to
+ # authenticate with
+
+ runner = test.runner.get_runner()
+ is_password_only = test.runner.TorConnection.PASSWORD == runner.get_connection_type()
+
+ # tests without a password
+ control_socket = runner.get_tor_socket(False)
+ auth_function = functools.partial(stem.connection.authenticate, control_socket)
+
+ if is_password_only:
+ self.assertRaises(stem.connection.MissingPassword, auth_function)
+ else:
+ auth_function()
+ self._exercise_socket(control_socket)
+
+ control_socket.close()
+
+ # tests with the incorrect password
+ control_socket = runner.get_tor_socket(False)
+ auth_function = functools.partial(stem.connection.authenticate, control_socket, "blarg")
+
+ if is_password_only:
+ self.assertRaises(stem.connection.IncorrectPassword, auth_function)
+ else:
+ auth_function()
+ self._exercise_socket(control_socket)
+
+ control_socket.close()
+
+ # tests with the right password
+ control_socket = runner.get_tor_socket(False)
+ stem.connection.authenticate(control_socket, test.runner.CONTROL_PASSWORD)
+ self._exercise_socket(control_socket)
+ control_socket.close()
+
def test_authenticate_none(self):
"""
Tests the authenticate_none function.
More information about the tor-commits
mailing list