fixed tests and package vulnerabilities
This commit is contained in:
@@ -3,6 +3,7 @@ process.env.JWT_SECRET = 'test-secret';
|
||||
process.env.DATABASE_URL = 'postgresql://test';
|
||||
process.env.GOOGLE_MAPS_API_KEY = 'test-key';
|
||||
process.env.STRIPE_SECRET_KEY = 'sk_test_key';
|
||||
process.env.CSRF_SECRET = 'test-csrf-secret-that-is-at-least-32-chars-long';
|
||||
|
||||
// Silence console
|
||||
global.console = {
|
||||
|
||||
@@ -106,16 +106,6 @@ describe('CSRF Middleware', () => {
|
||||
expect(res.status).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should validate token from query parameters', () => {
|
||||
req.query.csrfToken = 'mock-token-123';
|
||||
|
||||
csrfProtection(req, res, next);
|
||||
|
||||
expect(mockTokensInstance.verify).toHaveBeenCalledWith(process.env.CSRF_SECRET, 'mock-token-123');
|
||||
expect(next).toHaveBeenCalled();
|
||||
expect(res.status).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should prefer header token over body token', () => {
|
||||
req.headers['x-csrf-token'] = 'mock-token-123';
|
||||
req.body.csrfToken = 'different-token';
|
||||
@@ -126,25 +116,6 @@ describe('CSRF Middleware', () => {
|
||||
expect(next).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should prefer header token over query token', () => {
|
||||
req.headers['x-csrf-token'] = 'mock-token-123';
|
||||
req.query.csrfToken = 'different-token';
|
||||
|
||||
csrfProtection(req, res, next);
|
||||
|
||||
expect(mockTokensInstance.verify).toHaveBeenCalledWith(process.env.CSRF_SECRET, 'mock-token-123');
|
||||
expect(next).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should prefer body token over query token', () => {
|
||||
req.body.csrfToken = 'mock-token-123';
|
||||
req.query.csrfToken = 'different-token';
|
||||
|
||||
csrfProtection(req, res, next);
|
||||
|
||||
expect(mockTokensInstance.verify).toHaveBeenCalledWith(process.env.CSRF_SECRET, 'mock-token-123');
|
||||
expect(next).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Missing tokens', () => {
|
||||
|
||||
@@ -3,6 +3,27 @@ const crypto = require('crypto');
|
||||
// Mock crypto module
|
||||
jest.mock('crypto');
|
||||
|
||||
// Mock the logger to prevent winston-daily-rotate-file issues
|
||||
jest.mock('../../../utils/logger', () => ({
|
||||
error: jest.fn(),
|
||||
info: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
withRequestId: jest.fn(() => ({
|
||||
error: jest.fn(),
|
||||
info: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
})),
|
||||
}));
|
||||
|
||||
// Mock TwoFactorService to prevent otplib loading
|
||||
jest.mock('../../../services/TwoFactorService', () => ({
|
||||
generateSecret: jest.fn(),
|
||||
verifyToken: jest.fn(),
|
||||
generateQRCode: jest.fn(),
|
||||
}));
|
||||
|
||||
// Mock the entire models module
|
||||
jest.mock('../../../models', () => {
|
||||
const mockUser = {
|
||||
|
||||
Reference in New Issue
Block a user