forked from laurent22/joplin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server: Expire sessions after 12 hours
- Loading branch information
Showing
5 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,46 @@ | ||
import { createUserAndSession, beforeAllDb, afterAllTests, beforeEachDb, models } from '../utils/testing/testUtils'; | ||
import { defaultSessionTtl } from './SessionModel'; | ||
|
||
describe('SessionModel', function() { | ||
|
||
beforeAll(async () => { | ||
await beforeAllDb('SessionModel'); | ||
}); | ||
|
||
afterAll(async () => { | ||
await afterAllTests(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await beforeEachDb(); | ||
}); | ||
|
||
test('should delete expired sessions', async function() { | ||
jest.useFakeTimers('modern'); | ||
|
||
const t0 = new Date('2020-01-01T00:00:00').getTime(); | ||
jest.setSystemTime(t0); | ||
|
||
const { user, password } = await createUserAndSession(1); | ||
await models().session().authenticate(user.email, password); | ||
|
||
jest.setSystemTime(new Date(t0 + defaultSessionTtl + 10)); | ||
|
||
const lastSession = await models().session().authenticate(user.email, password); | ||
|
||
expect(await models().session().count()).toBe(3); | ||
|
||
await models().session().deleteExpiredSessions(); | ||
|
||
expect(await models().session().count()).toBe(1); | ||
expect((await models().session().all())[0].id).toBe(lastSession.id); | ||
|
||
await models().session().authenticate(user.email, password); | ||
await models().session().deleteExpiredSessions(); | ||
|
||
expect(await models().session().count()).toBe(2); | ||
|
||
jest.useRealTimers(); | ||
}); | ||
|
||
}); |
This file contains 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 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 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 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