feat(core): Add MFA (#4767)

https://linear.app/n8n/issue/ADO-947/sync-branch-with-master-and-fix-fe-e2e-tets

---------

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Ricardo Espinoza
2023-08-23 22:59:16 -04:00
committed by GitHub
parent a01c3fbc19
commit 2b7ba6fdf1
61 changed files with 2301 additions and 105 deletions

View File

@@ -23,6 +23,7 @@ import { registerController } from '@/decorators';
import {
AuthController,
LdapController,
MFAController,
MeController,
NodesController,
OwnerController,
@@ -49,7 +50,9 @@ import * as testDb from '../../shared/testDb';
import { AUTHLESS_ENDPOINTS, PUBLIC_API_REST_PATH_SEGMENT, REST_PATH_SEGMENT } from '../constants';
import type { EndpointGroup, SetupProps, TestServer } from '../types';
import { mockInstance } from './mocking';
import { JwtService } from '@/services/jwt.service';
import { MfaService } from '@/Mfa/mfa.service';
import { TOTPService } from '@/Mfa/totp.service';
import { UserSettings } from 'n8n-core';
import { MetricsService } from '@/services/metrics.service';
/**
@@ -179,11 +182,12 @@ export const setupTestServer = ({
}
if (functionEndpoints.length) {
const encryptionKey = await UserSettings.getEncryptionKey();
const repositories = Db.collections;
const externalHooks = Container.get(ExternalHooks);
const internalHooks = Container.get(InternalHooks);
const mailer = Container.get(UserManagementMailer);
const jwtService = Container.get(JwtService);
const repositories = Db.collections;
const mfaService = new MfaService(repositories.User, new TOTPService(), encryptionKey);
for (const group of functionEndpoints) {
switch (group) {
@@ -197,14 +201,11 @@ export const setupTestServer = ({
registerController(
app,
config,
new AuthController({
config,
logger,
internalHooks,
repositories,
}),
new AuthController({ config, logger, internalHooks, repositories, mfaService }),
);
break;
case 'mfa':
registerController(app, config, new MFAController(mfaService));
case 'ldap':
Container.get(License).isLdapEnabled = () => true;
await handleLdapInit();
@@ -250,6 +251,7 @@ export const setupTestServer = ({
externalHooks,
internalHooks,
mailer,
mfaService,
}),
);
break;