|
30 | 30 |
|
31 | 31 | #include "mongo/bson/json.h"
|
32 | 32 | #include "mongo/db/cluster_role.h"
|
| 33 | +#include "mongo/db/database_name.h" |
33 | 34 | #include "mongo/db/replica_set_endpoint_util.h"
|
34 | 35 |
|
35 | 36 | #include "mongo/util/database_name_util.h"
|
@@ -215,6 +216,87 @@ TEST_F(ReplicaSetEndpointUtilTest, ShouldRoute_AdminDatabase) {
|
215 | 216 | ASSERT(shouldRouteRequest(opCtx.get(), opMsgRequest));
|
216 | 217 | }
|
217 | 218 |
|
| 219 | +TEST_F(ReplicaSetEndpointUtilTest, ShouldNotRoute_SystemDotProfileCollection) { |
| 220 | + std::shared_ptr<transport::Session> session = getTransportLayer().createSession(); |
| 221 | + auto client = |
| 222 | + getServiceContext()->getService()->makeClient("SystemDotProfileCollection", session); |
| 223 | + auto opCtx = client->makeOperationContext(); |
| 224 | + |
| 225 | + auto dbName = |
| 226 | + DatabaseName::createDatabaseName_forTest(boost::none /* tenantId */, {kTestDbName}); |
| 227 | + auto ns = NamespaceString::makeSystemDotProfileNamespace(dbName); |
| 228 | + commands_test_example::ExampleIncrement incrementCmd(ns, 0); |
| 229 | + auto opMsgRequest = mongo::OpMsgRequest::fromDBAndBody(ns.dbName(), incrementCmd.toBSON({})); |
| 230 | + |
| 231 | + ASSERT_FALSE(shouldRouteRequest(opCtx.get(), opMsgRequest)); |
| 232 | +} |
| 233 | + |
| 234 | +TEST_F(ReplicaSetEndpointUtilTest, ShouldRoute_ConfigSystemSessionsCollection) { |
| 235 | + std::shared_ptr<transport::Session> session = getTransportLayer().createSession(); |
| 236 | + auto client = |
| 237 | + getServiceContext()->getService()->makeClient("ConfigSystemSessionsCollection", session); |
| 238 | + auto opCtx = client->makeOperationContext(); |
| 239 | + |
| 240 | + auto ns = NamespaceString::kLogicalSessionsNamespace; |
| 241 | + commands_test_example::ExampleIncrement incrementCmd(ns, 0); |
| 242 | + auto opMsgRequest = mongo::OpMsgRequest::fromDBAndBody(ns.dbName(), incrementCmd.toBSON({})); |
| 243 | + |
| 244 | + ASSERT(shouldRouteRequest(opCtx.get(), opMsgRequest)); |
| 245 | +} |
| 246 | + |
| 247 | +TEST_F(ReplicaSetEndpointUtilTest, ShouldRoute_AdminSystemUsersCollection) { |
| 248 | + std::shared_ptr<transport::Session> session = getTransportLayer().createSession(); |
| 249 | + auto client = |
| 250 | + getServiceContext()->getService()->makeClient("AdminSystemUsersCollection", session); |
| 251 | + auto opCtx = client->makeOperationContext(); |
| 252 | + |
| 253 | + auto ns = NamespaceString::createNamespaceString_forTest(NamespaceString::kSystemUsers); |
| 254 | + commands_test_example::ExampleIncrement incrementCmd(ns, 0); |
| 255 | + auto opMsgRequest = mongo::OpMsgRequest::fromDBAndBody(ns.dbName(), incrementCmd.toBSON({})); |
| 256 | + |
| 257 | + ASSERT(shouldRouteRequest(opCtx.get(), opMsgRequest)); |
| 258 | +} |
| 259 | + |
| 260 | +TEST_F(ReplicaSetEndpointUtilTest, ShouldRoute_UserSystemCollection) { |
| 261 | + std::shared_ptr<transport::Session> session = getTransportLayer().createSession(); |
| 262 | + auto client = getServiceContext()->getService()->makeClient("UserSystemCollection", session); |
| 263 | + auto opCtx = client->makeOperationContext(); |
| 264 | + |
| 265 | + auto ns = |
| 266 | + NamespaceString::createNamespaceString_forTest(kTestDbName, "system." + kTestCollName); |
| 267 | + commands_test_example::ExampleIncrement incrementCmd(ns, 0); |
| 268 | + auto opMsgRequest = mongo::OpMsgRequest::fromDBAndBody(ns.dbName(), incrementCmd.toBSON({})); |
| 269 | + |
| 270 | + ASSERT(shouldRouteRequest(opCtx.get(), opMsgRequest)); |
| 271 | +} |
| 272 | + |
| 273 | +TEST_F(ReplicaSetEndpointUtilTest, ShouldRoute_UserNonSystemCollection) { |
| 274 | + std::shared_ptr<transport::Session> session = getTransportLayer().createSession(); |
| 275 | + auto client = getServiceContext()->getService()->makeClient("UserNonSystemCollection", session); |
| 276 | + auto opCtx = client->makeOperationContext(); |
| 277 | + |
| 278 | + auto ns0 = |
| 279 | + NamespaceString::createNamespaceString_forTest(kTestDbName, "system-" + kTestCollName); |
| 280 | + commands_test_example::ExampleIncrement incrementCmd0(ns0, 0); |
| 281 | + auto opMsgRequest0 = mongo::OpMsgRequest::fromDBAndBody(ns0.dbName(), incrementCmd0.toBSON({})); |
| 282 | + |
| 283 | + ASSERT(shouldRouteRequest(opCtx.get(), opMsgRequest0)); |
| 284 | + |
| 285 | + auto ns1 = |
| 286 | + NamespaceString::createNamespaceString_forTest(kTestDbName, kTestCollName + "system"); |
| 287 | + commands_test_example::ExampleIncrement incrementCmd1(ns1, 0); |
| 288 | + auto opMsgRequest1 = mongo::OpMsgRequest::fromDBAndBody(ns1.dbName(), incrementCmd1.toBSON({})); |
| 289 | + |
| 290 | + ASSERT(shouldRouteRequest(opCtx.get(), opMsgRequest1)); |
| 291 | + |
| 292 | + auto ns2 = |
| 293 | + NamespaceString::createNamespaceString_forTest(kTestDbName, kTestCollName + ".system.foo"); |
| 294 | + commands_test_example::ExampleIncrement incrementCmd2(ns2, 0); |
| 295 | + auto opMsgRequest2 = mongo::OpMsgRequest::fromDBAndBody(ns2.dbName(), incrementCmd2.toBSON({})); |
| 296 | + |
| 297 | + ASSERT(shouldRouteRequest(opCtx.get(), opMsgRequest2)); |
| 298 | +} |
| 299 | + |
218 | 300 | TEST_F(ReplicaSetEndpointUtilTest, ShouldNotRoute_TargetedCommand) {
|
219 | 301 | std::shared_ptr<transport::Session> session = getTransportLayer().createSession();
|
220 | 302 | auto client = getServiceContext()->getService()->makeClient("TargetedCommand", session);
|
|
0 commit comments