Skip to content

Commit 80de3da

Browse files
committed
add test descriptiongs
1 parent cf813c8 commit 80de3da

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

integration/tests/session-token-cache/multi-session.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import { appConfigs } from '../../presets';
44
import type { FakeUser } from '../../testUtils';
55
import { createTestUtils, testAgainstRunningApps } from '../../testUtils';
66

7+
/**
8+
* Tests MemoryTokenCache session isolation in multi-session scenarios
9+
*
10+
* This suite validates that when multiple user sessions exist simultaneously,
11+
* each session maintains its own isolated token cache. Tokens are not shared
12+
* between different sessions, even within the same tab, ensuring proper
13+
* security boundaries between users.
14+
*/
715
testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
816
'MemoryTokenCache Multi-Session Integration @nextjs',
917
({ app }) => {
@@ -26,6 +34,23 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })(
2634
await app.teardown();
2735
});
2836

37+
/**
38+
* Test Flow:
39+
* 1. Tab1: Sign in as user1, fetch and cache their token
40+
* 2. Tab2: Opens and inherits user1's session via cookies
41+
* 3. Tab2: Sign in as user2 using programmatic sign-in (preserves both sessions)
42+
* 4. Tab2: Now has two active sessions (user1 and user2)
43+
* 5. Tab2: Switch between sessions and fetch tokens for each
44+
* 6. Verify no network requests occur (tokens served from cache)
45+
* 7. Tab1: Verify it still has user1 as active session (tab independence)
46+
*
47+
* Expected Behavior:
48+
* - Each session has its own isolated token cache
49+
* - Switching sessions in tab2 returns different tokens
50+
* - Both tokens are served from cache (no network requests)
51+
* - Tab1 remains unaffected by tab2's session changes
52+
* - Multi-session state is properly maintained per-tab
53+
*/
2954
test('MemoryTokenCache multi-session - multiple users in different tabs with separate token caches', async ({
3055
context,
3156
}) => {

integration/tests/session-token-cache/single-session.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import { appConfigs } from '../../presets';
44
import type { FakeUser } from '../../testUtils';
55
import { createTestUtils, testAgainstRunningApps } from '../../testUtils';
66

7+
/**
8+
* Tests MemoryTokenCache cross-tab token sharing via BroadcastChannel
9+
*
10+
* This suite validates that when multiple browser tabs share the same user session,
11+
* token fetches in one tab are automatically broadcast and cached in other tabs,
12+
* eliminating redundant network requests.
13+
*/
714
testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })(
815
'MemoryTokenCache Multi-Tab Integration @generic',
916
({ app }) => {
@@ -25,6 +32,20 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })(
2532
await app.teardown();
2633
});
2734

35+
/**
36+
* Test Flow:
37+
* 1. Open two tabs with the same browser context (shared cookies)
38+
* 2. Sign in on tab1, which creates a session
39+
* 3. Reload tab2 to pick up the session from cookies
40+
* 4. Clear token cache on both tabs
41+
* 5. Fetch token on tab1 (triggers network request + broadcast)
42+
* 6. Fetch token on tab2 (should use broadcasted token, no network request)
43+
*
44+
* Expected Behavior:
45+
* - Both tabs receive identical tokens
46+
* - Only ONE network request is made (from tab1)
47+
* - Tab2 gets the token via BroadcastChannel, proving cross-tab cache sharing
48+
*/
2849
test('MemoryTokenCache multi-tab token sharing', async ({ context }) => {
2950
const page1 = await context.newPage();
3051
const page2 = await context.newPage();

0 commit comments

Comments
 (0)