From f05e800820a43d0c66c3e1c9c93efc6eb2815ca2 Mon Sep 17 00:00:00 2001 From: "A. Jesse Jiryu Davis" Date: Thu, 23 Apr 2015 15:24:23 -0400 Subject: [PATCH] Fix test_auth_network_error for replsets. We added a user then tried to admin with a disconnected client. During reconnect it may try to log in with a secondary, which hasn't always replicated the credentials yet. This change uses the global test creds instead of creating new ones, so replication doesn't confound the test. --- test/test_auth.py | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/test/test_auth.py b/test/test_auth.py index 434193e22..983a73531 100644 --- a/test/test_auth.py +++ b/test/test_auth.py @@ -1005,36 +1005,29 @@ class TestReplicaSetClientAuth(TestReplicaSetClientBase, TestRequestMixin): def test_auth_network_error(self): # Make sure there's no semaphore leak if we get a network error # when authenticating a new socket with cached credentials. - auth_client = self._get_client() + # Get a client with one socket so we detect if it's leaked. + c = self._get_client(max_pool_size=1, waitQueueTimeoutMS=1) - auth_context.client.admin.add_user('admin', 'password') - auth_client.admin.authenticate('admin', 'password') - try: - # Get a client with one socket so we detect if it's leaked. - c = self._get_client(max_pool_size=1, waitQueueTimeoutMS=1) + # Simulate an authenticate() call on a different socket. + credentials = auth._build_credentials_tuple( + 'DEFAULT', 'admin', + unicode(db_user), unicode(db_pwd), + {}) - # Simulate an authenticate() call on a different socket. - credentials = auth._build_credentials_tuple( - 'DEFAULT', 'admin', - unicode('admin'), unicode('password'), - {}) + c._cache_credentials('test', credentials, connect=False) - c._cache_credentials('test', credentials, connect=False) + # Cause a network error on the actual socket. + pool = get_pool(c) + socket_info = one(pool.sockets) + socket_info.sock.close() - # Cause a network error on the actual socket. - pool = get_pool(c) - socket_info = one(pool.sockets) - socket_info.sock.close() + # In __check_auth, the client authenticates its socket with the + # new credential, but gets a socket.error. Should be reraised as + # AutoReconnect. + self.assertRaises(AutoReconnect, c.test.collection.find_one) - # In __check_auth, the client authenticates its socket with the - # new credential, but gets a socket.error. Should be reraised as - # AutoReconnect. - self.assertRaises(AutoReconnect, c.test.collection.find_one) - - # No semaphore leak, the pool is allowed to make a new socket. - c.test.collection.find_one() - finally: - auth_client.admin.remove_user('admin') + # No semaphore leak, the pool is allowed to make a new socket. + c.test.collection.find_one() class TestBulkAuthorization(BulkTestBase):