summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSophia Tan <sophia_tll@hotmail.com>2022-04-28 14:02:48 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-28 15:28:28 +0000
commit5268b0ce77f81f4a26636e1abc7ab7eb850b2628 (patch)
treeefbc496ecdfcb1b1fa1529e1fd0f17d02a22c429 /src
parentea67f8909049edd2b8abf55a48999bdd20e7ab87 (diff)
downloadmongo-5268b0ce77f81f4a26636e1abc7ab7eb850b2628.tar.gz
SERVER-65449 Add $tenant field to IDL for commands
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/SConscript11
-rw-r--r--src/mongo/db/commands/SConscript1
-rw-r--r--src/mongo/db/commands/user_management_commands.idl6
-rw-r--r--src/mongo/db/multitenancy.idl9
-rw-r--r--src/mongo/idl/SConscript1
-rw-r--r--src/mongo/idl/basic_types.idl7
-rw-r--r--src/mongo/idl/idl_test.cpp49
7 files changed, 68 insertions, 16 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index b0cc69d3d82..12e2beb4e49 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -258,6 +258,16 @@ env.Library(
)
env.Library(
+ target='tenant_id',
+ source=[
+ 'tenant_id.cpp',
+ ],
+ LIBDEPS=[
+ '$BUILD_DIR/mongo/base',
+ ],
+)
+
+env.Library(
target='update_index_data',
source=[
'update_index_data.cpp'
@@ -286,7 +296,6 @@ env.Library(
target='multitenancy_params',
source=[
'multitenancy.idl',
- 'tenant_id.cpp',
],
LIBDEPS_PRIVATE=[
'$BUILD_DIR/mongo/base',
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript
index 590b145470f..7fdbb486450 100644
--- a/src/mongo/db/commands/SConscript
+++ b/src/mongo/db/commands/SConscript
@@ -582,6 +582,7 @@ env.Library(
'$BUILD_DIR/mongo/db/s/user_writes_recoverable_critical_section',
'$BUILD_DIR/mongo/db/server_feature_flags',
'$BUILD_DIR/mongo/db/server_options_core',
+ '$BUILD_DIR/mongo/db/tenant_id',
'$BUILD_DIR/mongo/db/timeseries/timeseries_conversion_util',
'$BUILD_DIR/mongo/db/transaction_api',
'$BUILD_DIR/mongo/idl/idl_parser',
diff --git a/src/mongo/db/commands/user_management_commands.idl b/src/mongo/db/commands/user_management_commands.idl
index 36e410dc1dc..fb68bb63f36 100644
--- a/src/mongo/db/commands/user_management_commands.idl
+++ b/src/mongo/db/commands/user_management_commands.idl
@@ -128,12 +128,6 @@ commands:
description: "List of valid authentication mechanisms for the user"
type: array<string>
optional: true
- "$tenant":
- # Only available with enableTestCommands and multitenancySupport
- description: "Associate this user with a specific tenant"
- type: tenant_id
- cpp_name: tenantOverride
- optional: true
updateUser:
description: "Modify a user"
diff --git a/src/mongo/db/multitenancy.idl b/src/mongo/db/multitenancy.idl
index a45623c6f99..a2f366dd412 100644
--- a/src/mongo/db/multitenancy.idl
+++ b/src/mongo/db/multitenancy.idl
@@ -38,12 +38,3 @@ server_parameters:
cpp_vartype: bool
cpp_varname: gMultitenancySupport
default: false
-
-types:
- tenant_id:
- bson_serialization_type: any
- description: "A struct representing a tenant id"
- cpp_type: "TenantId"
- deserializer: "mongo::TenantId::parseFromBSON"
- serializer: "mongo::TenantId::serializeToBSON"
-
diff --git a/src/mongo/idl/SConscript b/src/mongo/idl/SConscript
index de25a54c950..f2cabda3292 100644
--- a/src/mongo/idl/SConscript
+++ b/src/mongo/idl/SConscript
@@ -30,6 +30,7 @@ env.Library(
LIBDEPS=[
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/db/commands/server_status_core',
+ '$BUILD_DIR/mongo/db/tenant_id',
]
)
diff --git a/src/mongo/idl/basic_types.idl b/src/mongo/idl/basic_types.idl
index d124f29cdae..7c482cd65a9 100644
--- a/src/mongo/idl/basic_types.idl
+++ b/src/mongo/idl/basic_types.idl
@@ -32,6 +32,7 @@ global:
cpp_includes:
- "mongo/db/logical_time.h"
- "mongo/db/namespace_string.h"
+ - "mongo/db/tenant_id.h"
- "mongo/idl/basic_types.h"
- "mongo/util/uuid.h"
@@ -255,6 +256,12 @@ types:
cpp_type: "mongo::IDLAnyTypeOwned"
serializer: mongo::IDLAnyTypeOwned::serializeToBSON
deserializer: mongo::IDLAnyTypeOwned::parseFromBSON
+ tenant_id:
+ bson_serialization_type: any
+ description: "A struct representing a tenant id"
+ cpp_type: "TenantId"
+ deserializer: "mongo::TenantId::parseFromBSON"
+ serializer: "mongo::TenantId::serializeToBSON"
enums:
CollationCaseFirst:
diff --git a/src/mongo/idl/idl_test.cpp b/src/mongo/idl/idl_test.cpp
index 505c99f756d..b65f51305cb 100644
--- a/src/mongo/idl/idl_test.cpp
+++ b/src/mongo/idl/idl_test.cpp
@@ -3805,5 +3805,54 @@ TEST(IDLFieldTests, TestOptionalBoolField) {
}
}
+TEST(IDLFieldTests, TenantOverrideField) {
+ const auto mkdoc = [](boost::optional<TenantId> tenantId) {
+ BSONObjBuilder doc;
+ doc.append("BasicIgnoredCommand", 1);
+ doc.append("$db", "admin");
+ if (tenantId) {
+ tenantId->serializeToBSON("$tenant", &doc);
+ }
+ doc.append("field1", 42);
+ doc.append("field2", "foo");
+ return doc.obj();
+ };
+
+ // Test optionality of $tenant arg.
+ {
+ auto obj = BasicIgnoredCommand::parse({"nil"}, mkdoc(boost::none));
+ auto tenant = obj.getDollarTenant();
+ ASSERT(tenant == boost::none);
+ }
+
+ // Test passing an tenant id (acting on behalf of a specific tenant)
+ {
+ auto id = TenantId(OID::gen());
+ auto obj = BasicIgnoredCommand::parse({"oid"}, mkdoc(id));
+ auto tenant = obj.getDollarTenant();
+ ASSERT(tenant == id);
+ }
+}
+
+TEST(IDLFieldTests, TenantOverrideFieldWithInvalidValue) {
+ const auto mkdoc = [](auto tenantId) {
+ BSONObjBuilder doc;
+ doc.append("BasicIgnoredCommand", 1);
+ doc.append("$db", "admin");
+ doc.append("$tenant", tenantId);
+ doc.append("field1", 42);
+ doc.append("field2", "foo");
+ return doc.obj();
+ };
+
+ // Negative: Parse invalid types.
+ {
+ ASSERT_THROWS(BasicIgnoredCommand::parse({"int"}, mkdoc(123)), DBException);
+ ASSERT_THROWS(BasicIgnoredCommand::parse({"float"}, mkdoc(3.14)), DBException);
+ ASSERT_THROWS(BasicIgnoredCommand::parse({"string"}, mkdoc("bar")), DBException);
+ ASSERT_THROWS(BasicIgnoredCommand::parse({"object"}, mkdoc(BSONObj())), DBException);
+ }
+}
+
} // namespace
} // namespace mongo