Various fixes for auth tests with old mongos versions.

This commit is contained in:
Bernie Hackett 2014-05-02 15:24:32 -07:00
parent 352a5f6231
commit becc359cad
5 changed files with 20 additions and 7 deletions

View File

@ -704,6 +704,11 @@ class Database(common.BaseObject):
# See SERVER-4225 for more information.
if 'login' in str(exc):
pass
# First admin user add fails gle from mongos 2.0.x
# and 2.2.x.
elif (exc.details and
'getlasterror' in exc.details.get('note', '')):
pass
else:
raise

View File

@ -1067,7 +1067,7 @@ class MongoClient(common.BaseObject):
# for some errors.
if "errObjects" in result:
for errobj in result["errObjects"]:
if errobj["err"] == error_msg:
if errobj.get("err") == error_msg:
details = errobj
break

View File

@ -220,6 +220,9 @@ class TestClient(unittest.TestCase, TestRequestMixin):
# from a master in a master-slave pair.
if server_is_master_with_slave(c):
raise SkipTest("SERVER-2329")
if (not version.at_least(c, (2, 6, 0)) and
is_mongos(c) and server_started_with_auth(c)):
raise SkipTest("Need mongos >= 2.6.0 to test with authentication")
# We test copy twice; once starting in a request and once not. In
# either case the copy should succeed (because it starts a request
# internally) and should leave us in the same state as before the copy.
@ -256,8 +259,7 @@ class TestClient(unittest.TestCase, TestRequestMixin):
self.assertEqual("bar", c.pymongo_test2.test.find_one()["foo"])
# See SERVER-6427 for mongos
if (version.at_least(c, (1, 3, 3, 1)) and
not is_mongos(c) and server_started_with_auth(c)):
if not is_mongos(c) and server_started_with_auth(c):
c.drop_database("pymongo_test1")

View File

@ -594,7 +594,10 @@ class TestCollection(unittest.TestCase):
db.drop_collection("test")
if version.at_least(db.connection, (1, 9)):
db.create_collection("test", capped=True, size=4096)
self.assertEqual(db.test.options(), {"capped": True, 'size': 4096})
result = db.test.options()
# mongos 2.2.x adds an $auth field when auth is enabled.
result.pop('$auth', None)
self.assertEqual(result, {"capped": True, 'size': 4096})
else:
db.create_collection("test", capped=True)
self.assertEqual(db.test.options(), {"capped": True})

View File

@ -111,7 +111,10 @@ class TestDatabase(unittest.TestCase):
db.drop_collection("test.foo")
db.create_collection("test.foo")
self.assertTrue(u("test.foo") in db.collection_names())
self.assertEqual(db.test.foo.options(), {})
result = db.test.foo.options()
# mongos 2.2.x adds an $auth field when auth is enabled.
result.pop('$auth', None)
self.assertEqual(result, {})
self.assertRaises(CollectionInvalid, db.create_collection, "test.foo")
def test_collection_names(self):
@ -581,8 +584,8 @@ class TestDatabase(unittest.TestCase):
def test_authenticate_multiple(self):
client = get_client()
if (is_mongos(client) and not
version.at_least(self.client, (2, 0, 0))):
raise SkipTest("Auth with sharding requires MongoDB >= 2.0.0")
version.at_least(self.client, (2, 2, 0))):
raise SkipTest("Need mongos >= 2.2.0")
if not server_started_with_auth(client):
raise SkipTest("Authentication is not enabled on server")