mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(core): Do not return inviteAcceptUrl in response if email was sent (#7465)
This commit is contained in:
committed by
GitHub
parent
ab6a9bbac2
commit
55c6a1b0d3
@@ -1,11 +1,17 @@
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { compare } from 'bcryptjs';
|
||||
import { Container } from 'typedi';
|
||||
import { License } from '@/License';
|
||||
|
||||
import * as Db from '@/Db';
|
||||
import config from '@/config';
|
||||
import type { Role } from '@db/entities/Role';
|
||||
import type { User } from '@db/entities/User';
|
||||
import { setCurrentAuthenticationMethod } from '@/sso/ssoHelpers';
|
||||
import { ExternalHooks } from '@/ExternalHooks';
|
||||
import { JwtService } from '@/services/jwt.service';
|
||||
import { UserManagementMailer } from '@/UserManagement/email';
|
||||
|
||||
import * as utils from './shared/utils/';
|
||||
import {
|
||||
randomEmail,
|
||||
@@ -15,12 +21,7 @@ import {
|
||||
randomValidPassword,
|
||||
} from './shared/random';
|
||||
import * as testDb from './shared/testDb';
|
||||
import { setCurrentAuthenticationMethod } from '@/sso/ssoHelpers';
|
||||
import { ExternalHooks } from '@/ExternalHooks';
|
||||
import { JwtService } from '@/services/jwt.service';
|
||||
import { Container } from 'typedi';
|
||||
|
||||
jest.mock('@/UserManagement/email/NodeMailer');
|
||||
config.set('userManagement.jwtSecret', randomString(5, 10));
|
||||
|
||||
let globalOwnerRole: Role;
|
||||
@@ -29,6 +30,7 @@ let owner: User;
|
||||
let member: User;
|
||||
|
||||
const externalHooks = utils.mockInstance(ExternalHooks);
|
||||
const mailer = utils.mockInstance(UserManagementMailer, { isEmailSetUp: true });
|
||||
const testServer = utils.setupTestServer({ endpointGroups: ['passwordReset'] });
|
||||
const jwtService = Container.get(JwtService);
|
||||
|
||||
@@ -43,6 +45,7 @@ beforeEach(async () => {
|
||||
owner = await testDb.createUser({ globalRole: globalOwnerRole });
|
||||
member = await testDb.createUser({ globalRole: globalMemberRole });
|
||||
externalHooks.run.mockReset();
|
||||
jest.replaceProperty(mailer, 'isEmailSetUp', true);
|
||||
});
|
||||
|
||||
describe('POST /forgot-password', () => {
|
||||
@@ -52,8 +55,6 @@ describe('POST /forgot-password', () => {
|
||||
globalRole: globalMemberRole,
|
||||
});
|
||||
|
||||
config.set('userManagement.emails.mode', 'smtp');
|
||||
|
||||
await Promise.all(
|
||||
[{ email: owner.email }, { email: member.email.toUpperCase() }].map(async (payload) => {
|
||||
const response = await testServer.authlessAgent.post('/forgot-password').send(payload);
|
||||
@@ -65,7 +66,7 @@ describe('POST /forgot-password', () => {
|
||||
});
|
||||
|
||||
test('should fail if emailing is not set up', async () => {
|
||||
config.set('userManagement.emails.mode', '');
|
||||
jest.replaceProperty(mailer, 'isEmailSetUp', false);
|
||||
|
||||
await testServer.authlessAgent
|
||||
.post('/forgot-password')
|
||||
@@ -75,7 +76,6 @@ describe('POST /forgot-password', () => {
|
||||
|
||||
test('should fail if SAML is authentication method', async () => {
|
||||
await setCurrentAuthenticationMethod('saml');
|
||||
config.set('userManagement.emails.mode', 'smtp');
|
||||
const member = await testDb.createUser({
|
||||
email: 'test@test.com',
|
||||
globalRole: globalMemberRole,
|
||||
@@ -91,7 +91,6 @@ describe('POST /forgot-password', () => {
|
||||
|
||||
test('should succeed if SAML is authentication method and requestor is owner', async () => {
|
||||
await setCurrentAuthenticationMethod('saml');
|
||||
config.set('userManagement.emails.mode', 'smtp');
|
||||
|
||||
const response = await testServer.authlessAgent
|
||||
.post('/forgot-password')
|
||||
@@ -104,8 +103,6 @@ describe('POST /forgot-password', () => {
|
||||
});
|
||||
|
||||
test('should fail with invalid inputs', async () => {
|
||||
config.set('userManagement.emails.mode', 'smtp');
|
||||
|
||||
const invalidPayloads = [
|
||||
randomEmail(),
|
||||
[randomEmail()],
|
||||
@@ -121,8 +118,6 @@ describe('POST /forgot-password', () => {
|
||||
});
|
||||
|
||||
test('should fail if user is not found', async () => {
|
||||
config.set('userManagement.emails.mode', 'smtp');
|
||||
|
||||
const response = await testServer.authlessAgent
|
||||
.post('/forgot-password')
|
||||
.send({ email: randomEmail() });
|
||||
@@ -132,10 +127,6 @@ describe('POST /forgot-password', () => {
|
||||
});
|
||||
|
||||
describe('GET /resolve-password-token', () => {
|
||||
beforeEach(() => {
|
||||
config.set('userManagement.emails.mode', 'smtp');
|
||||
});
|
||||
|
||||
test('should succeed with valid inputs', async () => {
|
||||
const resetPasswordToken = jwtService.signData({ sub: owner.id });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user