-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: Add cookieSessionStore option to support multi-replica deployments
#3016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
9
commits into
alpha
Choose a base branch
from
copilot/fix-csrf-token-validation
base: alpha
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+232
−4
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1b2e6b8
Initial plan
Copilot 0d763dd
Add sessionStore option for multi-replica deployments
Copilot dbb1c94
Add tests for sessionStore functionality
Copilot 3b69608
Add example configurations for multi-replica deployments
Copilot ed88924
Remove example files and simplify README with session store list
Copilot 6c87a73
Add simple connect-redis example to README
Copilot a2170b4
Apply suggestion from @mtrezza
mtrezza ce564c8
Apply suggestion from @mtrezza
mtrezza faaeb2d
Rename sessionStore to cookieSessionStore across the codebase
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| /* | ||
| * Copyright (c) 2016-present, Parse, LLC | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the license found in the LICENSE file in | ||
| * the root directory of this source tree. | ||
| */ | ||
| jest.dontMock('../../../Parse-Dashboard/Authentication.js'); | ||
| jest.dontMock('../../../Parse-Dashboard/app.js'); | ||
|
|
||
| const express = require('express'); | ||
| const session = require('express-session'); | ||
| const Authentication = require('../../../Parse-Dashboard/Authentication'); | ||
|
|
||
| describe('SessionStore Integration', () => { | ||
| it('uses default in-memory store when sessionStore is not provided', () => { | ||
| const app = express(); | ||
| const users = [{ user: 'test', pass: 'password' }]; | ||
| const auth = new Authentication(users, false, '/'); | ||
|
|
||
| // Mock app.use to capture session configuration | ||
| const useSpy = jest.fn(); | ||
| app.use = useSpy; | ||
|
|
||
| auth.initialize(app, {}); | ||
|
|
||
| // Find the call that sets up express-session | ||
| const sessionCall = useSpy.mock.calls.find(call => | ||
| call[0] && call[0].name === 'session' | ||
| ); | ||
|
|
||
| expect(sessionCall).toBeDefined(); | ||
| // When no store is provided, express-session uses MemoryStore by default | ||
| // The session function should be called without a custom store | ||
| }); | ||
|
|
||
| it('uses custom session store when sessionStore is provided', () => { | ||
| const app = express(); | ||
| const users = [{ user: 'test', pass: 'password' }]; | ||
| const auth = new Authentication(users, false, '/'); | ||
|
|
||
| // Create a mock session store that implements the Store interface | ||
| const Store = session.Store; | ||
| class MockStore extends Store { | ||
| constructor() { | ||
| super(); | ||
| } | ||
| get(sid, callback) { | ||
| callback(null, {}); | ||
| } | ||
| set(sid, session, callback) { | ||
| callback(null); | ||
| } | ||
| destroy(sid, callback) { | ||
| callback(null); | ||
| } | ||
| } | ||
|
|
||
| const mockStore = new MockStore(); | ||
|
|
||
| // Mock app.use to capture session configuration | ||
| const useSpy = jest.fn(); | ||
| app.use = useSpy; | ||
|
|
||
| auth.initialize(app, { sessionStore: mockStore }); | ||
|
|
||
| // The session middleware should have been configured | ||
| expect(useSpy).toHaveBeenCalled(); | ||
|
|
||
| // Find the call that sets up express-session | ||
| const sessionCall = useSpy.mock.calls.find(call => | ||
| call[0] && call[0].name === 'session' | ||
| ); | ||
|
|
||
| expect(sessionCall).toBeDefined(); | ||
| }); | ||
|
|
||
| it('passes sessionStore through app.js to Authentication', () => { | ||
| const parseDashboard = require('../../../Parse-Dashboard/app.js'); | ||
|
|
||
| // Create a mock session store that implements the Store interface | ||
| const Store = session.Store; | ||
| class MockStore extends Store { | ||
| constructor() { | ||
| super(); | ||
| } | ||
| get(sid, callback) { | ||
| callback(null, {}); | ||
| } | ||
| set(sid, session, callback) { | ||
| callback(null); | ||
| } | ||
| destroy(sid, callback) { | ||
| callback(null); | ||
| } | ||
| } | ||
|
|
||
| const mockStore = new MockStore(); | ||
|
|
||
| const config = { | ||
| apps: [ | ||
| { | ||
| serverURL: 'http://localhost:1337/parse', | ||
| appId: 'testAppId', | ||
| masterKey: 'testMasterKey', | ||
| appName: 'TestApp', | ||
| }, | ||
| ], | ||
| users: [ | ||
| { | ||
| user: 'testuser', | ||
| pass: 'testpass', | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const options = { | ||
| sessionStore: mockStore, | ||
| cookieSessionSecret: 'test-secret', | ||
| }; | ||
|
|
||
| // Create dashboard app | ||
| const dashboardApp = parseDashboard(config, options); | ||
|
|
||
| // The app should be created successfully with the session store | ||
| expect(dashboardApp).toBeDefined(); | ||
| expect(typeof dashboardApp).toBe('function'); // Express app is a function | ||
| }); | ||
|
|
||
| it('maintains backward compatibility without sessionStore option', () => { | ||
| const parseDashboard = require('../../../Parse-Dashboard/app.js'); | ||
|
|
||
| const config = { | ||
| apps: [ | ||
| { | ||
| serverURL: 'http://localhost:1337/parse', | ||
| appId: 'testAppId', | ||
| masterKey: 'testMasterKey', | ||
| appName: 'TestApp', | ||
| }, | ||
| ], | ||
| users: [ | ||
| { | ||
| user: 'testuser', | ||
| pass: 'testpass', | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const options = { | ||
| cookieSessionSecret: 'test-secret', | ||
| }; | ||
|
|
||
| // Create dashboard app without sessionStore option | ||
| const dashboardApp = parseDashboard(config, options); | ||
|
|
||
| // The app should be created successfully even without session store | ||
| expect(dashboardApp).toBeDefined(); | ||
| expect(typeof dashboardApp).toBe('function'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.