mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
test: Add user type of admin to E2E tests (#7935)
## Summary Extend existing user types in the E2E database. Currently, we have only owner and member but we need also admin --------- Co-authored-by: Val <68596159+valya@users.noreply.github.com>
This commit is contained in:
parent
92bab72cff
commit
c461025f70
|
@ -12,6 +12,13 @@ export const INSTANCE_OWNER = {
|
||||||
lastName: randLastName(),
|
lastName: randLastName(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const INSTANCE_ADMIN = {
|
||||||
|
email: 'admin@n8n.io',
|
||||||
|
password: DEFAULT_USER_PASSWORD,
|
||||||
|
firstName: randFirstName(),
|
||||||
|
lastName: randLastName(),
|
||||||
|
};
|
||||||
|
|
||||||
export const INSTANCE_MEMBERS = [
|
export const INSTANCE_MEMBERS = [
|
||||||
{
|
{
|
||||||
email: 'rebecca@n8n.io',
|
email: 'rebecca@n8n.io',
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { INSTANCE_MEMBERS, INSTANCE_OWNER } from '../constants';
|
import { INSTANCE_MEMBERS, INSTANCE_OWNER, INSTANCE_ADMIN } from '../constants';
|
||||||
import { MainSidebar, SettingsSidebar, SettingsUsersPage, WorkflowPage } from '../pages';
|
import { MainSidebar, SettingsSidebar, SettingsUsersPage, WorkflowPage } from '../pages';
|
||||||
import { PersonalSettingsPage } from '../pages/settings-personal';
|
import { PersonalSettingsPage } from '../pages/settings-personal';
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ describe('User Management', { disableAutoLogin: true }, () => {
|
||||||
it('should properly render UM settings page for instance owners', () => {
|
it('should properly render UM settings page for instance owners', () => {
|
||||||
usersSettingsPage.actions.loginAndVisit(INSTANCE_OWNER.email, INSTANCE_OWNER.password, true);
|
usersSettingsPage.actions.loginAndVisit(INSTANCE_OWNER.email, INSTANCE_OWNER.password, true);
|
||||||
// All items in user list should be there
|
// All items in user list should be there
|
||||||
usersSettingsPage.getters.userListItems().should('have.length', 3);
|
usersSettingsPage.getters.userListItems().should('have.length', 4);
|
||||||
// List item for current user should have the `Owner` badge
|
// List item for current user should have the `Owner` badge
|
||||||
usersSettingsPage.getters
|
usersSettingsPage.getters
|
||||||
.userItem(INSTANCE_OWNER.email)
|
.userItem(INSTANCE_OWNER.email)
|
||||||
|
@ -55,6 +55,7 @@ describe('User Management', { disableAutoLogin: true }, () => {
|
||||||
// Other users list items should contain action pop-up list
|
// Other users list items should contain action pop-up list
|
||||||
usersSettingsPage.getters.userActionsToggle(INSTANCE_MEMBERS[0].email).should('exist');
|
usersSettingsPage.getters.userActionsToggle(INSTANCE_MEMBERS[0].email).should('exist');
|
||||||
usersSettingsPage.getters.userActionsToggle(INSTANCE_MEMBERS[1].email).should('exist');
|
usersSettingsPage.getters.userActionsToggle(INSTANCE_MEMBERS[1].email).should('exist');
|
||||||
|
usersSettingsPage.getters.userActionsToggle(INSTANCE_ADMIN.email).should('exist');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to change theme', () => {
|
it('should be able to change theme', () => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { MainSidebar } from './../pages/sidebar/main-sidebar';
|
import { MainSidebar } from './../pages/sidebar/main-sidebar';
|
||||||
import { INSTANCE_OWNER, BACKEND_BASE_URL } from '../constants';
|
import { INSTANCE_OWNER, INSTANCE_ADMIN, BACKEND_BASE_URL } from '../constants';
|
||||||
import { SigninPage } from '../pages';
|
import { SigninPage } from '../pages';
|
||||||
import { PersonalSettingsPage } from '../pages/settings-personal';
|
import { PersonalSettingsPage } from '../pages/settings-personal';
|
||||||
import { MfaLoginPage } from '../pages/mfa-login';
|
import { MfaLoginPage } from '../pages/mfa-login';
|
||||||
|
@ -19,6 +19,16 @@ const user = {
|
||||||
mfaRecoveryCodes: [RECOVERY_CODE],
|
mfaRecoveryCodes: [RECOVERY_CODE],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const admin = {
|
||||||
|
email: INSTANCE_ADMIN.email,
|
||||||
|
password: INSTANCE_ADMIN.password,
|
||||||
|
firstName: 'Admin',
|
||||||
|
lastName: 'B',
|
||||||
|
mfaEnabled: false,
|
||||||
|
mfaSecret: MFA_SECRET,
|
||||||
|
mfaRecoveryCodes: [RECOVERY_CODE],
|
||||||
|
};
|
||||||
|
|
||||||
const mfaLoginPage = new MfaLoginPage();
|
const mfaLoginPage = new MfaLoginPage();
|
||||||
const signinPage = new SigninPage();
|
const signinPage = new SigninPage();
|
||||||
const personalSettingsPage = new PersonalSettingsPage();
|
const personalSettingsPage = new PersonalSettingsPage();
|
||||||
|
@ -30,6 +40,7 @@ describe('Two-factor authentication', () => {
|
||||||
cy.request('POST', `${BACKEND_BASE_URL}/rest/e2e/reset`, {
|
cy.request('POST', `${BACKEND_BASE_URL}/rest/e2e/reset`, {
|
||||||
owner: user,
|
owner: user,
|
||||||
members: [],
|
members: [],
|
||||||
|
admin,
|
||||||
});
|
});
|
||||||
cy.on('uncaught:exception', (err, runnable) => {
|
cy.on('uncaught:exception', (err, runnable) => {
|
||||||
expect(err.message).to.include('Not logged in');
|
expect(err.message).to.include('Not logged in');
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import { BACKEND_BASE_URL, INSTANCE_MEMBERS, INSTANCE_OWNER } from '../constants';
|
import { BACKEND_BASE_URL, INSTANCE_ADMIN, INSTANCE_MEMBERS, INSTANCE_OWNER } from '../constants';
|
||||||
import './commands';
|
import './commands';
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
cy.request('POST', `${BACKEND_BASE_URL}/rest/e2e/reset`, {
|
cy.request('POST', `${BACKEND_BASE_URL}/rest/e2e/reset`, {
|
||||||
owner: INSTANCE_OWNER,
|
owner: INSTANCE_OWNER,
|
||||||
members: INSTANCE_MEMBERS,
|
members: INSTANCE_MEMBERS,
|
||||||
|
admin: INSTANCE_ADMIN,
|
||||||
});
|
});
|
||||||
|
|
||||||
Cypress.on('uncaught:exception', (err) => {
|
Cypress.on('uncaught:exception', (err) => {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import type { UserSetupPayload } from '@/requests';
|
||||||
import type { BooleanLicenseFeature, IPushDataType } from '@/Interfaces';
|
import type { BooleanLicenseFeature, IPushDataType } from '@/Interfaces';
|
||||||
import { MfaService } from '@/Mfa/mfa.service';
|
import { MfaService } from '@/Mfa/mfa.service';
|
||||||
import { Push } from '@/push';
|
import { Push } from '@/push';
|
||||||
|
import { CacheService } from '@/services/cache.service';
|
||||||
|
|
||||||
if (!inE2ETests) {
|
if (!inE2ETests) {
|
||||||
console.error('E2E endpoints only allowed during E2E tests');
|
console.error('E2E endpoints only allowed during E2E tests');
|
||||||
|
@ -49,6 +50,7 @@ type ResetRequest = Request<
|
||||||
{
|
{
|
||||||
owner: UserSetupPayload;
|
owner: UserSetupPayload;
|
||||||
members: UserSetupPayload[];
|
members: UserSetupPayload[];
|
||||||
|
admin: UserSetupPayload;
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
@ -92,6 +94,7 @@ export class E2EController {
|
||||||
private userRepo: UserRepository,
|
private userRepo: UserRepository,
|
||||||
private workflowRunner: ActiveWorkflowRunner,
|
private workflowRunner: ActiveWorkflowRunner,
|
||||||
private mfaService: MfaService,
|
private mfaService: MfaService,
|
||||||
|
private cacheService: CacheService,
|
||||||
) {
|
) {
|
||||||
license.isFeatureEnabled = (feature: BooleanLicenseFeature) =>
|
license.isFeatureEnabled = (feature: BooleanLicenseFeature) =>
|
||||||
this.enabledFeatures[feature] ?? false;
|
this.enabledFeatures[feature] ?? false;
|
||||||
|
@ -103,7 +106,8 @@ export class E2EController {
|
||||||
await this.resetLogStreaming();
|
await this.resetLogStreaming();
|
||||||
await this.removeActiveWorkflows();
|
await this.removeActiveWorkflows();
|
||||||
await this.truncateAll();
|
await this.truncateAll();
|
||||||
await this.setupUserManagement(req.body.owner, req.body.members);
|
await this.resetCache();
|
||||||
|
await this.setupUserManagement(req.body.owner, req.body.members, req.body.admin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('/push')
|
@Post('/push')
|
||||||
|
@ -160,19 +164,25 @@ export class E2EController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async setupUserManagement(owner: UserSetupPayload, members: UserSetupPayload[]) {
|
private async setupUserManagement(
|
||||||
|
owner: UserSetupPayload,
|
||||||
|
members: UserSetupPayload[],
|
||||||
|
admin: UserSetupPayload,
|
||||||
|
) {
|
||||||
const roles: Array<[Role['name'], Role['scope']]> = [
|
const roles: Array<[Role['name'], Role['scope']]> = [
|
||||||
['owner', 'global'],
|
['owner', 'global'],
|
||||||
['member', 'global'],
|
['member', 'global'],
|
||||||
|
['admin', 'global'],
|
||||||
['owner', 'workflow'],
|
['owner', 'workflow'],
|
||||||
['owner', 'credential'],
|
['owner', 'credential'],
|
||||||
['user', 'credential'],
|
['user', 'credential'],
|
||||||
['editor', 'workflow'],
|
['editor', 'workflow'],
|
||||||
];
|
];
|
||||||
|
|
||||||
const [{ id: globalOwnerRoleId }, { id: globalMemberRoleId }] = await this.roleRepo.save(
|
const [{ id: globalOwnerRoleId }, { id: globalMemberRoleId }, { id: globalAdminRoleId }] =
|
||||||
roles.map(([name, scope], index) => ({ name, scope, id: (index + 1).toString() })),
|
await this.roleRepo.save(
|
||||||
);
|
roles.map(([name, scope], index) => ({ name, scope, id: (index + 1).toString() })),
|
||||||
|
);
|
||||||
|
|
||||||
const instanceOwner = {
|
const instanceOwner = {
|
||||||
id: uuid(),
|
id: uuid(),
|
||||||
|
@ -188,9 +198,16 @@ export class E2EController {
|
||||||
instanceOwner.mfaRecoveryCodes = encryptedRecoveryCodes;
|
instanceOwner.mfaRecoveryCodes = encryptedRecoveryCodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const adminUser = {
|
||||||
|
id: uuid(),
|
||||||
|
...admin,
|
||||||
|
password: await hashPassword(admin.password),
|
||||||
|
globalRoleId: globalAdminRoleId,
|
||||||
|
};
|
||||||
|
|
||||||
const users = [];
|
const users = [];
|
||||||
|
|
||||||
users.push(instanceOwner);
|
users.push(instanceOwner, adminUser);
|
||||||
|
|
||||||
for (const { password, ...payload } of members) {
|
for (const { password, ...payload } of members) {
|
||||||
users.push(
|
users.push(
|
||||||
|
@ -212,4 +229,8 @@ export class E2EController {
|
||||||
|
|
||||||
config.set('userManagement.isInstanceOwnerSetUp', true);
|
config.set('userManagement.isInstanceOwnerSetUp', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async resetCache() {
|
||||||
|
await this.cacheService.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue