refactor(userInfo): minor updates

Signed-off-by: Phil Kuang <pkuang@factset.com>
This commit is contained in:
Phil Kuang
2024-06-16 10:52:30 -04:00
parent 79b0b1f3d3
commit 4a50a87364
7 changed files with 15 additions and 5 deletions
@@ -22,6 +22,7 @@ import {
decodeProtectedHeader,
jwtVerify,
} from 'jose';
import { omit } from 'lodash';
import { MemoryKeyStore } from './MemoryKeyStore';
import { TokenFactory } from './TokenFactory';
import { UserInfoDatabaseHandler } from './UserInfoDatabaseHandler';
@@ -88,7 +89,7 @@ describe('TokenFactory', () => {
);
expect(mockUserInfoDatabaseHandler.addUserInfo).toHaveBeenCalledWith({
claims: verifyResult.payload,
claims: omit(verifyResult.payload, ['aud', 'iat', 'iss', 'uip']),
});
// Emulate the reconstruction of a limited user token
@@ -25,6 +25,7 @@ import {
GeneralSign,
KeyLike,
} from 'jose';
import { omit } from 'lodash';
import { DateTime } from 'luxon';
import { v4 as uuid } from 'uuid';
import { LoggerService } from '@backstage/backend-plugin-api';
@@ -220,7 +221,9 @@ export class TokenFactory implements TokenIssuer {
// Store the user info in the database upon successful token
// issuance so that it can be retrieved later by limited user tokens
await this.userInfoDatabaseHandler.addUserInfo({ claims });
await this.userInfoDatabaseHandler.addUserInfo({
claims: omit(claims, ['aud', 'iat', 'iss', 'uip']),
});
return token;
}
@@ -24,6 +24,8 @@ const migrationsDir = resolvePackagePath(
'migrations',
);
jest.setTimeout(60_000);
describe('UserInfoDatabaseHandler', () => {
const databases = TestDatabases.create();
@@ -41,14 +43,14 @@ describe('UserInfoDatabaseHandler', () => {
}
describe.each(databases.eachSupportedId())(
'%p',
'should support database %p',
databaseId => {
let knex: Knex;
let dbHandler: UserInfoDatabaseHandler;
beforeEach(async () => {
({ knex, dbHandler } = await createDatabaseHandler(databaseId));
}, 30000);
});
it('addUserInfo', async () => {
const userInfo = {
@@ -104,6 +106,5 @@ describe('UserInfoDatabaseHandler', () => {
expect(savedUserInfo).toEqual(userInfo);
});
},
60000,
);
});