Skip to content

Commit 491784c

Browse files
spencerjacksonamidvidy
authored andcommitted
CXX-440 Fix tests for 2.2
1 parent e240e06 commit 491784c

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/mongo/client/examples/authTest.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@
3131

3232
using namespace mongo;
3333

34+
bool serverLTE(DBClientBase* c, int major, int minor) {
35+
BSONObj result;
36+
c->runCommand("admin", BSON("buildinfo" << true), result);
37+
38+
std::vector<BSONElement> version = result.getField("versionArray").Array();
39+
int serverMajor = version[0].Int();
40+
int serverMinor = version[1].Int();
41+
42+
return (serverMajor <= major && serverMinor <= minor);
43+
}
44+
45+
3446
int main( int argc, const char **argv ) {
3547

3648
using std::cout;
@@ -95,9 +107,15 @@ int main( int argc, const char **argv ) {
95107
return EXIT_FAILURE;
96108
}
97109

98-
if (conn->auth("test", "eliot", "bars", errmsg)) { // incorrect password
99-
cout << "Authentication with invalid password should have failed but didn't" << endl;
100-
return EXIT_FAILURE;
110+
try {
111+
if (conn->auth("test", "eliot", "bars", errmsg)) { // incorrect password
112+
cout << "Authentication with invalid password should have failed but didn't" << endl;
113+
return EXIT_FAILURE;
114+
}
115+
} catch (const DBException&) {
116+
//Expected on v2.2 and below
117+
assert(serverLTE(conn.get(), 2, 2));
101118
}
119+
102120
return EXIT_SUCCESS;
103121
}

src/mongo/integration/replica_set/read_preference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ namespace {
9494

9595
void count(const auto_ptr<DBClientReplicaSet>& test_conn, ReadPreference rp) {
9696
Query q = Query().readPref(rp, BSONArray());
97-
test_conn->count(TEST_NS, q);
97+
test_conn->count(TEST_NS, q, QueryOption_SlaveOk);
9898
}
9999

100100
void distinct(const auto_ptr<DBClientReplicaSet>& test_conn, ReadPreference rp) {

src/mongo/integration/standalone/dbclient_test.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,11 @@ namespace {
14141414
if (serverGTE(&c, 2, 4) && (!serverGTE(&c, 2, 7) || kCompiledWithSSL)) {
14151415
createUser(c, TEST_DB, "user3", "password3");
14161416
std::string errmsg;
1417-
ASSERT_FALSE(c.auth("test", "user3", "notPassword3", errmsg));
1417+
try {
1418+
ASSERT_FALSE(c.auth("test", "user3", "notPassword3", errmsg));
1419+
} catch (const DBException&) {
1420+
//Expected on 2.2
1421+
}
14181422
}
14191423
}
14201424

0 commit comments

Comments
 (0)