1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-04 00:18:01 +01:00

fix: PAT not taking into account expires_at (#2167)

This commit is contained in:
Nuno Góis 2022-10-10 15:38:47 +01:00 committed by GitHub
parent 0651c83bd1
commit 2fa86ef97f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -215,6 +215,7 @@ class UserStore implements IUserStore {
`${TABLE}.id`, `${TABLE}.id`,
) )
.where('secret', secret) .where('secret', secret)
.andWhere('expires_at', '>', 'now()')
.first(); .first();
return rowToUser(row); return rowToUser(row);
} }

View File

@ -2,9 +2,11 @@ import { IUnleashTest, setupAppWithAuth } from '../../../helpers/test-helper';
import dbInit, { ITestDb } from '../../../helpers/database-init'; import dbInit, { ITestDb } from '../../../helpers/database-init';
import getLogger from '../../../../fixtures/no-logger'; import getLogger from '../../../../fixtures/no-logger';
import { IPat } from '../../../../../lib/types/models/pat'; import { IPat } from '../../../../../lib/types/models/pat';
import { IPatStore } from '../../../../../lib/types/stores/pat-store';
let app: IUnleashTest; let app: IUnleashTest;
let db: ITestDb; let db: ITestDb;
let patStore: IPatStore;
let tomorrow = new Date(); let tomorrow = new Date();
let firstSecret; let firstSecret;
@ -13,6 +15,7 @@ tomorrow.setDate(tomorrow.getDate() + 1);
beforeAll(async () => { beforeAll(async () => {
db = await dbInit('user_pat', getLogger); db = await dbInit('user_pat', getLogger);
patStore = db.stores.patStore;
app = await setupAppWithAuth(db.stores, { app = await setupAppWithAuth(db.stores, {
experimental: { flags: { personalAccessTokens: true } }, experimental: { flags: { personalAccessTokens: true } },
}); });
@ -188,3 +191,18 @@ test('should not get user with invalid token', async () => {
.set('Authorization', 'randomtoken') .set('Authorization', 'randomtoken')
.expect(401); .expect(401);
}); });
test('should not get user with expired token', async () => {
const token = await patStore.create({
id: 1,
secret: 'user:expired-token',
description: 'expired-token',
userId: 1,
expiresAt: new Date('2020-01-01'),
});
await app.request
.get('/api/admin/user')
.set('Authorization', token.secret)
.expect(401);
});