diff --git a/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls b/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls index 2fe71f086..7ceeb6736 100644 --- a/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls +++ b/nebula-logger/core/main/log-management/classes/LogEntryEventHandler.cls @@ -614,6 +614,7 @@ public without sharing class LogEntryEventHandler extends LoggerSObjectHandler { log.LoginPlatform__c = matchingAuthSessionProxy.LoginHistory.Platform; log.LoginType__c = matchingAuthSessionProxy.LoginType; log.LogoutUrl__c = matchingAuthSessionProxy.LogoutUrl; + log.ParentSessionId__c = matchingAuthSessionProxy.ParentId; log.SessionId__c = matchingAuthSessionProxy.Id; log.SessionSecurityLevel__c = matchingAuthSessionProxy.SessionSecurityLevel; log.SessionType__c = matchingAuthSessionProxy.SessionType; diff --git a/nebula-logger/core/tests/log-management/classes/LogEntryEventHandler_Tests.cls b/nebula-logger/core/tests/log-management/classes/LogEntryEventHandler_Tests.cls index 3f3729b82..107cb15ad 100644 --- a/nebula-logger/core/tests/log-management/classes/LogEntryEventHandler_Tests.cls +++ b/nebula-logger/core/tests/log-management/classes/LogEntryEventHandler_Tests.cls @@ -587,26 +587,43 @@ private class LogEntryEventHandler_Tests { logEntryEvent.SessionType__c = null; logEntryEvent.SourceIp__c = null; LoggerTestConfigurator.setMock(new LoggerParameter__mdt(DeveloperName = 'QueryAuthSessionDataSynchronously', Value__c = String.valueOf(false))); + System.Assert.isFalse(LoggerParameter.QUERY_AUTH_SESSION_DATA_SYNCHRONOUSLY); + MockLoggerEngineDataSelector mockSelector = new MockLoggerEngineDataSelector(); + LoggerEngineDataSelector.setMock(mockSelector); + LoggerSObjectProxy.LoginHistory mockLoginHistoryProxy = new LoggerSObjectProxy.LoginHistory(null); + mockLoginHistoryProxy.Application = 'Application'; + mockLoginHistoryProxy.Browser = 'Browser'; + mockLoginHistoryProxy.Platform = 'Platform'; + mockLoginHistoryProxy.UserId = System.UserInfo.getUserId(); + LoggerSObjectProxy.AuthSession mockAuthSessionProxy = new LoggerSObjectProxy.AuthSession(null); + mockAuthSessionProxy.Id = LoggerMockDataCreator.createId(Schema.AuthSession.SObjectType); + mockAuthSessionProxy.LoginHistory = mockLoginHistoryProxy; + mockAuthSessionProxy.LoginHistoryId = LoggerMockDataCreator.createId(Schema.LoginHistory.SObjectType); + mockAuthSessionProxy.LoginType = 'LoginType'; + mockAuthSessionProxy.LogoutUrl = 'LogoutUrl'; + mockAuthSessionProxy.ParentId = LoggerMockDataCreator.createId(Schema.AuthSession.SObjectType); + mockAuthSessionProxy.SessionSecurityLevel = 'SessionSecurityLevel'; + mockAuthSessionProxy.SessionType = 'SessionType'; + mockAuthSessionProxy.SourceIp = 'SourceIp'; + mockAuthSessionProxy.UsersId = System.UserInfo.getUserId(); + mockSelector.setCachedAuthSessionProxy(mockAuthSessionProxy); + System.Assert.areEqual(0, mockSelector.getCachedAuthSessionQueryCount()); LoggerMockDataStore.getEventBus().publishRecord(logEntryEvent); LoggerMockDataStore.getEventBus().deliver(new LogEntryEventHandler()); - List userIds = new List{ logEntryEvent.LoggedById__c }; - LoggerSObjectProxy.AuthSession expectedAuthSessionProxy = LoggerEngineDataSelector.getInstance() - .getAuthSessionProxies(userIds) - .get(logEntryEvent.LoggedById__c); Log__c log = getLog(); - System.Assert.areEqual(expectedAuthSessionProxy?.LoginHistory.Application, log.LoginApplication__c); - System.Assert.areEqual(expectedAuthSessionProxy?.LoginHistory.Browser, log.LoginBrowser__c); - System.Assert.areEqual(expectedAuthSessionProxy?.LoginHistoryId, log.LoginHistoryId__c); - System.Assert.areEqual(expectedAuthSessionProxy?.LoginHistory.Platform, log.LoginPlatform__c); - System.Assert.areEqual(expectedAuthSessionProxy?.LoginType, log.LoginType__c); - System.Assert.areEqual(expectedAuthSessionProxy?.LogoutUrl, log.LogoutUrl__c); - System.Assert.areEqual(expectedAuthSessionProxy?.Id, log.SessionId__c); - System.Assert.areEqual(expectedAuthSessionProxy?.ParentId, log.ParentSessionId__c); - System.Assert.areEqual(expectedAuthSessionProxy?.SessionSecurityLevel, log.SessionSecurityLevel__c); - System.Assert.areEqual(expectedAuthSessionProxy?.SessionType, log.SessionType__c); - System.Assert.areEqual(expectedAuthSessionProxy?.SourceIp, log.SourceIp__c); + System.Assert.areEqual(mockAuthSessionProxy.Id, log.SessionId__c); + System.Assert.areEqual(mockAuthSessionProxy.LoginHistory.Application, log.LoginApplication__c); + System.Assert.areEqual(mockAuthSessionProxy.LoginHistory.Browser, log.LoginBrowser__c); + System.Assert.areEqual(mockAuthSessionProxy.LoginHistory.Platform, log.LoginPlatform__c); + System.Assert.areEqual(mockAuthSessionProxy.LoginHistoryId, log.LoginHistoryId__c); + System.Assert.areEqual(mockAuthSessionProxy.LoginType, log.LoginType__c); + System.Assert.areEqual(mockAuthSessionProxy.LogoutUrl, log.LogoutUrl__c); + System.Assert.areEqual(mockAuthSessionProxy.ParentId, log.ParentSessionId__c); + System.Assert.areEqual(mockAuthSessionProxy.SessionSecurityLevel, log.SessionSecurityLevel__c); + System.Assert.areEqual(mockAuthSessionProxy.SessionType, log.SessionType__c); + System.Assert.areEqual(mockAuthSessionProxy.SourceIp, log.SourceIp__c); } @IsTest @@ -1793,4 +1810,25 @@ private class LogEntryEventHandler_Tests { ); System.Assert.areEqual(logEntryEvent.TriggerSObjectType__c, logEntry.TriggerSObjectType__c, 'logEntry.TriggerSObjectType__c was not properly set'); } + + private class MockLoggerEngineDataSelector extends LoggerEngineDataSelector { + private Integer authSessionProxiesQueryCount = 0; + private LoggerSObjectProxy.AuthSession mockAuthSessionProxy; + + public Integer getCachedAuthSessionQueryCount() { + return authSessionProxiesQueryCount; + } + + public override Map getAuthSessionProxies(List userIds) { + this.authSessionProxiesQueryCount++; + if (this.mockAuthSessionProxy != null) { + return new Map{ mockAuthSessionProxy.UsersId => mockAuthSessionProxy }; + } + return super.getAuthSessionProxies(userIds); + } + + public void setCachedAuthSessionProxy(LoggerSObjectProxy.AuthSession mockAuthSessionProxy) { + this.mockAuthSessionProxy = mockAuthSessionProxy; + } + } } diff --git a/nebula-logger/core/tests/logger-engine/classes/LogEntryEventBuilder_Tests.cls b/nebula-logger/core/tests/logger-engine/classes/LogEntryEventBuilder_Tests.cls index 32934ab74..b1bd1699a 100644 --- a/nebula-logger/core/tests/logger-engine/classes/LogEntryEventBuilder_Tests.cls +++ b/nebula-logger/core/tests/logger-engine/classes/LogEntryEventBuilder_Tests.cls @@ -1858,6 +1858,10 @@ private class LogEntryEventBuilder_Tests { private Integer cachedUserQueryCount = 0; private LoggerSObjectProxy.AuthSession mockAuthSessionProxy; + public Integer getCachedAuthSessionQueryCount() { + return cachedAuthSessionQueryCount; + } + public override LoggerSObjectProxy.AuthSession getCachedAuthSessionProxy() { this.cachedAuthSessionQueryCount++; if (this.mockAuthSessionProxy != null) { @@ -1870,10 +1874,6 @@ private class LogEntryEventBuilder_Tests { this.mockAuthSessionProxy = mockAuthSessionProxy; } - public Integer getCachedAuthSessionQueryCount() { - return cachedAuthSessionQueryCount; - } - public override Schema.Organization getCachedOrganization() { this.cachedOrganizationQueryCount++; return super.getCachedOrganization();