summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/op_msg_fuzzer_fixture.cpp27
-rw-r--r--src/mongo/db/op_msg_fuzzer_fixture.h2
2 files changed, 18 insertions, 11 deletions
diff --git a/src/mongo/db/op_msg_fuzzer_fixture.cpp b/src/mongo/db/op_msg_fuzzer_fixture.cpp
index 5efdddd3223..a2f6d29eadc 100644
--- a/src/mongo/db/op_msg_fuzzer_fixture.cpp
+++ b/src/mongo/db/op_msg_fuzzer_fixture.cpp
@@ -59,6 +59,21 @@ namespace {
constexpr auto kTempDirStem = "op_msg_fuzzer_fixture"_sd;
}
+// This must be called before creating any new threads that may access `AuthorizationManager` to
+// avoid a data-race.
+void OpMsgFuzzerFixture::_setAuthorizationManager() {
+ auto localExternalState = std::make_unique<AuthzManagerExternalStateMock>();
+ _externalState = localExternalState.get();
+
+ auto localAuthzManager =
+ std::make_unique<AuthorizationManagerImpl>(_serviceContext, std::move(localExternalState));
+ _authzManager = localAuthzManager.get();
+ _externalState->setAuthorizationManager(_authzManager);
+ _authzManager->setAuthEnabled(true);
+
+ AuthorizationManager::set(_serviceContext, std::move(localAuthzManager));
+}
+
OpMsgFuzzerFixture::OpMsgFuzzerFixture(bool skipGlobalInitializers)
: _dir(kTempDirStem.toString()) {
if (!skipGlobalInitializers) {
@@ -70,6 +85,7 @@ OpMsgFuzzerFixture::OpMsgFuzzerFixture(bool skipGlobalInitializers)
_session = _transportLayer.createSession();
_serviceContext = getGlobalServiceContext();
+ _setAuthorizationManager();
_serviceContext->setServiceEntryPoint(
std::make_unique<ServiceEntryPointMongod>(_serviceContext));
@@ -102,17 +118,6 @@ OpMsgFuzzerFixture::OpMsgFuzzerFixture(bool skipGlobalInitializers)
std::make_unique<IndexAccessMethodFactoryImpl>());
Collection::Factory::set(_serviceContext, std::make_unique<CollectionImpl::FactoryImpl>());
- auto localExternalState = std::make_unique<AuthzManagerExternalStateMock>();
- _externalState = localExternalState.get();
-
- auto localAuthzManager =
- std::make_unique<AuthorizationManagerImpl>(_serviceContext, std::move(localExternalState));
- _authzManager = localAuthzManager.get();
- _externalState->setAuthorizationManager(_authzManager);
- _authzManager->setAuthEnabled(true);
-
- AuthorizationManager::set(_serviceContext, std::move(localAuthzManager));
-
// Setup the repl coordinator in standalone mode so we don't need an oplog etc.
repl::ReplicationCoordinator::set(
_serviceContext,
diff --git a/src/mongo/db/op_msg_fuzzer_fixture.h b/src/mongo/db/op_msg_fuzzer_fixture.h
index b519fa98271..4eb95dbf16d 100644
--- a/src/mongo/db/op_msg_fuzzer_fixture.h
+++ b/src/mongo/db/op_msg_fuzzer_fixture.h
@@ -55,6 +55,8 @@ public:
int testOneInput(const char* Data, size_t Size);
private:
+ void _setAuthorizationManager();
+
const LogicalTime kInMemoryLogicalTime = LogicalTime(Timestamp(3, 1));
// This member is responsible for both creating and deleting the base directory. Think of it as