mirror of
https://github.com/strapi/strapi.git
synced 2025-11-15 09:39:15 +00:00
Fix tests
This commit is contained in:
parent
87520328bd
commit
d834bf6f48
@ -86,7 +86,7 @@ describe('API Token Auth Strategy', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Expired token throws on authorize', async () => {
|
test('Expired token throws on authorize', async () => {
|
||||||
const pastDate = Date.now() - 1;
|
const pastDate = new Date(Date.now() - 1).toISOString();
|
||||||
|
|
||||||
const getBy = jest.fn(() => {
|
const getBy = jest.fn(() => {
|
||||||
return {
|
return {
|
||||||
@ -109,9 +109,11 @@ describe('API Token Auth Strategy', () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(async () => {
|
const { authenticated, error } = await apiTokenStrategy.authenticate(ctx);
|
||||||
await apiTokenStrategy.authenticate(ctx);
|
|
||||||
}).rejects.toThrow(new UnauthorizedError('Token expired'));
|
expect(authenticated).toBe(false);
|
||||||
|
expect(error).toBeInstanceOf(UnauthorizedError);
|
||||||
|
expect(error.message).toBe('Token expired');
|
||||||
|
|
||||||
expect(getBy).toHaveBeenCalledWith({ accessKey: 'api-token_tests-hashed-access-key' });
|
expect(getBy).toHaveBeenCalledWith({ accessKey: 'api-token_tests-hashed-access-key' });
|
||||||
});
|
});
|
||||||
|
|||||||
@ -47,7 +47,7 @@ const authenticate = async (ctx) => {
|
|||||||
|
|
||||||
// token has expired
|
// token has expired
|
||||||
if (expirationDate < currentDate) {
|
if (expirationDate < currentDate) {
|
||||||
throw new UnauthorizedError('Token expired');
|
return { authenticated: false, error: new UnauthorizedError('Token expired') };
|
||||||
}
|
}
|
||||||
|
|
||||||
// update lastUsedAt
|
// update lastUsedAt
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user