From d19daaf276d26b9dcedb26e8b029b9be6122a2c2 Mon Sep 17 00:00:00 2001 From: Zac Spitzer Date: Fri, 12 Jan 2024 14:28:03 +0100 Subject: [PATCH] LDEV-4166 improve test case --- .../runtime/type/scope/ScopeContext.java | 2 +- test/tickets/LDEV4166.cfc | 39 ++++++++++++++----- .../Jee_session_Invalidate/Application.cfc | 2 +- .../test_jee_sessionEnd.cfm | 5 ++- .../cfml_session_Invalidate/Application.cfc | 2 +- .../test_cfml_sessionEnd.cfm | 5 ++- 6 files changed, 39 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/lucee/runtime/type/scope/ScopeContext.java b/core/src/main/java/lucee/runtime/type/scope/ScopeContext.java index fb6c49c773..3b016cb238 100755 --- a/core/src/main/java/lucee/runtime/type/scope/ScopeContext.java +++ b/core/src/main/java/lucee/runtime/type/scope/ScopeContext.java @@ -1005,7 +1005,7 @@ public void invalidateUserScope(PageContextImpl pc, boolean migrateSessionData, } catch (Throwable t) { ExceptionUtil.rethrowIfNecessary(t); - ExceptionHandler.log(pc.getCfmlFactory(), Caster.toPageException(t)); + ExceptionHandler.log(pc.getConfig(), Caster.toPageException(t)); } // remove Scopes completly diff --git a/test/tickets/LDEV4166.cfc b/test/tickets/LDEV4166.cfc index 940db7b89f..f567ce01ce 100644 --- a/test/tickets/LDEV4166.cfc +++ b/test/tickets/LDEV4166.cfc @@ -1,11 +1,11 @@ -component extends="org.lucee.cfml.test.LuceeTestCase" labels="session" skip="true" { +component extends="org.lucee.cfml.test.LuceeTestCase" labels="session" { function beforeAll(){ - server.LDEV4166_ended_CFML_Sessions = {}; + server.LDEV4166_ended_CFML_Sessions = {}; server.LDEV4166_ended_JEE_Sessions = {}; } - function afterAll(){ + function afterAll(){ structDelete(server, "LDEV4166_ended_CFML_Sessions"); structDelete(server, "LDEV4166_ended_JEE_Sessions"); } @@ -15,39 +15,60 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="session" skip="tru it( title='cfml session - onSessionEnd with SessionInvalidate()', body=function( currentSpec ) { uri = createURI("LDEV4166"); local.cfmlSessionId = _InternalRequest( - template : "#uri#\cfml_session_invalidate\test_cfml_sessionend.cfm" + template : "#uri#/cfml_session_invalidate/test_cfml_sessionend.cfm" ); //dumpResult( "cfmlSessionId: " & cfmlSessionId.filecontent ); expect( len( cfmlSessionId.filecontent ) ).toBeGT( 0 ); + + var appName = listFirst( trim( cfmlSessionId.filecontent ), '-' ) & "-" ; + // allow session to expire + expect( getSessionCount( appName ) ).toBe( 1 ); + sleep(1001); admin action="purgeExpiredSessions" type="server" password="#request.SERVERADMINPASSWORD#"; - - expect( structKeyExists(server.LDEV4166_ended_CFML_Sessions, trim(cfmlSessionId.filecontent)) ).toBeTrue(); + //systemOutput(server.LDEV4166_ended_CFML_Sessions, true); + // let's check first that the session actually ended! + expect( getSessionCount( appName ) ).toBe( 0 ); + expect( structKeyExists( server.LDEV4166_ended_CFML_Sessions, trim( cfmlSessionId.filecontent ) ) ).toBeTrue(); }); it( title='jee session - onSessionEnd with SessionInvalidate()', body=function( currentSpec ) { uri = createURI("LDEV4166"); local.j2eeSessionId = _InternalRequest( - template : "#uri#\jee_session_invalidate\test_jee_sessionend.cfm" + template : "#uri#/jee_session_invalidate/test_jee_sessionend.cfm" ); //dumpResult( "j2eeSessionId: " & j2eeSessionId.filecontent ); expect( len( j2eeSessionId.filecontent ) ).toBeGT( 0 ); + + var appName = listFirst( trim( j2eeSessionId.filecontent ), '-' ) & "-" ; + + expect( getSessionCount( appName ) ).toBe( 1 ); // allow session to expire sleep(1001); admin action="purgeExpiredSessions" type="server" password="#request.SERVERADMINPASSWORD#"; - - expect( structKeyExists(server.LDEV4166_ended_JEE_Sessions, trim(j2eeSessionId.filecontent)) ).toBeTrue(); + //systemOutput(server.LDEV4166_ended_JEE_Sessions, true); + // let's check first that the session actually ended! + expect( getSessionCount( appName ) ).toBe( 0 ); + expect( structKeyExists( server.LDEV4166_ended_JEE_Sessions, trim( j2eeSessionId.filecontent ) ) ).toBeTrue(); }); }); } + private numeric function getSessionCount( applicationName ){ + var sess = getPageContext().getCFMLFactory().getScopeContext().getAllCFSessionScopes(); + if ( structKeyExists( sess, arguments.applicationName ) ) + return len( sess[ arguments.applicationName ] ); + else + return 0; + } + private string function createURI(string calledName){ var baseURI = "/test/#listLast(getDirectoryFromPath(getCurrentTemplatePath()),"\/")#/"; return baseURI&""&calledName; diff --git a/test/tickets/LDEV4166/Jee_session_Invalidate/Application.cfc b/test/tickets/LDEV4166/Jee_session_Invalidate/Application.cfc index ef7e6db534..6b7dab8d6b 100644 --- a/test/tickets/LDEV4166/Jee_session_Invalidate/Application.cfc +++ b/test/tickets/LDEV4166/Jee_session_Invalidate/Application.cfc @@ -1,5 +1,5 @@ component { - this.name="onsessionend_jee_sessionInvalidate"; + this.name="onsessionend_jee_sessionInvalidate-"; this.sessionManagement = true; this.sessionStorage="memory"; this.sessiontimeout="#createTimeSpan(0,0,0,1)#"; diff --git a/test/tickets/LDEV4166/Jee_session_Invalidate/test_jee_sessionEnd.cfm b/test/tickets/LDEV4166/Jee_session_Invalidate/test_jee_sessionEnd.cfm index b5bc9840c0..5a8edb8c69 100644 --- a/test/tickets/LDEV4166/Jee_session_Invalidate/test_jee_sessionEnd.cfm +++ b/test/tickets/LDEV4166/Jee_session_Invalidate/test_jee_sessionEnd.cfm @@ -1,4 +1,5 @@ - sessionInvalidate(); // make SessionInvalidate - echo( session.sessionid ); + initialSessionId = session.sessionid; + sessionInvalidate(); + echo( initialSessionId ); \ No newline at end of file diff --git a/test/tickets/LDEV4166/cfml_session_Invalidate/Application.cfc b/test/tickets/LDEV4166/cfml_session_Invalidate/Application.cfc index 979d8c22c5..59716ecba9 100644 --- a/test/tickets/LDEV4166/cfml_session_Invalidate/Application.cfc +++ b/test/tickets/LDEV4166/cfml_session_Invalidate/Application.cfc @@ -1,5 +1,5 @@ component { - this.name="onsessionend_cfml_sessionInvalidate"; + this.name="onsessionend_cfml_sessionInvalidate-"; this.sessionManagement = true; this.sessionStorage="memory"; this.sessiontimeout="#createTimeSpan(0,0,0,1)#"; diff --git a/test/tickets/LDEV4166/cfml_session_Invalidate/test_cfml_sessionEnd.cfm b/test/tickets/LDEV4166/cfml_session_Invalidate/test_cfml_sessionEnd.cfm index c164506b7a..5a8edb8c69 100644 --- a/test/tickets/LDEV4166/cfml_session_Invalidate/test_cfml_sessionEnd.cfm +++ b/test/tickets/LDEV4166/cfml_session_Invalidate/test_cfml_sessionEnd.cfm @@ -1,4 +1,5 @@ - sessionInvalidate(); // make sessionInvalidate - echo( session.sessionid ); + initialSessionId = session.sessionid; + sessionInvalidate(); + echo( initialSessionId ); \ No newline at end of file