Skip to content

Commit f05e800

Browse files
committed
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.
1 parent 18711ca commit f05e800

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

test/test_auth.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,36 +1005,29 @@ def test_copy_db(self):
10051005
def test_auth_network_error(self):
10061006
# Make sure there's no semaphore leak if we get a network error
10071007
# when authenticating a new socket with cached credentials.
1008-
auth_client = self._get_client()
1008+
# Get a client with one socket so we detect if it's leaked.
1009+
c = self._get_client(max_pool_size=1, waitQueueTimeoutMS=1)
10091010

1010-
auth_context.client.admin.add_user('admin', 'password')
1011-
auth_client.admin.authenticate('admin', 'password')
1012-
try:
1013-
# Get a client with one socket so we detect if it's leaked.
1014-
c = self._get_client(max_pool_size=1, waitQueueTimeoutMS=1)
1011+
# Simulate an authenticate() call on a different socket.
1012+
credentials = auth._build_credentials_tuple(
1013+
'DEFAULT', 'admin',
1014+
unicode(db_user), unicode(db_pwd),
1015+
{})
10151016

1016-
# Simulate an authenticate() call on a different socket.
1017-
credentials = auth._build_credentials_tuple(
1018-
'DEFAULT', 'admin',
1019-
unicode('admin'), unicode('password'),
1020-
{})
1017+
c._cache_credentials('test', credentials, connect=False)
10211018

1022-
c._cache_credentials('test', credentials, connect=False)
1019+
# Cause a network error on the actual socket.
1020+
pool = get_pool(c)
1021+
socket_info = one(pool.sockets)
1022+
socket_info.sock.close()
10231023

1024-
# Cause a network error on the actual socket.
1025-
pool = get_pool(c)
1026-
socket_info = one(pool.sockets)
1027-
socket_info.sock.close()
1024+
# In __check_auth, the client authenticates its socket with the
1025+
# new credential, but gets a socket.error. Should be reraised as
1026+
# AutoReconnect.
1027+
self.assertRaises(AutoReconnect, c.test.collection.find_one)
10281028

1029-
# In __check_auth, the client authenticates its socket with the
1030-
# new credential, but gets a socket.error. Should be reraised as
1031-
# AutoReconnect.
1032-
self.assertRaises(AutoReconnect, c.test.collection.find_one)
1033-
1034-
# No semaphore leak, the pool is allowed to make a new socket.
1035-
c.test.collection.find_one()
1036-
finally:
1037-
auth_client.admin.remove_user('admin')
1029+
# No semaphore leak, the pool is allowed to make a new socket.
1030+
c.test.collection.find_one()
10381031

10391032

10401033
class TestBulkAuthorization(BulkTestBase):

0 commit comments

Comments
 (0)