-
-
Notifications
You must be signed in to change notification settings - Fork 729
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
feat: show deleted user sessions #8749
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
98f2cbb
feat: show deleted user sessions
kwasniew 638c377
feat: show deleted user sessions
kwasniew 80c3ba6
feat: show deleted user sessions
kwasniew 9b80501
feat: show deleted user sessions
kwasniew 8e80a4f
feat: show deleted user sessions
kwasniew eac1071
feat: show deleted user sessions
kwasniew 8834f00
feat: show deleted user sessions
kwasniew 567576a
feat: show deleted user sessions
kwasniew 4a7962a
feat: show deleted user sessions
kwasniew 0795bbd
feat: show deleted user sessions
kwasniew 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 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
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
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ import PasswordMismatch from '../../../lib/error/password-mismatch'; | |
import type { EventService } from '../../../lib/services'; | ||
import { | ||
CREATE_ADDON, | ||
type IFlagResolver, | ||
type IUnleashStores, | ||
type IUserStore, | ||
SYSTEM_USER_AUDIT, | ||
|
@@ -45,6 +46,8 @@ let eventService: EventService; | |
let accessService: AccessService; | ||
let eventBus: EventEmitter; | ||
|
||
const allowedSessions = 2; | ||
|
||
beforeAll(async () => { | ||
db = await dbInit('user_service_serial', getLogger); | ||
stores = db.stores; | ||
|
@@ -63,14 +66,31 @@ beforeAll(async () => { | |
sessionService = new SessionService(stores, config); | ||
settingService = new SettingService(stores, config, eventService); | ||
|
||
userService = new UserService(stores, config, { | ||
accessService, | ||
resetTokenService, | ||
emailService, | ||
eventService, | ||
sessionService, | ||
settingService, | ||
}); | ||
const flagResolver = { | ||
isEnabled() { | ||
return true; | ||
}, | ||
getVariant() { | ||
return { | ||
feature_enabled: true, | ||
payload: { | ||
value: String(allowedSessions), | ||
}, | ||
}; | ||
}, | ||
} as unknown as IFlagResolver; | ||
userService = new UserService( | ||
stores, | ||
{ ...config, flagResolver }, | ||
{ | ||
accessService, | ||
resetTokenService, | ||
emailService, | ||
eventService, | ||
sessionService, | ||
settingService, | ||
}, | ||
); | ||
userStore = stores.userStore; | ||
const rootRoles = await accessService.getRootRoles(); | ||
adminRole = rootRoles.find((r) => r.name === RoleName.ADMIN)!; | ||
|
@@ -95,8 +115,9 @@ afterAll(async () => { | |
await db.destroy(); | ||
}); | ||
|
||
afterEach(async () => { | ||
beforeEach(async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's a better practice to clean data before not after since it allows debugging failed tests |
||
await userStore.deleteAll(); | ||
await settingService.deleteAll(); | ||
}); | ||
|
||
test('should create initial admin user', async () => { | ||
|
@@ -361,6 +382,42 @@ test("deleting a user should delete the user's sessions", async () => { | |
expect(noSessions.length).toBe(0); | ||
}); | ||
|
||
test('user login should remove stale sessions', async () => { | ||
const email = '[email protected]'; | ||
const user = await userService.createUser( | ||
{ | ||
email, | ||
password: 'A very strange P4ssw0rd_', | ||
rootRole: adminRole.id, | ||
}, | ||
TEST_AUDIT_USER, | ||
); | ||
const userSession = (index: number) => ({ | ||
sid: `sid${index}`, | ||
sess: { | ||
cookie: { | ||
originalMaxAge: minutesToMilliseconds(48), | ||
expires: addDays(Date.now(), 1).toDateString(), | ||
secure: false, | ||
httpOnly: true, | ||
path: '/', | ||
}, | ||
user, | ||
}, | ||
}); | ||
|
||
for (let i = 0; i < allowedSessions; i++) { | ||
await sessionService.insertSession(userSession(i)); | ||
} | ||
|
||
const insertedUser = await userService.loginUser( | ||
email, | ||
'A very strange P4ssw0rd_', | ||
); | ||
|
||
expect(insertedUser.deletedSessions).toBe(1); | ||
}); | ||
|
||
test('updating a user without an email should not strip the email', async () => { | ||
const email = '[email protected]'; | ||
const user = await userService.createUser( | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tymek I'm using the field that you added to user schema