summaryrefslogtreecommitdiff
path: root/src/mongo/idl/idl_test.cpp
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/mongo/idl/idl_test.cpp
parentea67f8909049edd2b8abf55a48999bdd20e7ab87 (diff)
downloadmongo-5268b0ce77f81f4a26636e1abc7ab7eb850b2628.tar.gz
SERVER-65449 Add $tenant field to IDL for commands
Diffstat (limited to 'src/mongo/idl/idl_test.cpp')
-rw-r--r--src/mongo/idl/idl_test.cpp49
1 files changed, 49 insertions, 0 deletions
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