summaryrefslogtreecommitdiff
path: root/src/mongo/db/operation_context_test.cpp
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2017-07-21 11:54:18 -0400
committerJason Carey <jcarey@argv.me>2017-07-26 15:53:42 -0400
commitedfe3f3b1276ef3598b1af673d088e6b5c4b3ad5 (patch)
tree08f0efcdb6100dc315cf5e9ac98c0c6261be928d /src/mongo/db/operation_context_test.cpp
parentcb36a96d7c96cf1b24c7ef3b8b086cfc04c77642 (diff)
downloadmongo-edfe3f3b1276ef3598b1af673d088e6b5c4b3ad5.tar.gz
SERVER-30298 Add UserDigest LogicalSessionID
Inclusion of a sha256 digest of the full username to the logical session id (in addition to the current guid) is necessary to fully disambiguate logical sessions in degraded clusters (when the authoritative record for a session is unreachable). Semantics for the uid are as follows: session creation via startSession() * Sessions can only be created with one, and only one, user authenticated * The composite key is created from a guid created on the spot, as well as the digest of the currently auth'd username * Only the session guid is returned to the user * This prevents outside users from attempting to send back a value we'd have to check. It's preferable to decorate the guid with the user digest per command, rather than having to check a value the user might send. session use for a command * Sessions are passed via the lsid top level field in any command * Sessions are only meaningful for commands which requireAuth. For sessions which don't require auth, we strip session information from the command at parse time * Session ids are passed as an object, which can optionally include the username digest * It is illegal to pass the username digest unless the currently auth'd user has the impersonate privilege (the __system user does). This enables sessions on shard servers via mongos
Diffstat (limited to 'src/mongo/db/operation_context_test.cpp')
-rw-r--r--src/mongo/db/operation_context_test.cpp64
1 files changed, 2 insertions, 62 deletions
diff --git a/src/mongo/db/operation_context_test.cpp b/src/mongo/db/operation_context_test.cpp
index 5174e599748..b5c8fe2c91d 100644
--- a/src/mongo/db/operation_context_test.cpp
+++ b/src/mongo/db/operation_context_test.cpp
@@ -89,7 +89,7 @@ TEST(OperationContextTest, SessionIdNoTransactionNumber) {
auto client = serviceCtx->makeClient("OperationContextTest");
auto opCtx = client->makeOperationContext();
- const auto lsid = assertGet(LogicalSessionId::parse("00000000-abab-4000-8000-000000000000"));
+ const auto lsid = makeLogicalSessionIdForTest();
opCtx->setLogicalSessionId(lsid);
ASSERT(opCtx->getLogicalSessionId());
@@ -103,7 +103,7 @@ TEST(OperationContextTest, SessionIdAndTransactionNumber) {
auto client = serviceCtx->makeClient("OperationContextTest");
auto opCtx = client->makeOperationContext();
- const auto lsid = assertGet(LogicalSessionId::parse("00000000-abab-4000-8000-000000000000"));
+ const auto lsid = makeLogicalSessionIdForTest();
opCtx->setLogicalSessionId(lsid);
opCtx->setTxnNumber(5);
@@ -111,66 +111,6 @@ TEST(OperationContextTest, SessionIdAndTransactionNumber) {
ASSERT_EQUALS(5, *opCtx->getTxnNumber());
}
-TEST(OperationContextTest, InitializeOperationSessionInfo_NoSessionIdNoTransactionNumber) {
- auto serviceCtx = stdx::make_unique<ServiceContextNoop>();
- auto client = serviceCtx->makeClient("OperationContextTest");
- auto opCtx = client->makeOperationContext();
-
- initializeOperationSessionInfo(opCtx.get(), BSON("TestCmd" << 1));
-
- ASSERT(!opCtx->getLogicalSessionId());
- ASSERT(!opCtx->getTxnNumber());
-}
-
-TEST(OperationContextTest, InitializeOperationSessionInfo_SessionIdNoTransactionNumber) {
- auto serviceCtx = stdx::make_unique<ServiceContextNoop>();
- auto client = serviceCtx->makeClient("OperationContextTest");
- auto opCtx = client->makeOperationContext();
-
- LogicalSessionId lsid;
-
- initializeOperationSessionInfo(opCtx.get(),
- BSON("TestCmd" << 1 << "lsid" << lsid.toBSON() << "OtherField"
- << "TestField"));
-
- ASSERT(opCtx->getLogicalSessionId());
- ASSERT_EQ(lsid, *opCtx->getLogicalSessionId());
-
- ASSERT(!opCtx->getTxnNumber());
-}
-
-TEST(OperationContextTest, InitializeOperationSessionInfo_MissingSessionIdWithTransactionNumber) {
- auto serviceCtx = stdx::make_unique<ServiceContextNoop>();
- auto client = serviceCtx->makeClient("OperationContextTest");
- auto opCtx = client->makeOperationContext();
-
- ASSERT_THROWS_CODE(
- initializeOperationSessionInfo(opCtx.get(),
- BSON("TestCmd" << 1 << "txnNumber" << 100LL << "OtherField"
- << "TestField")),
- UserException,
- ErrorCodes::IllegalOperation);
-}
-
-TEST(OperationContextTest, InitializeOperationSessionInfo_SessionIdAndTransactionNumber) {
- auto serviceCtx = stdx::make_unique<ServiceContextNoop>();
- auto client = serviceCtx->makeClient("OperationContextTest");
- auto opCtx = client->makeOperationContext();
-
- LogicalSessionId lsid;
-
- initializeOperationSessionInfo(
- opCtx.get(),
- BSON("TestCmd" << 1 << "lsid" << lsid.toBSON() << "txnNumber" << 100LL << "OtherField"
- << "TestField"));
-
- ASSERT(opCtx->getLogicalSessionId());
- ASSERT_EQ(lsid, *opCtx->getLogicalSessionId());
-
- ASSERT(opCtx->getTxnNumber());
- ASSERT_EQ(100, *opCtx->getTxnNumber());
-}
-
TEST(OperationContextTest, OpCtxGroup) {
OperationContextGroup group1;
ASSERT_TRUE(group1.isEmpty());