summaryrefslogtreecommitdiff
path: root/src/mongo/idl
diff options
context:
space:
mode:
authorjannaerin <golden.janna@gmail.com>2022-07-12 15:31:08 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-07-12 16:25:47 +0000
commitac1ca195885cd42bb2ae7ac9a892c93425082669 (patch)
treebf42bbbe1c28d442a63e9121300090afdeb99cc8 /src/mongo/idl
parent69a25807e5fb0b8a1bf3792bb5150e1baf0f0c37 (diff)
downloadmongo-ac1ca195885cd42bb2ae7ac9a892c93425082669.tar.gz
Revert "SERVER-65459 Construct NamespaceString using tenantId on the OpMsgRequest during command parsing for IDL defined commands"
This reverts commit c340d5a7a891758510728997c839f8e8d7e5eaa0.
Diffstat (limited to 'src/mongo/idl')
-rw-r--r--src/mongo/idl/basic_types.idl3
-rw-r--r--src/mongo/idl/idl_parser.cpp9
-rw-r--r--src/mongo/idl/idl_parser.h5
-rw-r--r--src/mongo/idl/idl_test.cpp123
-rw-r--r--src/mongo/idl/unittest.idl20
5 files changed, 8 insertions, 152 deletions
diff --git a/src/mongo/idl/basic_types.idl b/src/mongo/idl/basic_types.idl
index 7f338af5c98..36796cb008a 100644
--- a/src/mongo/idl/basic_types.idl
+++ b/src/mongo/idl/basic_types.idl
@@ -231,8 +231,7 @@ types:
description: "A MongoDB NamespaceString"
cpp_type: "mongo::NamespaceString"
serializer: mongo::NamespaceString::toString
- deserializer: mongo::NamespaceString
- deserialize_with_tenant: true
+ deserializer: mongo::NamespaceString::parseFromStringExpectTenantIdInMultitenancyMode
base64string:
bson_serialization_type: string
diff --git a/src/mongo/idl/idl_parser.cpp b/src/mongo/idl/idl_parser.cpp
index 29a1d5163aa..a76d75eeba4 100644
--- a/src/mongo/idl/idl_parser.cpp
+++ b/src/mongo/idl/idl_parser.cpp
@@ -241,7 +241,7 @@ void IDLParserErrorContext::throwAPIStrictErrorIfApplicable(StringData fieldName
!_apiStrict);
}
-NamespaceString IDLParserErrorContext::parseNSCollectionRequired(const DatabaseName& dbName,
+NamespaceString IDLParserErrorContext::parseNSCollectionRequired(StringData dbName,
const BSONElement& element,
bool allowGlobalCollectionName) {
const bool isUUID = (element.canonicalType() == canonicalizeBSONType(mongo::BinData) &&
@@ -272,13 +272,14 @@ NamespaceString IDLParserErrorContext::parseNSCollectionRequired(const DatabaseN
return nss;
}
-NamespaceStringOrUUID IDLParserErrorContext::parseNsOrUUID(const DatabaseName& dbName,
+NamespaceStringOrUUID IDLParserErrorContext::parseNsOrUUID(StringData dbname,
const BSONElement& element) {
if (element.type() == BinData && element.binDataType() == BinDataType::newUUID) {
- return {dbName, uassertStatusOK(UUID::parse(element))};
+ return {dbname.toString(), uassertStatusOK(UUID::parse(element))};
} else {
// Ensure collection identifier is not a Command
- return {parseNSCollectionRequired(dbName, element, false)};
+ const NamespaceString nss(parseNSCollectionRequired(dbname, element, false));
+ return nss;
}
}
diff --git a/src/mongo/idl/idl_parser.h b/src/mongo/idl/idl_parser.h
index 3a534755bcb..a9df8299e3b 100644
--- a/src/mongo/idl/idl_parser.h
+++ b/src/mongo/idl/idl_parser.h
@@ -340,15 +340,14 @@ public:
* Equivalent to CommandHelpers::parseNsCollectionRequired.
* 'allowGlobalCollectionName' allows use of global collection name, e.g. {aggregate: 1}.
*/
- static NamespaceString parseNSCollectionRequired(const DatabaseName& dbname,
+ static NamespaceString parseNSCollectionRequired(StringData dbName,
const BSONElement& element,
bool allowGlobalCollectionName);
/**
* Equivalent to CommandHelpers::parseNsOrUUID
*/
- static NamespaceStringOrUUID parseNsOrUUID(const DatabaseName& dbname,
- const BSONElement& element);
+ static NamespaceStringOrUUID parseNsOrUUID(StringData dbname, const BSONElement& element);
/**
* Take all the well known command generic arguments from commandPassthroughFields, but ignore
diff --git a/src/mongo/idl/idl_test.cpp b/src/mongo/idl/idl_test.cpp
index 70d949c0636..aad9e190aa2 100644
--- a/src/mongo/idl/idl_test.cpp
+++ b/src/mongo/idl/idl_test.cpp
@@ -2321,15 +2321,6 @@ OpMsgRequest makeOMR(BSONObj obj) {
return request;
}
-OpMsgRequest makeOMRWithTenant(BSONObj obj, TenantId tenant) {
- OpMsgRequest request;
- request.body = obj;
-
- using VTS = auth::ValidatedTenancyScope;
- request.validatedTenancyScope = VTS(std::move(tenant), VTS::TenantForTestingTag{});
- return request;
-}
-
// Positive: demonstrate a command with concatenate with db
TEST(IDLCommand, TestConcatentateWithDb) {
IDLParserErrorContext ctxt("root");
@@ -2376,28 +2367,6 @@ TEST(IDLCommand, TestConcatentateWithDb) {
}
}
-TEST(IDLCommand, TestConcatentateWithDb_WithTenant) {
- IDLParserErrorContext ctxt("root");
-
- const auto kTenantId = TenantId(OID::gen());
-
- auto testDoc = BSONObjBuilder{}
- .append(BasicConcatenateWithDbCommand::kCommandName, "coll1")
- .append("field1", 3)
- .append("field2", "five")
- .append("$db", "db")
- .obj();
-
- auto testStruct =
- BasicConcatenateWithDbCommand::parse(ctxt, makeOMRWithTenant(testDoc, kTenantId));
- ASSERT_EQUALS(testStruct.getNamespace(), NamespaceString(kTenantId, "db.coll1"));
-
- assert_same_types<decltype(testStruct.getNamespace()), const NamespaceString&>();
-
- // Positive: Test we can roundtrip from the just parsed document
- ASSERT_BSONOBJ_EQ(testDoc, serializeCmd(testStruct));
-}
-
TEST(IDLCommand, TestConcatentateWithDbSymbol) {
IDLParserErrorContext ctxt("root");
@@ -2508,27 +2477,6 @@ TEST(IDLCommand, TestConcatentateWithDbOrUUID_TestNSS) {
}
}
-TEST(IDLCommand, TestConcatentateWithDbOrUUID_TestNSS_WithTenant) {
- IDLParserErrorContext ctxt("root");
-
- auto testDoc = BSONObjBuilder{}
- .append(BasicConcatenateWithDbOrUUIDCommand::kCommandName, "coll1")
- .append("field1", 3)
- .append("field2", "five")
- .append("$db", "db")
- .obj();
-
- const auto kTenantId = TenantId(OID::gen());
- auto testStruct =
- BasicConcatenateWithDbOrUUIDCommand::parse(ctxt, makeOMRWithTenant(testDoc, kTenantId));
- ASSERT_EQUALS(testStruct.getNamespaceOrUUID().nss().get(),
- NamespaceString(kTenantId, "db.coll1"));
-
- assert_same_types<decltype(testStruct.getNamespaceOrUUID()), const NamespaceStringOrUUID&>();
-
- // Positive: Test we can roundtrip from the just parsed document
- ASSERT_BSONOBJ_EQ(testDoc, serializeCmd(testStruct));
-}
// Positive: demonstrate a command with concatenate with db or uuid - test UUID
TEST(IDLCommand, TestConcatentateWithDbOrUUID_TestUUID) {
@@ -2577,30 +2525,6 @@ TEST(IDLCommand, TestConcatentateWithDbOrUUID_TestUUID) {
}
}
-TEST(IDLCommand, TestConcatentateWithDbOrUUID_TestUUID_WithTenant) {
- IDLParserErrorContext ctxt("root");
-
- UUID uuid = UUID::gen();
-
- auto testDoc =
- BSONObjBuilder{}
- .appendElements(BSON(BasicConcatenateWithDbOrUUIDCommand::kCommandName << uuid))
- .append("field1", 3)
- .append("field2", "five")
- .append("$db", "db")
- .obj();
-
- const auto kTenantId = TenantId(OID::gen());
- auto testStruct =
- BasicConcatenateWithDbOrUUIDCommand::parse(ctxt, makeOMRWithTenant(testDoc, kTenantId));
- ASSERT_EQUALS(testStruct.getNamespaceOrUUID().dbName().get(), DatabaseName(kTenantId, "db"));
-
- assert_same_types<decltype(testStruct.getNamespaceOrUUID()), const NamespaceStringOrUUID&>();
-
- // Positive: Test we can roundtrip from the just parsed document
- ASSERT_BSONOBJ_EQ(testDoc, serializeCmd(testStruct));
-}
-
TEST(IDLCommand, TestConcatentateWithDbOrUUIDNegative) {
IDLParserErrorContext ctxt("root");
@@ -3896,53 +3820,6 @@ TEST(IDLTypeCommand, TestCommandWithIDLAnyTypeOwnedField) {
<< "b"))["anyTypeField"]);
}
-TEST(IDLCommand, TestCommandTypeNamespaceCommand_WithTenant) {
- IDLParserErrorContext ctxt("root");
-
- auto testDoc = BSON(CommandTypeNamespaceCommand::kCommandName << "db.coll1"
- << "field1" << 3 << "$db"
- << "admin");
-
- const auto kTenantId = TenantId(OID::gen());
- auto testStruct =
- CommandTypeNamespaceCommand::parse(ctxt, makeOMRWithTenant(testDoc, kTenantId));
- ASSERT_EQUALS(testStruct.getCommandParameter(), NamespaceString(kTenantId, "db.coll1"));
-
- assert_same_types<decltype(testStruct.getCommandParameter()), const NamespaceString&>();
-
- // Positive: Test we can roundtrip from the just parsed document
- ASSERT_BSONOBJ_EQ(testDoc, serializeCmd(testStruct));
-}
-
-TEST(IDLTypeCommand, TestCommandWithNamespaceMember_WithTenant) {
- IDLParserErrorContext ctxt("root");
-
- auto testDoc = BSONObjBuilder{}
- .append("CommandWithNamespaceMember", 1)
- .append("field1", "db.coll1")
- .append("field2",
- BSON_ARRAY("a.b"
- << "c.d"))
- .append("$db", "admin")
- .obj();
-
- const auto kTenantId = TenantId(OID::gen());
- auto testStruct =
- CommandWithNamespaceMember::parse(ctxt, makeOMRWithTenant(testDoc, kTenantId));
-
- assert_same_types<decltype(testStruct.getField1()), const NamespaceString&>();
- assert_same_types<decltype(testStruct.getField2()),
- const std::vector<mongo::NamespaceString>&>();
-
- ASSERT_EQUALS(testStruct.getField1(), NamespaceString(kTenantId, "db.coll1"));
- std::vector<NamespaceString> field2{NamespaceString(kTenantId, "a.b"),
- NamespaceString(kTenantId, "c.d")};
- ASSERT_TRUE(field2 == testStruct.getField2());
-
- // Positive: Test we can roundtrip from the just parsed document
- ASSERT_BSONOBJ_EQ(testDoc, serializeCmd(testStruct));
-}
-
void verifyContract(const AuthorizationContract& left, const AuthorizationContract& right) {
ASSERT_TRUE(left.contains(right));
ASSERT_TRUE(right.contains(left));
diff --git a/src/mongo/idl/unittest.idl b/src/mongo/idl/unittest.idl
index 824621910e3..37892632cd9 100644
--- a/src/mongo/idl/unittest.idl
+++ b/src/mongo/idl/unittest.idl
@@ -1066,15 +1066,6 @@ commands:
type:
variant: [bool, one_string]
- CommandTypeNamespaceCommand:
- description: Command with custom type naemspacestring
- command_name: CommandTypeNamespaceCommand
- namespace: type
- type: namespacestring
- api_version: ""
- fields:
- field1: int
-
_underscore_command:
description: Command with custom type string
command_name: _underscore_command
@@ -1149,17 +1140,6 @@ commands:
fields:
anyTypeField: IDLAnyTypeOwned
- CommandWithNamespaceMember:
- description: "A mock command to test field with namespacestring"
- command_name: CommandWithNamespaceMember
- namespace: ignored
- api_version: ""
- fields:
- field1:
- type: namespacestring
- field2:
- type: array<namespacestring>
-
AccessCheckNone:
description: A Stable API command with access_check and none
command_name: AccessCheckNoneCommandName