Skip to content

Commit

Permalink
LDEV-4166 improve test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Jan 12, 2024
1 parent 0fa5a1f commit d19daaf
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 30 additions & 9 deletions test/tickets/LDEV4166.cfc
Original file line number Diff line number Diff line change
@@ -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");
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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)#";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<cfscript>
sessionInvalidate(); // make SessionInvalidate
echo( session.sessionid );
initialSessionId = session.sessionid;
sessionInvalidate();
echo( initialSessionId );
</cfscript>
Original file line number Diff line number Diff line change
@@ -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)#";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<cfscript>
sessionInvalidate(); // make sessionInvalidate
echo( session.sessionid );
initialSessionId = session.sessionid;
sessionInvalidate();
echo( initialSessionId );
</cfscript>

0 comments on commit d19daaf

Please sign in to comment.