Skip to content

Commit 1fecbd8

Browse files
authored
Merge pull request #109 from stephschuster/master
send impersonator user id field to db
2 parents 897b68d + a918116 commit 1fecbd8

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

packages/server/src/AccountsServer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,10 @@ export class AccountsServer {
375375
return { authorized: false };
376376
}
377377

378-
const newSessionId = await this.db.createSession(impersonatedUser.id, ip, userAgent);
378+
const newSessionId = await this.db.createSession(impersonatedUser.id,
379+
ip,
380+
userAgent,
381+
{ impersonatorUserId: user.id });
379382
const impersonationTokens = this.createTokens(newSessionId, true);
380383
const impersonationResult = {
381384
authorized: true,

packages/server/src/AccountsServer.spec.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,7 @@ describe('Accounts', () => {
14291429

14301430
it('returns correct response if authorized', async () => {
14311431
const { accessToken } = Accounts.createTokens('555');
1432+
const createSession = jest.fn(() => Promise.resolve('001'));
14321433
Accounts.config(
14331434
{
14341435
//eslint-disable-next-line
@@ -1439,7 +1440,7 @@ describe('Accounts', () => {
14391440
{
14401441
findUserById: () => Promise.resolve(user),
14411442
findUserByUsername: () => Promise.resolve(impersonatedUser),
1442-
createSession: () => Promise.resolve('001'),
1443+
createSession,
14431444
},
14441445
);
14451446

@@ -1455,6 +1456,10 @@ describe('Accounts', () => {
14551456
tokens: { sessionId: '001', isImpersonated: true },
14561457
user: impersonatedUser,
14571458
});
1459+
expect(createSession).toHaveBeenCalledWith(impersonatedUser.id,
1460+
undefined,
1461+
undefined,
1462+
{ impersonatorUserId: user.id });
14581463
});
14591464
});
14601465

packages/server/src/DBInterface.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface DBInterface {
3333

3434
// Session related operations
3535
findSessionById(sessionId: string) : Promise<?SessionType>,
36-
createSession(userId: string, ip: ?string, userAgent: ?string) : Promise<string>,
36+
createSession(userId: string, ip: ?string, userAgent: ?string, extraData: ?Object) : Promise<string>,
3737
updateSession(sessionId: string, ip: string, userAgent: string) : Promise<void>,
3838
invalidateSession(sessionId: string): Promise<void>,
3939
invalidateAllSessions(userId: string): Promise<void>

0 commit comments

Comments
 (0)