diff options
author | matt dannenberg <matt.dannenberg@10gen.com> | 2015-11-13 05:52:16 -0500 |
---|---|---|
committer | matt dannenberg <matt.dannenberg@10gen.com> | 2015-11-13 08:27:31 -0500 |
commit | 5980c09739ad203916a4604ee8533ea5aacf58e9 (patch) | |
tree | 3e498ba8d2765e1d5258f38c9aba1a696845e467 /src | |
parent | 9e431f4fd9a6af65292aff3729a3f6d281784ac1 (diff) | |
download | mongo-5980c09739ad203916a4604ee8533ea5aacf58e9.tar.gz |
SERVER-21447 reject configs with protocolversions other than 0 and 1
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/repl/replica_set_config.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/repl/replica_set_config_test.cpp | 19 |
2 files changed, 19 insertions, 4 deletions
diff --git a/src/mongo/db/repl/replica_set_config.cpp b/src/mongo/db/repl/replica_set_config.cpp index 106e8329473..2e83b80a000 100644 --- a/src/mongo/db/repl/replica_set_config.cpp +++ b/src/mongo/db/repl/replica_set_config.cpp @@ -422,10 +422,10 @@ Status ReplicaSetConfig::validate() const { } } - if (_protocolVersion < 0 || _protocolVersion > std::numeric_limits<int>::max()) { + if (_protocolVersion != 0 && _protocolVersion != 1) { return Status(ErrorCodes::BadValue, str::stream() << kProtocolVersionFieldName << " field value of " - << _protocolVersion << " is out of range"); + << _protocolVersion << " is not 1 or 0"); } if (_configServer) { diff --git a/src/mongo/db/repl/replica_set_config_test.cpp b/src/mongo/db/repl/replica_set_config_test.cpp index 5ec17940e65..4e264f34046 100644 --- a/src/mongo/db/repl/replica_set_config_test.cpp +++ b/src/mongo/db/repl/replica_set_config_test.cpp @@ -89,7 +89,7 @@ TEST(ReplicaSetConfig, ParseLargeConfigAndCheckAccessors) { << "localhost:12345" << "tags" << BSON("NYC" << "NY"))) - << "protocolVersion" << 2 << "settings" + << "protocolVersion" << 1 << "settings" << BSON("getLastErrorDefaults" << BSON("w" << "majority") << "getLastErrorModes" << BSON("eastCoast" << BSON("NYC" << 1)) << "chainingAllowed" @@ -108,7 +108,7 @@ TEST(ReplicaSetConfig, ParseLargeConfigAndCheckAccessors) { ASSERT_EQUALS(Seconds(5), config.getHeartbeatInterval()); ASSERT_EQUALS(Seconds(120), config.getHeartbeatTimeoutPeriod()); ASSERT_EQUALS(Milliseconds(10), config.getElectionTimeoutPeriod()); - ASSERT_EQUALS(2, config.getProtocolVersion()); + ASSERT_EQUALS(1, config.getProtocolVersion()); } TEST(ReplicaSetConfig, MajorityCalculationThreeVotersNoArbiters) { @@ -645,6 +645,21 @@ TEST(ReplicaSetConfig, ParseFailsWithNonExistentGetLastErrorModesConstraintTag) ASSERT_EQUALS(ErrorCodes::NoSuchKey, status); } +TEST(ReplicaSetConfig, ValidateFailsWithBadProtocolVersion) { + ReplicaSetConfig config; + Status status = config.initialize(BSON("_id" + << "rs0" + << "protocolVersion" << 3 << "version" << 1 << "members" + << BSON_ARRAY(BSON("_id" << 0 << "host" + << "localhost:12345") + << BSON("_id" << 1 << "host" + << "localhost:54321")))); + ASSERT_OK(status); + + status = config.validate(); + ASSERT_EQUALS(ErrorCodes::BadValue, status); +} + TEST(ReplicaSetConfig, ValidateFailsWithDuplicateMemberId) { ReplicaSetConfig config; Status status = config.initialize(BSON("_id" |