diff options
Diffstat (limited to 'src/mongo/rpc')
-rw-r--r-- | src/mongo/rpc/command_request.cpp | 17 | ||||
-rw-r--r-- | src/mongo/rpc/command_request_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/rpc/legacy_reply.cpp | 11 | ||||
-rw-r--r-- | src/mongo/rpc/legacy_reply.h | 2 | ||||
-rw-r--r-- | src/mongo/rpc/legacy_request_builder.cpp | 2 | ||||
-rw-r--r-- | src/mongo/rpc/metadata.cpp | 2 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/audit_metadata.h | 4 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/config_server_metadata.cpp | 4 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/repl_set_metadata_test.cpp | 10 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/server_selection_metadata.cpp | 10 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/server_selection_metadata_test.cpp | 41 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/sharding_metadata_test.cpp | 49 | ||||
-rw-r--r-- | src/mongo/rpc/object_check.h | 2 | ||||
-rw-r--r-- | src/mongo/rpc/object_check_test.cpp | 5 | ||||
-rw-r--r-- | src/mongo/rpc/protocol.cpp | 6 | ||||
-rw-r--r-- | src/mongo/rpc/protocol_test.cpp | 7 | ||||
-rw-r--r-- | src/mongo/rpc/reply_builder_test.cpp | 6 |
17 files changed, 115 insertions, 65 deletions
diff --git a/src/mongo/rpc/command_request.cpp b/src/mongo/rpc/command_request.cpp index 577c3a27349..9a27ac45512 100644 --- a/src/mongo/rpc/command_request.cpp +++ b/src/mongo/rpc/command_request.cpp @@ -74,8 +74,11 @@ CommandRequest::CommandRequest(const Message* message) : _message(message) { uassert(28636, str::stream() << "Database parsed in OP_COMMAND message must be between" - << kMinDatabaseLength << " and " << kMaxDatabaseLength - << " bytes. Got: " << _database, + << kMinDatabaseLength + << " and " + << kMaxDatabaseLength + << " bytes. Got: " + << _database, (_database.size() >= kMinDatabaseLength) && (_database.size() <= kMaxDatabaseLength)); uassert( @@ -88,8 +91,11 @@ CommandRequest::CommandRequest(const Message* message) : _message(message) { uassert(28637, str::stream() << "Command name parsed in OP_COMMAND message must be between" - << kMinCommandNameLength << " and " << kMaxCommandNameLength - << " bytes. Got: " << _database, + << kMinCommandNameLength + << " and " + << kMaxCommandNameLength + << " bytes. Got: " + << _database, (_commandName.size() >= kMinCommandNameLength) && (_commandName.size() <= kMaxCommandNameLength)); @@ -99,7 +105,8 @@ CommandRequest::CommandRequest(const Message* message) : _message(message) { uassert(39950, str::stream() << "Command name parsed in OP_COMMAND message '" << _commandName << "' doesn't match command name from object '" - << _commandArgs.firstElementFieldName() << '\'', + << _commandArgs.firstElementFieldName() + << '\'', _commandArgs.firstElementFieldName() == _commandName); uassertStatusOK(cur.readAndAdvance<>(&obj)); diff --git a/src/mongo/rpc/command_request_test.cpp b/src/mongo/rpc/command_request_test.cpp index 2dc944b7118..fece0b22352 100644 --- a/src/mongo/rpc/command_request_test.cpp +++ b/src/mongo/rpc/command_request_test.cpp @@ -36,8 +36,8 @@ #include "mongo/rpc/command_request.h" #include "mongo/rpc/command_request_builder.h" #include "mongo/unittest/unittest.h" -#include "mongo/util/net/message.h" #include "mongo/util/assert_util.h" +#include "mongo/util/net/message.h" namespace { diff --git a/src/mongo/rpc/legacy_reply.cpp b/src/mongo/rpc/legacy_reply.cpp index e298a97814f..e9af23dee9e 100644 --- a/src/mongo/rpc/legacy_reply.cpp +++ b/src/mongo/rpc/legacy_reply.cpp @@ -30,8 +30,8 @@ #include "mongo/rpc/legacy_reply.h" -#include <utility> #include <tuple> +#include <utility> #include "mongo/rpc/legacy_reply_builder.h" #include "mongo/rpc/metadata.h" @@ -51,17 +51,20 @@ LegacyReply::LegacyReply(const Message* message) : _message(std::move(message)) uassert(ErrorCodes::BadValue, str::stream() << "Got legacy command reply with a bad cursorId field," - << " expected a value of 0 but got " << qr.getCursorId(), + << " expected a value of 0 but got " + << qr.getCursorId(), qr.getCursorId() == 0); uassert(ErrorCodes::BadValue, str::stream() << "Got legacy command reply with a bad nReturned field," - << " expected a value of 1 but got " << qr.getNReturned(), + << " expected a value of 1 but got " + << qr.getNReturned(), qr.getNReturned() == 1); uassert(ErrorCodes::BadValue, str::stream() << "Got legacy command reply with a bad startingFrom field," - << " expected a value of 0 but got " << qr.getStartingFrom(), + << " expected a value of 0 but got " + << qr.getStartingFrom(), qr.getStartingFrom() == 0); std::tie(_commandReply, _metadata) = diff --git a/src/mongo/rpc/legacy_reply.h b/src/mongo/rpc/legacy_reply.h index 9e6fb8b0b79..bfb366f1da2 100644 --- a/src/mongo/rpc/legacy_reply.h +++ b/src/mongo/rpc/legacy_reply.h @@ -31,8 +31,8 @@ #include "mongo/db/dbmessage.h" #include "mongo/db/jsobj.h" #include "mongo/rpc/document_range.h" -#include "mongo/rpc/reply_interface.h" #include "mongo/rpc/protocol.h" +#include "mongo/rpc/reply_interface.h" namespace mongo { class Message; diff --git a/src/mongo/rpc/legacy_request_builder.cpp b/src/mongo/rpc/legacy_request_builder.cpp index c3a78803db3..c2155537611 100644 --- a/src/mongo/rpc/legacy_request_builder.cpp +++ b/src/mongo/rpc/legacy_request_builder.cpp @@ -30,8 +30,8 @@ #include "mongo/rpc/legacy_request_builder.h" -#include <utility> #include <tuple> +#include <utility> #include "mongo/db/namespace_string.h" #include "mongo/rpc/metadata.h" diff --git a/src/mongo/rpc/metadata.cpp b/src/mongo/rpc/metadata.cpp index 09d88d78d31..5c9a2a47a40 100644 --- a/src/mongo/rpc/metadata.cpp +++ b/src/mongo/rpc/metadata.cpp @@ -34,8 +34,8 @@ #include "mongo/db/jsobj.h" #include "mongo/rpc/metadata/audit_metadata.h" #include "mongo/rpc/metadata/config_server_metadata.h" -#include "mongo/rpc/metadata/sharding_metadata.h" #include "mongo/rpc/metadata/server_selection_metadata.h" +#include "mongo/rpc/metadata/sharding_metadata.h" namespace mongo { namespace rpc { diff --git a/src/mongo/rpc/metadata/audit_metadata.h b/src/mongo/rpc/metadata/audit_metadata.h index 44caeef87f0..b7519d3cbd7 100644 --- a/src/mongo/rpc/metadata/audit_metadata.h +++ b/src/mongo/rpc/metadata/audit_metadata.h @@ -32,9 +32,9 @@ #include <vector> #include "mongo/base/disallow_copying.h" -#include "mongo/db/operation_context.h" -#include "mongo/db/auth/user_name.h" #include "mongo/db/auth/role_name.h" +#include "mongo/db/auth/user_name.h" +#include "mongo/db/operation_context.h" namespace mongo { class BSONObj; diff --git a/src/mongo/rpc/metadata/config_server_metadata.cpp b/src/mongo/rpc/metadata/config_server_metadata.cpp index dae494bc505..bf8be47c641 100644 --- a/src/mongo/rpc/metadata/config_server_metadata.cpp +++ b/src/mongo/rpc/metadata/config_server_metadata.cpp @@ -63,7 +63,9 @@ StatusWith<ConfigServerMetadata> ConfigServerMetadata::readFromMetadata( } else if (metadataElem.type() != mongo::Object) { return {ErrorCodes::TypeMismatch, str::stream() << "ConfigServerMetadata element has incorrect type: expected" - << mongo::Object << " but got " << metadataElem.type()}; + << mongo::Object + << " but got " + << metadataElem.type()}; } BSONObj configMetadataObj = metadataElem.Obj(); diff --git a/src/mongo/rpc/metadata/repl_set_metadata_test.cpp b/src/mongo/rpc/metadata/repl_set_metadata_test.cpp index 46df9bed886..bd2109fe413 100644 --- a/src/mongo/rpc/metadata/repl_set_metadata_test.cpp +++ b/src/mongo/rpc/metadata/repl_set_metadata_test.cpp @@ -60,8 +60,14 @@ TEST(ReplResponseMetadataTest, Roundtrip) { << BSON("ts" << opTime.getTimestamp() << "t" << opTime.getTerm()) << "lastOpVisible" << BSON("ts" << opTime2.getTimestamp() << "t" << opTime2.getTerm()) - << "configVersion" << 6 << "replicaSetId" << metadata.getReplicaSetId() - << "primaryIndex" << 12 << "syncSourceIndex" << -1))); + << "configVersion" + << 6 + << "replicaSetId" + << metadata.getReplicaSetId() + << "primaryIndex" + << 12 + << "syncSourceIndex" + << -1))); BSONObj serializedObj = builder.obj(); ASSERT_EQ(expectedObj, serializedObj); diff --git a/src/mongo/rpc/metadata/server_selection_metadata.cpp b/src/mongo/rpc/metadata/server_selection_metadata.cpp index 56e82e0ae5a..9100fc18c55 100644 --- a/src/mongo/rpc/metadata/server_selection_metadata.cpp +++ b/src/mongo/rpc/metadata/server_selection_metadata.cpp @@ -30,8 +30,8 @@ #include "mongo/rpc/metadata/server_selection_metadata.h" -#include <utility> #include <tuple> +#include <utility> #include "mongo/base/status_with.h" #include "mongo/bson/util/bson_extract.h" @@ -160,7 +160,9 @@ StatusWith<ServerSelectionMetadata> ServerSelectionMetadata::readFromMetadata( } else if (metadataElem.type() != mongo::Object) { return {ErrorCodes::TypeMismatch, str::stream() << "ServerSelectionMetadata element has incorrect type: expected" - << mongo::Object << " but got " << metadataElem.type()}; + << mongo::Object + << " but got " + << metadataElem.type()}; } bool secondaryOk = false; @@ -174,7 +176,9 @@ StatusWith<ServerSelectionMetadata> ServerSelectionMetadata::readFromMetadata( if (ssmElem.type() != mongo::Object) { return Status(ErrorCodes::TypeMismatch, str::stream() << "ReadPreference has incorrect type: expected" - << mongo::Object << "but got" << metadataElem.type()); + << mongo::Object + << "but got" + << metadataElem.type()); } auto parsedRps = ReadPreferenceSetting::fromBSON(ssmElem.Obj()); if (!parsedRps.isOK()) { diff --git a/src/mongo/rpc/metadata/server_selection_metadata_test.cpp b/src/mongo/rpc/metadata/server_selection_metadata_test.cpp index e2f7c103178..90b66f86185 100644 --- a/src/mongo/rpc/metadata/server_selection_metadata_test.cpp +++ b/src/mongo/rpc/metadata/server_selection_metadata_test.cpp @@ -112,18 +112,21 @@ TEST(ServerSelectionMetadata, UpconvertValidMetadata) { // Wrapped in 'query', with readPref. checkUpconvert(BSON("query" << BSON("pong" << 1 << "foo" - << "bar") << "$readPreference" + << "bar") + << "$readPreference" << BSON("mode" << "primary" - << "tags" << BSON("dc" - << "ny"))), + << "tags" + << BSON("dc" + << "ny"))), 0, BSON("pong" << 1 << "foo" << "bar"), BSON("$ssm" << BSON("$readPreference" << BSON("mode" << "primary" - << "tags" << BSON("dc" - << "ny"))))); + << "tags" + << BSON("dc" + << "ny"))))); // Unwrapped, no readPref, no slaveOk checkUpconvert(BSON("ping" << 1), 0, BSON("ping" << 1), BSONObj()); @@ -133,15 +136,17 @@ TEST(ServerSelectionMetadata, UpconvertValidMetadata) { << "$queryOptions" << BSON("$readPreference" << BSON("mode" << "nearest" - << "tags" << BSON("rack" - << "city")))), + << "tags" + << BSON("rack" + << "city")))), 0, BSON("pang" << "pong"), BSON("$ssm" << BSON("$readPreference" << BSON("mode" << "nearest" - << "tags" << BSON("rack" - << "city"))))); + << "tags" + << BSON("rack" + << "city"))))); } void checkUpconvertFails(const BSONObj& legacyCommand, ErrorCodes::Error error) { @@ -156,27 +161,35 @@ void checkUpconvertFails(const BSONObj& legacyCommand, ErrorCodes::Error error) TEST(ServerSelectionMetadata, UpconvertInvalidMetadata) { // $readPreference not an object. checkUpconvertFails(BSON("$query" << BSON("pang" - << "pong") << "$readPreference" << 2), + << "pong") + << "$readPreference" + << 2), ErrorCodes::TypeMismatch); // has $maxTimeMS option checkUpconvertFails(BSON("query" << BSON("foo" - << "bar") << "$maxTimeMS" << 200), + << "bar") + << "$maxTimeMS" + << 200), ErrorCodes::InvalidOptions); checkUpconvertFails(BSON("$query" << BSON("foo" - << "bar") << "$maxTimeMS" << 200), + << "bar") + << "$maxTimeMS" + << 200), ErrorCodes::InvalidOptions); // has $queryOptions field, but invalid $readPreference checkUpconvertFails(BSON("ping" << "pong" - << "$queryOptions" << BSON("$readPreference" << 1.2)), + << "$queryOptions" + << BSON("$readPreference" << 1.2)), ErrorCodes::TypeMismatch); // has $queryOptions field, but no $readPreference checkUpconvertFails(BSON("ping" << "pong" - << "$queryOptions" << BSONObj()), + << "$queryOptions" + << BSONObj()), ErrorCodes::NoSuchKey); // invalid wrapped query diff --git a/src/mongo/rpc/metadata/sharding_metadata_test.cpp b/src/mongo/rpc/metadata/sharding_metadata_test.cpp index 90050f6781d..51ebf5452bc 100644 --- a/src/mongo/rpc/metadata/sharding_metadata_test.cpp +++ b/src/mongo/rpc/metadata/sharding_metadata_test.cpp @@ -53,7 +53,8 @@ TEST(ShardingMetadata, ReadFromMetadata) { auto sm = checkParse( BSON("$gleStats" << BSON("lastOpTime" << BSON("ts" << kLastOpTime.getTimestamp() << "t" << kLastOpTime.getTerm()) - << "electionId" << kElectionId))); + << "electionId" + << kElectionId))); ASSERT_EQ(sm.getLastElectionId(), kElectionId); ASSERT_EQ(sm.getLastOpTime(), kLastOpTime); } @@ -87,7 +88,8 @@ TEST(ShardingMetadata, ReadFromInvalidMetadata) { checkParseFails( BSON("$gleStats" << BSON("lastOpTime" << BSON("ts" << kLastOpTime.getTimestamp() << "t" << kLastOpTime.getTerm()) - << "electionId" << 3)), + << "electionId" + << 3)), ErrorCodes::TypeMismatch); } { @@ -101,7 +103,9 @@ TEST(ShardingMetadata, ReadFromInvalidMetadata) { checkParseFails( BSON("$gleStats" << BSON("lastOpTime" << BSON("ts" << kLastOpTime.getTimestamp() << "t" << kLastOpTime.getTerm()) - << "electionId" << kElectionId << "extra" + << "electionId" + << kElectionId + << "extra" << "this should not be here")), ErrorCodes::InvalidOptions); } @@ -131,14 +135,16 @@ TEST(ShardingMetadata, UpconvertValidMetadata) { checkUpconvert( BSON("ok" << 1 << "$gleStats" << BSON("lastOpTime" << BSON("ts" << kLastOpTime.getTimestamp() << "t" - << kLastOpTime.getTerm()) << "electionId" + << kLastOpTime.getTerm()) + << "electionId" << kElectionId)), BSON("ok" << 1), BSON("$gleStats" << BSON("lastOpTime" << BSON("ts" << kLastOpTime.getTimestamp() << "t" << kLastOpTime.getTerm()) - << "electionId" << kElectionId))); + << "electionId" + << kElectionId))); } { checkUpconvert( @@ -146,8 +152,10 @@ TEST(ShardingMetadata, UpconvertValidMetadata) { << "some other stuff" << "$gleStats" << BSON("lastOpTime" << BSON("ts" << kLastOpTime.getTimestamp() << "t" - << kLastOpTime.getTerm()) << "electionId" - << kElectionId) << "morestuff" + << kLastOpTime.getTerm()) + << "electionId" + << kElectionId) + << "morestuff" << "more other stuff"), BSON("ok" << 1 << "somestuff" @@ -157,7 +165,8 @@ TEST(ShardingMetadata, UpconvertValidMetadata) { BSON("$gleStats" << BSON("lastOpTime" << BSON("ts" << kLastOpTime.getTimestamp() << "t" << kLastOpTime.getTerm()) - << "electionId" << kElectionId))); + << "electionId" + << kElectionId))); } } @@ -181,13 +190,15 @@ TEST(ShardingMetadata, UpconvertInvalidMetadata) { ErrorCodes::TypeMismatch); } { - checkUpconvertFails(BSON("ok" - << 1 << "$gleStats" - << BSON("lastOpTime" << BSON("ts" << kLastOpTime.getTimestamp() - << "t" << kLastOpTime.getTerm()) - << "electionId" << kElectionId << "krandom" - << "shouldnotbehere")), - ErrorCodes::InvalidOptions); + checkUpconvertFails( + BSON("ok" << 1 << "$gleStats" + << BSON("lastOpTime" << BSON("ts" << kLastOpTime.getTimestamp() << "t" + << kLastOpTime.getTerm()) + << "electionId" + << kElectionId + << "krandom" + << "shouldnotbehere")), + ErrorCodes::InvalidOptions); } } @@ -205,9 +216,11 @@ TEST(ShardingMetadata, Downconvert) { BSON("ok" << 1), BSON("$gleStats" << BSON("lastOpTime" << BSON("ts" << kLastOpTime.getTimestamp() << "t" << kLastOpTime.getTerm()) - << "electionId" << kElectionId)), - BSON("ok" << 1 << "$gleStats" << BSON("lastOpTime" << kLastOpTime.getTimestamp() - << "electionId" << kElectionId))); + << "electionId" + << kElectionId)), + BSON("ok" << 1 << "$gleStats" + << BSON("lastOpTime" << kLastOpTime.getTimestamp() << "electionId" + << kElectionId))); } { checkDownconvert(BSON("ok" << 1), BSONObj(), BSON("ok" << 1)); } } diff --git a/src/mongo/rpc/object_check.h b/src/mongo/rpc/object_check.h index 8d58baa203b..8c8be115136 100644 --- a/src/mongo/rpc/object_check.h +++ b/src/mongo/rpc/object_check.h @@ -29,8 +29,8 @@ #pragma once #include "mongo/base/data_type_validated.h" -#include "mongo/bson/bsontypes.h" #include "mongo/bson/bson_validate.h" +#include "mongo/bson/bsontypes.h" #include "mongo/db/server_options.h" // We do not use the rpc namespace here so we can specialize Validator. diff --git a/src/mongo/rpc/object_check_test.cpp b/src/mongo/rpc/object_check_test.cpp index 03adedd0983..00092ec009d 100644 --- a/src/mongo/rpc/object_check_test.cpp +++ b/src/mongo/rpc/object_check_test.cpp @@ -53,8 +53,9 @@ TEST(DataTypeValidated, BSONValidationEnabled) { BSONObj valid = BSON("baz" << "bar" - << "garply" << BSON("foo" - << "bar")); + << "garply" + << BSON("foo" + << "bar")); char buf[1024] = {0}; std::copy(valid.objdata(), valid.objdata() + valid.objsize(), begin(buf)); { diff --git a/src/mongo/rpc/protocol.cpp b/src/mongo/rpc/protocol.cpp index 6ad7d5859a4..b7e2c8f098c 100644 --- a/src/mongo/rpc/protocol.cpp +++ b/src/mongo/rpc/protocol.cpp @@ -74,9 +74,9 @@ StatusWith<Protocol> negotiate(ProtocolSet fst, ProtocolSet snd) { ProtocolSet common = fst & snd; - auto it = std::find_if(begin(kPreferredProtos), - end(kPreferredProtos), - [common](Protocol p) { return common & static_cast<ProtocolSet>(p); }); + auto it = std::find_if(begin(kPreferredProtos), end(kPreferredProtos), [common](Protocol p) { + return common & static_cast<ProtocolSet>(p); + }); if (it == end(kPreferredProtos)) { return Status(ErrorCodes::RPCProtocolNegotiationFailed, "No common protocol found."); diff --git a/src/mongo/rpc/protocol_test.cpp b/src/mongo/rpc/protocol_test.cpp index ad8437ee280..150c97583e7 100644 --- a/src/mongo/rpc/protocol_test.cpp +++ b/src/mongo/rpc/protocol_test.cpp @@ -81,15 +81,16 @@ TEST(Protocol, parseProtocolSetFromIsMasterReply) { // MongoDB 3.2 (mongos) auto mongos32 = BSON("maxWireVersion" << static_cast<int>(WireVersion::FIND_COMMAND) << "minWireVersion" - << static_cast<int>(WireVersion::RELEASE_2_4_AND_BEFORE) << "msg" + << static_cast<int>(WireVersion::RELEASE_2_4_AND_BEFORE) + << "msg" << "isdbgrid"); ASSERT_EQ(assertGet(parseProtocolSetFromIsMasterReply(mongos32)), supports::kOpQueryOnly); } { // MongoDB 3.0 (mongod) - auto mongod30 = BSON("maxWireVersion" - << static_cast<int>(WireVersion::RELEASE_2_7_7) << "minWireVersion" + auto mongod30 = BSON( + "maxWireVersion" << static_cast<int>(WireVersion::RELEASE_2_7_7) << "minWireVersion" << static_cast<int>(WireVersion::RELEASE_2_4_AND_BEFORE)); ASSERT_EQ(assertGet(parseProtocolSetFromIsMasterReply(mongod30)), supports::kOpQueryOnly); } diff --git a/src/mongo/rpc/reply_builder_test.cpp b/src/mongo/rpc/reply_builder_test.cpp index ce37dc36141..dddfbd535a1 100644 --- a/src/mongo/rpc/reply_builder_test.cpp +++ b/src/mongo/rpc/reply_builder_test.cpp @@ -32,12 +32,12 @@ #include "mongo/db/jsobj.h" #include "mongo/db/json.h" #include "mongo/rpc/command_reply.h" -#include "mongo/rpc/legacy_reply.h" #include "mongo/rpc/command_reply_builder.h" -#include "mongo/rpc/legacy_reply_builder.h" #include "mongo/rpc/document_range.h" -#include "mongo/unittest/unittest.h" +#include "mongo/rpc/legacy_reply.h" +#include "mongo/rpc/legacy_reply_builder.h" #include "mongo/unittest/death_test.h" +#include "mongo/unittest/unittest.h" namespace { |