[tor-commits] [stem/master] Defining when auth success should occur
atagar at torproject.org
atagar at torproject.org
Tue Dec 27 00:56:42 UTC 2011
commit a7772f8c62957ea46db7c3aa012c0ba6b018a3d0
Author: Damian Johnson <atagar at torproject.org>
Date: Mon Dec 26 16:53:20 2011 -0800
Defining when auth success should occur
Specifying in the general auth unit tests when authentication should succeed or
fail. I'd wanted to also check for the highest priority exception but after
messing with this quite a bit I'm waiving the white flag. This is decent
enough...
---
test/unit/connection/authentication.py | 21 +++++++++++++++------
1 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/test/unit/connection/authentication.py b/test/unit/connection/authentication.py
index bae723f..729e6c7 100644
--- a/test/unit/connection/authentication.py
+++ b/test/unit/connection/authentication.py
@@ -29,6 +29,7 @@ def get_protocolinfo(auth_methods):
protocolinfo_response = stem.socket.recv_message(StringIO.StringIO(control_message))
stem.connection.ProtocolInfoResponse.convert(protocolinfo_response)
protocolinfo_response.auth_methods = auth_methods
+ protocolinfo_response.cookie_path = "/tmp/blah"
return lambda *args: protocolinfo_response
def _get_all_auth_method_combinations():
@@ -135,11 +136,19 @@ class TestAuthenticate(unittest.TestCase):
stem.connection.authenticate_password = raise_exception(auth_password_exc)
stem.connection.authenticate_cookie = raise_exception(auth_cookie_exc)
- # calling authenticate should either succeed or raise a
- # AuthenticationFailure subclass
+ auth_tuple_set = (
+ (stem.connection.AuthMethod.NONE, auth_none_exc),
+ (stem.connection.AuthMethod.PASSWORD, auth_password_exc),
+ (stem.connection.AuthMethod.COOKIE, auth_cookie_exc))
- try:
- stem.connection.authenticate(None, protocolinfo_response = protocolinfo_input)
- except stem.connection.AuthenticationFailure:
- pass
+ expect_success = False
+ for auth_type, auth_exc in auth_tuple_set:
+ if auth_type in auth_methods and not auth_exc:
+ expect_success = True
+ break
+
+ if expect_success:
+ stem.connection.authenticate(None, "blah", protocolinfo_input)
+ else:
+ self.assertRaises(stem.connection.AuthenticationFailure, stem.connection.authenticate, None, "blah", protocolinfo_input)
More information about the tor-commits
mailing list