Skip to content

Commit 4bbb46a

Browse files
committed
test: add tests for terminatedManually session reactivation
- Add SECURITY TEST 4: Session reactivation after timeout - Add SECURITY TEST 5: Manual logout blocks access - Add simulate-timeout admin endpoint for testing - Update test numbering (now 6 security tests) Tests verify: - Sessions with terminatedManually: false can be reactivated - Sessions with terminatedManually: true are blocked permanently
1 parent 8e4b504 commit 4bbb46a

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

server/src/controllers/session.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,47 @@ module.exports = {
493493
}
494494
},
495495

496+
/**
497+
* Simulate session timeout for testing (Admin action)
498+
* POST /magic-sessionmanager/sessions/:sessionId/simulate-timeout
499+
* Sets isActive: false, terminatedManually: false (as if cleanup job ran)
500+
* This allows testing session reactivation behavior
501+
*/
502+
async simulateTimeout(ctx) {
503+
try {
504+
const { sessionId } = ctx.params;
505+
506+
// Find the session first
507+
const session = await strapi.documents(SESSION_UID).findOne({
508+
documentId: sessionId,
509+
});
510+
511+
if (!session) {
512+
return ctx.notFound('Session not found');
513+
}
514+
515+
// Simulate timeout: set isActive false but terminatedManually false
516+
await strapi.documents(SESSION_UID).update({
517+
documentId: sessionId,
518+
data: {
519+
isActive: false,
520+
terminatedManually: false, // This allows reactivation!
521+
},
522+
});
523+
524+
strapi.log.info(`[magic-sessionmanager] [TEST] Session ${sessionId} simulated timeout (terminatedManually: false)`);
525+
526+
ctx.body = {
527+
message: `Session ${sessionId} marked as timed out (reactivatable)`,
528+
success: true,
529+
terminatedManually: false,
530+
};
531+
} catch (err) {
532+
strapi.log.error('[magic-sessionmanager] Error simulating timeout:', err);
533+
ctx.throw(500, 'Error simulating session timeout');
534+
}
535+
},
536+
496537
/**
497538
* Terminate a single session (Admin action)
498539
* POST /magic-sessionmanager/sessions/:sessionId/terminate

server/src/routes/admin.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ module.exports = {
3939
description: 'Terminate a specific session (admin)',
4040
},
4141
},
42+
{
43+
method: 'POST',
44+
path: '/sessions/:sessionId/simulate-timeout',
45+
handler: 'session.simulateTimeout',
46+
config: {
47+
policies: ['admin::isAuthenticatedAdmin'],
48+
description: 'Simulate session timeout for testing (sets isActive: false, terminatedManually: false)',
49+
},
50+
},
4251
{
4352
method: 'DELETE',
4453
path: '/sessions/:sessionId',

0 commit comments

Comments
 (0)