summaryrefslogtreecommitdiff
path: root/src/mongo/embedded/mongo_embedded
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/embedded/mongo_embedded')
-rw-r--r--src/mongo/embedded/mongo_embedded/SConscript1
-rw-r--r--src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp126
2 files changed, 115 insertions, 12 deletions
diff --git a/src/mongo/embedded/mongo_embedded/SConscript b/src/mongo/embedded/mongo_embedded/SConscript
index 7a5f2043d6b..8f84ee065d5 100644
--- a/src/mongo/embedded/mongo_embedded/SConscript
+++ b/src/mongo/embedded/mongo_embedded/SConscript
@@ -94,7 +94,6 @@ if get_option('link-model') != 'dynamic-sdk':
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
- '$BUILD_DIR/mongo/bson/bson_validate',
'$BUILD_DIR/mongo/db/commands/test_commands_enabled',
'$BUILD_DIR/mongo/db/server_options_core',
'$BUILD_DIR/mongo/rpc/message',
diff --git a/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp b/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp
index 4a9945875f9..7d728bf451a 100644
--- a/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp
+++ b/src/mongo/embedded/mongo_embedded/mongo_embedded_test.cpp
@@ -35,7 +35,6 @@
#include <yaml-cpp/yaml.h>
#include "mongo/base/initializer.h"
-#include "mongo/bson/bson_validate.h"
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/db/commands/test_commands_enabled.h"
#include "mongo/db/json.h"
@@ -195,7 +194,7 @@ protected:
// convert the message into an OpMessage to examine its BSON
auto outputOpMsg = mongo::OpMsg::parseOwned(outputMessage);
- ASSERT_OK(mongo::validateBSON(outputOpMsg.body));
+ ASSERT(outputOpMsg.body.valid());
return outputOpMsg.body;
}
@@ -408,7 +407,7 @@ TEST_F(MongodbCAPITest, ReadDB) {
auto outputBSON = performRpc(client, findMsg);
- ASSERT_OK(mongo::validateBSON(outputBSON));
+ ASSERT(outputBSON.valid());
ASSERT(outputBSON.hasField("cursor"));
ASSERT(outputBSON.getField("cursor").embeddedObject().hasField("firstBatch"));
mongo::BSONObj arrObj =
@@ -433,7 +432,7 @@ TEST_F(MongodbCAPITest, InsertAndRead) {
"{insert: 'collection_name', documents: [{firstName: 'Mongo', lastName: 'DB', age: 10}]}");
auto insertOpMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", insertObj);
auto outputBSON1 = performRpc(client, insertOpMsg);
- ASSERT_OK(mongo::validateBSON(outputBSON1));
+ ASSERT(outputBSON1.valid());
ASSERT(outputBSON1.hasField("n"));
ASSERT(outputBSON1.getIntField("n") == 1);
ASSERT(outputBSON1.hasField("ok"));
@@ -442,7 +441,7 @@ TEST_F(MongodbCAPITest, InsertAndRead) {
mongo::BSONObj findObj = mongo::fromjson("{find: 'collection_name', limit: 1}");
auto findMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", findObj);
auto outputBSON2 = performRpc(client, findMsg);
- ASSERT_OK(mongo::validateBSON(outputBSON2));
+ ASSERT(outputBSON2.valid());
ASSERT(outputBSON2.hasField("cursor"));
ASSERT(outputBSON2.getField("cursor").embeddedObject().hasField("firstBatch"));
mongo::BSONObj arrObj =
@@ -468,7 +467,7 @@ TEST_F(MongodbCAPITest, InsertAndReadDifferentClients) {
"{insert: 'collection_name', documents: [{firstName: 'Mongo', lastName: 'DB', age: 10}]}");
auto insertOpMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", insertObj);
auto outputBSON1 = performRpc(client1, insertOpMsg);
- ASSERT_OK(mongo::validateBSON(outputBSON1));
+ ASSERT(outputBSON1.valid());
ASSERT(outputBSON1.hasField("n"));
ASSERT(outputBSON1.getIntField("n") == 1);
ASSERT(outputBSON1.hasField("ok"));
@@ -477,7 +476,7 @@ TEST_F(MongodbCAPITest, InsertAndReadDifferentClients) {
mongo::BSONObj findObj = mongo::fromjson("{find: 'collection_name', limit: 1}");
auto findMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", findObj);
auto outputBSON2 = performRpc(client2, findMsg);
- ASSERT_OK(mongo::validateBSON(outputBSON2));
+ ASSERT(outputBSON2.valid());
ASSERT(outputBSON2.hasField("cursor"));
ASSERT(outputBSON2.getField("cursor").embeddedObject().hasField("firstBatch"));
mongo::BSONObj arrObj =
@@ -502,7 +501,7 @@ TEST_F(MongodbCAPITest, InsertAndDelete) {
"age: 10}]}");
auto insertOpMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", insertObj);
auto outputBSON1 = performRpc(client, insertOpMsg);
- ASSERT_OK(mongo::validateBSON(outputBSON1));
+ ASSERT(outputBSON1.valid());
ASSERT(outputBSON1.hasField("n"));
ASSERT(outputBSON1.getIntField("n") == 1);
ASSERT(outputBSON1.hasField("ok"));
@@ -515,7 +514,7 @@ TEST_F(MongodbCAPITest, InsertAndDelete) {
"1}]}");
auto deleteOpMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", deleteObj);
auto outputBSON2 = performRpc(client, deleteOpMsg);
- ASSERT_OK(mongo::validateBSON(outputBSON2));
+ ASSERT(outputBSON2.valid());
ASSERT(outputBSON2.hasField("n"));
ASSERT(outputBSON2.getIntField("n") == 1);
ASSERT(outputBSON2.hasField("ok"));
@@ -531,7 +530,7 @@ TEST_F(MongodbCAPITest, InsertAndUpdate) {
"age: 10}]}");
auto insertOpMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", insertObj);
auto outputBSON1 = performRpc(client, insertOpMsg);
- ASSERT_OK(mongo::validateBSON(outputBSON1));
+ ASSERT(outputBSON1.valid());
ASSERT(outputBSON1.hasField("n"));
ASSERT(outputBSON1.getIntField("n") == 1);
ASSERT(outputBSON1.hasField("ok"));
@@ -544,13 +543,118 @@ TEST_F(MongodbCAPITest, InsertAndUpdate) {
"{age: 5}}}]}");
auto updateOpMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", updateObj);
auto outputBSON2 = performRpc(client, updateOpMsg);
- ASSERT_OK(mongo::validateBSON(outputBSON2));
+ ASSERT(outputBSON2.valid());
ASSERT(outputBSON2.hasField("ok"));
ASSERT(outputBSON2.getField("ok").numberDouble() == 1.0);
ASSERT(outputBSON2.hasField("nModified"));
ASSERT(outputBSON2.getIntField("nModified") == 1);
}
+TEST_F(MongodbCAPITest, RunListCommands) {
+ auto client = createClient();
+
+ std::vector<std::string> allowlist = {"_hashBSONElement",
+ "_killOperations",
+ "aggregate",
+ "buildInfo",
+ "collMod",
+ "collStats",
+ "configureFailPoint",
+ "count",
+ "create",
+ "createIndexes",
+ "currentOp",
+ "dataSize",
+ "dbStats",
+ "delete",
+ "distinct",
+ "drop",
+ "dropDatabase",
+ "dropIndexes",
+ "echo",
+ "endSessions",
+ "explain",
+ "find",
+ "findAndModify",
+ "getLastError",
+ "getMore",
+ "getParameter",
+ "httpClientRequest",
+ "insert",
+ "isMaster",
+ "killCursors",
+ "killOp",
+ "killSessions",
+ "killAllSessions",
+ "killAllSessionsByPattern",
+ "listCollections",
+ "listCommands",
+ "listDatabases",
+ "listIndexes",
+ "lockInfo",
+ "logMessage",
+ "ping",
+ "planCacheClear",
+ "planCacheClearFilters",
+ "planCacheListFilters",
+ "planCacheSetFilter",
+ "reIndex",
+ "refreshLogicalSessionCacheNow",
+ "refreshSessions",
+ "renameCollection",
+ "repairDatabase",
+ "serverStatus",
+ "setParameter",
+ "sleep",
+ "startSession",
+ "update",
+ "validate",
+ "validateDBMetadata",
+ "waitForFailPoint",
+ "whatsmysni"};
+
+ std::sort(allowlist.begin(), allowlist.end());
+
+ mongo::BSONObj listCommandsObj = mongo::fromjson("{ listCommands: 1 }");
+ auto listCommandsOpMsg = mongo::OpMsgRequest::fromDBAndBody("db_name", listCommandsObj);
+ auto output = performRpc(client, listCommandsOpMsg);
+ auto commandsBSON = output["commands"];
+ std::vector<std::string> commands;
+ for (const auto& element : commandsBSON.Obj()) {
+ commands.push_back(element.fieldNameStringData().toString());
+ }
+ std::sort(commands.begin(), commands.end());
+
+ std::vector<std::string> missing;
+ std::vector<std::string> unsupported;
+ std::set_difference(allowlist.begin(),
+ allowlist.end(),
+ commands.begin(),
+ commands.end(),
+ std::back_inserter(missing));
+ std::set_difference(commands.begin(),
+ commands.end(),
+ allowlist.begin(),
+ allowlist.end(),
+ std::back_inserter(unsupported));
+
+ if (!missing.empty()) {
+ std::cout << "\nMissing commands from the embedded binary:\n";
+ }
+ for (auto&& cmd : missing) {
+ std::cout << cmd << "\n";
+ }
+ if (!unsupported.empty()) {
+ std::cout << "\nUnsupported commands in the embedded binary:\n";
+ }
+ for (auto&& cmd : unsupported) {
+ std::cout << cmd << "\n";
+ }
+
+ ASSERT(missing.empty()) << mongo::StringSplitter::join(missing, ", ");
+ ASSERT(unsupported.empty()) << mongo::StringSplitter::join(unsupported, ", ");
+}
+
// This test is temporary to make sure that only one database can be created
// This restriction may be relaxed at a later time
TEST_F(MongodbCAPITest, CreateMultipleDBs) {