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
@@ -2,7 +2,6 @@ import validator from 'validator';
|
||||
import { Not } from 'typeorm';
|
||||
import type { SuperAgentTest } from 'supertest';
|
||||
|
||||
import config from '@/config';
|
||||
import * as Db from '@/Db';
|
||||
import { CredentialsEntity } from '@db/entities/CredentialsEntity';
|
||||
import type { Role } from '@db/entities/Role';
|
||||
@@ -10,7 +9,6 @@ import type { User } from '@db/entities/User';
|
||||
import { WorkflowEntity } from '@db/entities/WorkflowEntity';
|
||||
import { compareHash } from '@/UserManagement/UserManagementHelper';
|
||||
import { UserManagementMailer } from '@/UserManagement/email/UserManagementMailer';
|
||||
import { NodeMailer } from '@/UserManagement/email/NodeMailer';
|
||||
|
||||
import { SUCCESS_RESPONSE_BODY } from './shared/constants';
|
||||
import {
|
||||
@@ -23,14 +21,14 @@ import {
|
||||
import * as testDb from './shared/testDb';
|
||||
import * as utils from './shared/utils/';
|
||||
|
||||
jest.mock('@/UserManagement/email/NodeMailer');
|
||||
|
||||
let globalMemberRole: Role;
|
||||
let workflowOwnerRole: Role;
|
||||
let credentialOwnerRole: Role;
|
||||
let owner: User;
|
||||
let authOwnerAgent: SuperAgentTest;
|
||||
|
||||
const mailer = utils.mockInstance(UserManagementMailer, { isEmailSetUp: true });
|
||||
|
||||
const testServer = utils.setupTestServer({ endpointGroups: ['users'] });
|
||||
|
||||
beforeAll(async () => {
|
||||
@@ -54,10 +52,7 @@ beforeEach(async () => {
|
||||
await testDb.truncate(['SharedCredentials', 'SharedWorkflow', 'Workflow', 'Credentials']);
|
||||
await Db.collections.User.delete({ id: Not(owner.id) });
|
||||
|
||||
jest.mock('@/config');
|
||||
|
||||
config.set('userManagement.emails.mode', 'smtp');
|
||||
config.set('userManagement.emails.smtp.host', '');
|
||||
mailer.invite.mockResolvedValue({ emailSent: true });
|
||||
});
|
||||
|
||||
describe('DELETE /users/:id', () => {
|
||||
@@ -313,11 +308,8 @@ describe('POST /users/:id', () => {
|
||||
});
|
||||
|
||||
describe('POST /users', () => {
|
||||
beforeEach(() => {
|
||||
config.set('userManagement.emails.mode', 'smtp');
|
||||
});
|
||||
|
||||
test('should succeed if emailing is not set up', async () => {
|
||||
mailer.invite.mockResolvedValueOnce({ emailSent: false });
|
||||
const response = await authOwnerAgent.post('/users').send([{ email: randomEmail() }]);
|
||||
|
||||
expect(response.statusCode).toBe(200);
|
||||
@@ -342,11 +334,12 @@ describe('POST /users', () => {
|
||||
expect(response.statusCode).toBe(200);
|
||||
|
||||
for (const {
|
||||
user: { id, email: receivedEmail },
|
||||
user: { id, email: receivedEmail, inviteAcceptUrl },
|
||||
error,
|
||||
} of response.body.data) {
|
||||
expect(validator.isUUID(id)).toBe(true);
|
||||
expect(id).not.toBe(member.id);
|
||||
expect(inviteAcceptUrl).toBeUndefined();
|
||||
|
||||
const lowerCasedEmail = receivedEmail.toLowerCase();
|
||||
expect(receivedEmail).toBe(lowerCasedEmail);
|
||||
@@ -401,14 +394,6 @@ describe('POST /users', () => {
|
||||
});
|
||||
|
||||
describe('POST /users/:id/reinvite', () => {
|
||||
beforeEach(() => {
|
||||
config.set('userManagement.emails.mode', 'smtp');
|
||||
// those configs are needed to make sure the reinvite email is sent,because of this check isEmailSetUp()
|
||||
config.set('userManagement.emails.smtp.host', 'host');
|
||||
config.set('userManagement.emails.smtp.auth.user', 'user');
|
||||
config.set('userManagement.emails.smtp.auth.pass', 'pass');
|
||||
});
|
||||
|
||||
test('should send reinvite, but fail if user already accepted invite', async () => {
|
||||
const email = randomEmail();
|
||||
const payload = [{ email }];
|
||||
@@ -428,38 +413,3 @@ describe('POST /users/:id/reinvite', () => {
|
||||
expect(reinviteMemberResponse.statusCode).toBe(400);
|
||||
});
|
||||
});
|
||||
|
||||
describe('UserManagementMailer expect NodeMailer.verifyConnection', () => {
|
||||
let mockInit: jest.SpyInstance<Promise<void>, []>;
|
||||
let mockVerifyConnection: jest.SpyInstance<Promise<void>, []>;
|
||||
|
||||
beforeAll(() => {
|
||||
mockVerifyConnection = jest
|
||||
.spyOn(NodeMailer.prototype, 'verifyConnection')
|
||||
.mockImplementation(async () => {});
|
||||
mockInit = jest.spyOn(NodeMailer.prototype, 'init').mockImplementation(async () => {});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mockVerifyConnection.mockRestore();
|
||||
mockInit.mockRestore();
|
||||
});
|
||||
|
||||
test('not be called when SMTP not set up', async () => {
|
||||
const userManagementMailer = new UserManagementMailer();
|
||||
// NodeMailer.verifyConnection gets called only explicitly
|
||||
await expect(async () => userManagementMailer.verifyConnection()).rejects.toThrow();
|
||||
|
||||
expect(NodeMailer.prototype.verifyConnection).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test('to be called when SMTP set up', async () => {
|
||||
// host needs to be set, otherwise smtp is skipped
|
||||
config.set('userManagement.emails.smtp.host', 'host');
|
||||
config.set('userManagement.emails.mode', 'smtp');
|
||||
|
||||
const userManagementMailer = new UserManagementMailer();
|
||||
// NodeMailer.verifyConnection gets called only explicitly
|
||||
expect(async () => userManagementMailer.verifyConnection()).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user