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 2108bbba22..3b016cb238 100755 --- a/core/src/main/java/lucee/runtime/type/scope/ScopeContext.java +++ b/core/src/main/java/lucee/runtime/type/scope/ScopeContext.java @@ -999,6 +999,15 @@ public void invalidateUserScope(PageContextImpl pc, boolean migrateSessionData, Map sessionContext = getSubMap(cfSessionContexts, appContext.getName()); UserScope oldSession = (UserScope) sessionContext.get(pc.getCFID()); + ApplicationListener listener = factory.getConfig().getApplicationListener(); + try { + listener.onSessionEnd(factory, appContext.getName(), pc.getCFID()); + } + catch (Throwable t) { + ExceptionUtil.rethrowIfNecessary(t); + ExceptionHandler.log(pc.getConfig(), Caster.toPageException(t)); + } + // remove Scopes completly removeCFSessionScope(pc); removeClientScope(pc); diff --git a/test/tickets/LDEV3478.cfc b/test/tickets/LDEV3478.cfc index c489ce7593..f802eb95e6 100644 --- a/test/tickets/LDEV3478.cfc +++ b/test/tickets/LDEV3478.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.LDEV3478_ended_CFML_Sessions = {}; - server.LDEV3478_ended_JEE_Sessions = {}; + server.LDEV3478_ended_CFML_Sessions = {}; + server.LDEV3478_ended_JEE_Sessions = {}; } - function afterAll(){ + function afterAll(){ //systemOutput("ended sessionids:" & structKeyList(server.LDEV3478_endedSessions), true); structDelete(server, "LDEV3478_ended_CFML_Sessions"); structDelete(server, "LDEV3478_ended_JEE_Sessions"); @@ -16,46 +16,54 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="session" skip=true it( title='cfml session - onSessionEnd with sessionRotate()', body=function( currentSpec ) { uri = createURI("LDEV3478"); local.cfmlSessionId = _InternalRequest( - template : "#uri#\cfml_session_rotate\test_cfml_sessionend.cfm" + template : "#uri#/cfml_session_rotate/test_cfml_sessionend.cfm" ); //dumpResult( "cfmlSessionId: " & cfmlSessionId.filecontent ); expect( len( cfmlSessionId.filecontent ) ).toBeGT( 0 ); + + var appName = listFirst( trim( cfmlSessionId.filecontent ), '-' ) & "-"; + expect( getSessionCount( appName ) ).toBe( 1 ); // allow session to expire - sleep(1001); + sleep( 1001 ); admin action="purgeExpiredSessions" type="server" password="#request.SERVERADMINPASSWORD#"; - - //dumpResult( result.filecontent ); - expect( structKeyExists(server.LDEV3478_ended_CFML_Sessions, trim(cfmlSessionId.filecontent)) ).toBeTrue(); + + // let's check first that the session actually ended! + expect( getSessionCount( appName ) ).toBe( 0 ); + expect( structKeyExists( server.LDEV3478_ended_CFML_Sessions, trim( cfmlSessionId.filecontent ) ) ).toBeTrue(); }); it( title='jee session - onSessionEnd with sessionRotate()', body=function( currentSpec ) { uri = createURI("LDEV3478"); local.j2eeSessionId = _InternalRequest( - template : "#uri#\jee_session_rotate\test_jee_sessionend.cfm" + template : "#uri#/jee_session_rotate/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); + sleep( 1001 ); admin action="purgeExpiredSessions" type="server" password="#request.SERVERADMINPASSWORD#"; - - // dumpResult( result.filecontent ); - expect( structKeyExists(server.LDEV3478_ended_JEE_Sessions, trim(j2eeSessionId.filecontent)) ).toBeTrue(); + expect( getSessionCount( appName ) ).toBe( 0 ); + expect( structKeyExists( server.LDEV3478_ended_JEE_Sessions, trim( j2eeSessionId.filecontent ) ) ).toBeTrue(); }); }); } -// private function dumpResult(r){ -// // systemOutput("---", true); -// systemOutput(r, true); -// // systemOutput("---", true); -// } + 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()),"\/")#/"; diff --git a/test/tickets/LDEV3478/Jee_session_rotate/Application.cfc b/test/tickets/LDEV3478/Jee_session_rotate/Application.cfc index d1b9efa845..0fadbfe625 100644 --- a/test/tickets/LDEV3478/Jee_session_rotate/Application.cfc +++ b/test/tickets/LDEV3478/Jee_session_rotate/Application.cfc @@ -1,5 +1,5 @@ component { - this.name="onsessionend_jee_sessionRotate"; + this.name="ldev3478_onsessionend_jee_sessionRotate-"; this.sessionManagement = true; this.sessionStorage="memory"; this.sessiontimeout="#createTimeSpan(0,0,0,1)#"; @@ -21,7 +21,6 @@ component { } function onSessionEnd(SessionScope, ApplicationScope) { - // systemOutput("#now()# session ended #cgi.SCRIPT_NAME# #sessionScope.sessionid#", true); server.LDEV3478_ended_JEE_Sessions[ arguments.sessionScope.sessionid ] = now(); } diff --git a/test/tickets/LDEV3478/Jee_session_rotate/test_jee_sessionEnd.cfm b/test/tickets/LDEV3478/Jee_session_rotate/test_jee_sessionEnd.cfm index 53bb83272a..45f30658ae 100644 --- a/test/tickets/LDEV3478/Jee_session_rotate/test_jee_sessionEnd.cfm +++ b/test/tickets/LDEV3478/Jee_session_rotate/test_jee_sessionEnd.cfm @@ -1,4 +1,5 @@ - sessionRotate(); // make session Rotate - echo( session.sessionid ); + initialSessionId = session.sessionid; + sessionRotate(); + echo( initialSessionId ); \ No newline at end of file diff --git a/test/tickets/LDEV3478/cfml_session_rotate/Application.cfc b/test/tickets/LDEV3478/cfml_session_rotate/Application.cfc index 3f3ab5f67b..f900d460d1 100644 --- a/test/tickets/LDEV3478/cfml_session_rotate/Application.cfc +++ b/test/tickets/LDEV3478/cfml_session_rotate/Application.cfc @@ -1,5 +1,5 @@ component { - this.name="onsessionend_cfml_sessionRotate"; + this.name="ldev3478_onsessionend_cfml_sessionRotate-"; this.sessionManagement = true; this.sessionStorage="memory"; this.sessiontimeout="#createTimeSpan(0,0,0,1)#"; @@ -21,7 +21,6 @@ component { } function onSessionEnd(SessionScope, ApplicationScope) { - // systemOutput("#now()# session ended #cgi.SCRIPT_NAME# #sessionScope.sessionid#", true); server.LDEV3478_ended_CFML_Sessions[ arguments.sessionScope.sessionid ] = now(); } diff --git a/test/tickets/LDEV3478/cfml_session_rotate/test_cfml_sessionEnd.cfm b/test/tickets/LDEV3478/cfml_session_rotate/test_cfml_sessionEnd.cfm index 53bb83272a..45f30658ae 100644 --- a/test/tickets/LDEV3478/cfml_session_rotate/test_cfml_sessionEnd.cfm +++ b/test/tickets/LDEV3478/cfml_session_rotate/test_cfml_sessionEnd.cfm @@ -1,4 +1,5 @@ - sessionRotate(); // make session Rotate - echo( session.sessionid ); + initialSessionId = session.sessionid; + sessionRotate(); + echo( initialSessionId ); \ No newline at end of file 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