mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 00:24:07 -08:00
89f44021b9
* use jwt to reset password * increase expiration time to 1d * drop user id query string * refactor * use service instead of package in tests * sqlite migration * postgres migration * mysql migration * remove unused properties * remove userId from FE * fix test for users.api * move migration to the common folder * move type assertion to the jwt.service * Add jwt secret as a readonly property * use signData instead of sign in user.controller * remove base class * remove base class * add tests
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import config from '@/config';
|
|
import { JwtService } from '@/services/jwt.service';
|
|
import { randomString } from '../../integration/shared/random';
|
|
import * as jwt from 'jsonwebtoken';
|
|
|
|
describe('JwtService', () => {
|
|
config.set('userManagement.jwtSecret', randomString(5, 10));
|
|
|
|
const jwtService = new JwtService();
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
test('Should sign input with user management secret', async () => {
|
|
const userId = 1;
|
|
|
|
const token = jwtService.signData({ sub: userId });
|
|
expect(typeof token).toBe('string');
|
|
|
|
const secret = config.get('userManagement.jwtSecret');
|
|
|
|
const decodedToken = jwt.verify(token, secret);
|
|
|
|
expect(decodedToken).toHaveProperty('sub');
|
|
expect(decodedToken).toHaveProperty('iat');
|
|
expect(decodedToken?.sub).toBe(userId);
|
|
});
|
|
|
|
test('Should verify token with user management secret', async () => {
|
|
const userId = 1;
|
|
|
|
const secret = config.get('userManagement.jwtSecret');
|
|
|
|
const token = jwt.sign({ sub: userId }, secret);
|
|
|
|
const decodedToken = jwt.verify(token, secret);
|
|
|
|
expect(decodedToken).toHaveProperty('sub');
|
|
expect(decodedToken?.sub).toBe(userId);
|
|
});
|
|
});
|