-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://linear.app/n8n/issue/ADO-947/sync-branch-with-master-and-fix-fe-e2e-tets --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
- Loading branch information
1 parent
a01c3fb
commit 2b7ba6f
Showing
61 changed files
with
2,301 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { MainSidebar } from './../pages/sidebar/main-sidebar'; | ||
import { INSTANCE_OWNER, BACKEND_BASE_URL } from '../constants'; | ||
import { SigninPage } from '../pages'; | ||
import { PersonalSettingsPage } from '../pages/settings-personal'; | ||
import { MfaLoginPage } from '../pages/mfa-login'; | ||
|
||
const MFA_SECRET = 'KVKFKRCPNZQUYMLXOVYDSQKJKZDTSRLD'; | ||
|
||
const RECOVERY_CODE = 'd04ea17f-e8b2-4afa-a9aa-57a2c735b30e'; | ||
|
||
const user = { | ||
email: INSTANCE_OWNER.email, | ||
password: INSTANCE_OWNER.password, | ||
firstName: 'User', | ||
lastName: 'A', | ||
mfaEnabled: false, | ||
mfaSecret: MFA_SECRET, | ||
mfaRecoveryCodes: [RECOVERY_CODE], | ||
}; | ||
|
||
const mfaLoginPage = new MfaLoginPage(); | ||
const signinPage = new SigninPage(); | ||
const personalSettingsPage = new PersonalSettingsPage(); | ||
const mainSidebar = new MainSidebar(); | ||
|
||
describe('Two-factor authentication', () => { | ||
beforeEach(() => { | ||
Cypress.session.clearAllSavedSessions(); | ||
cy.request('POST', `${BACKEND_BASE_URL}/rest/e2e/reset`, { | ||
owner: user, | ||
members: [], | ||
}); | ||
cy.on('uncaught:exception', (err, runnable) => { | ||
expect(err.message).to.include('Not logged in'); | ||
return false; | ||
}); | ||
}); | ||
|
||
it('Should be able to login with MFA token', () => { | ||
const { email, password } = user; | ||
signinPage.actions.loginWithEmailAndPassword(email, password); | ||
personalSettingsPage.actions.enableMfa(); | ||
mainSidebar.actions.signout(); | ||
cy.generateToken(user.mfaSecret).then((token) => { | ||
mfaLoginPage.actions.loginWithMfaToken(email, password, token); | ||
mainSidebar.actions.signout(); | ||
}); | ||
}); | ||
|
||
it('Should be able to login with recovery code', () => { | ||
const { email, password } = user; | ||
signinPage.actions.loginWithEmailAndPassword(email, password); | ||
personalSettingsPage.actions.enableMfa(); | ||
mainSidebar.actions.signout(); | ||
mfaLoginPage.actions.loginWithRecoveryCode(email, password, user.mfaRecoveryCodes[0]); | ||
mainSidebar.actions.signout(); | ||
}); | ||
|
||
it('Should be able to disable MFA in account', () => { | ||
const { email, password } = user; | ||
signinPage.actions.loginWithEmailAndPassword(email, password); | ||
personalSettingsPage.actions.enableMfa(); | ||
mainSidebar.actions.signout(); | ||
cy.generateToken(user.mfaSecret).then((token) => { | ||
mfaLoginPage.actions.loginWithMfaToken(email, password, token); | ||
personalSettingsPage.actions.disableMfa(); | ||
mainSidebar.actions.signout(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { N8N_AUTH_COOKIE } from '../constants'; | ||
import { BasePage } from './base'; | ||
import { SigninPage } from './signin'; | ||
import { WorkflowsPage } from './workflows'; | ||
|
||
export class MfaLoginPage extends BasePage { | ||
url = '/mfa'; | ||
getters = { | ||
form: () => cy.getByTestId('mfa-login-form'), | ||
token: () => cy.getByTestId('token'), | ||
recoveryCode: () => cy.getByTestId('recoveryCode'), | ||
enterRecoveryCodeButton: () => cy.getByTestId('mfa-enter-recovery-code-button'), | ||
}; | ||
|
||
actions = { | ||
loginWithMfaToken: (email: string, password: string, mfaToken: string) => { | ||
const signinPage = new SigninPage(); | ||
const workflowsPage = new WorkflowsPage(); | ||
|
||
cy.session( | ||
[mfaToken], | ||
() => { | ||
cy.visit(signinPage.url); | ||
|
||
signinPage.getters.form().within(() => { | ||
signinPage.getters.email().type(email); | ||
signinPage.getters.password().type(password); | ||
signinPage.getters.submit().click(); | ||
}); | ||
|
||
this.getters.form().within(() => { | ||
this.getters.token().type(mfaToken); | ||
}); | ||
|
||
// we should be redirected to /workflows | ||
cy.url().should('include', workflowsPage.url); | ||
}, | ||
{ | ||
validate() { | ||
cy.getCookie(N8N_AUTH_COOKIE).should('exist'); | ||
}, | ||
}, | ||
); | ||
}, | ||
loginWithRecoveryCode: (email: string, password: string, recoveryCode: string) => { | ||
const signinPage = new SigninPage(); | ||
const workflowsPage = new WorkflowsPage(); | ||
|
||
cy.session( | ||
[recoveryCode], | ||
() => { | ||
cy.visit(signinPage.url); | ||
|
||
signinPage.getters.form().within(() => { | ||
signinPage.getters.email().type(email); | ||
signinPage.getters.password().type(password); | ||
signinPage.getters.submit().click(); | ||
}); | ||
|
||
this.getters.enterRecoveryCodeButton().click(); | ||
|
||
this.getters.form().within(() => { | ||
this.getters.recoveryCode().type(recoveryCode); | ||
}); | ||
|
||
// we should be redirected to /workflows | ||
cy.url().should('include', workflowsPage.url); | ||
}, | ||
{ | ||
validate() { | ||
cy.getCookie(N8N_AUTH_COOKIE).should('exist'); | ||
}, | ||
}, | ||
); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { BasePage } from './../base'; | ||
|
||
export class MfaSetupModal extends BasePage { | ||
getters = { | ||
modalContainer: () => cy.getByTestId('changePassword-modal').last(), | ||
tokenInput: () => cy.getByTestId('mfa-token-input'), | ||
copySecretToClipboardButton: () => cy.getByTestId('mfa-secret-button'), | ||
downloadRecoveryCodesButton: () => cy.getByTestId('mfa-recovery-codes-button'), | ||
saveButton: () => cy.getByTestId('mfa-save-button'), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { N8N_AUTH_COOKIE } from '../constants'; | ||
import { BasePage } from './base'; | ||
import { WorkflowsPage } from './workflows'; | ||
|
||
export class SigninPage extends BasePage { | ||
url = '/signin'; | ||
getters = { | ||
form: () => cy.getByTestId('auth-form'), | ||
email: () => cy.getByTestId('email'), | ||
password: () => cy.getByTestId('password'), | ||
submit: () => cy.get('button'), | ||
}; | ||
|
||
actions = { | ||
loginWithEmailAndPassword: (email: string, password: string) => { | ||
const signinPage = new SigninPage(); | ||
const workflowsPage = new WorkflowsPage(); | ||
|
||
cy.session( | ||
[email, password], | ||
() => { | ||
cy.visit(signinPage.url); | ||
|
||
this.getters.form().within(() => { | ||
this.getters.email().type(email); | ||
this.getters.password().type(password); | ||
this.getters.submit().click(); | ||
}); | ||
|
||
// we should be redirected to /workflows | ||
cy.url().should('include', workflowsPage.url); | ||
}, | ||
{ | ||
validate() { | ||
cy.getCookie(N8N_AUTH_COOKIE).should('exist'); | ||
}, | ||
}, | ||
); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const MFA_FEATURE_ENABLED = 'mfa.enabled'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import config from '@/config'; | ||
import * as Db from '@/Db'; | ||
import { MFA_FEATURE_ENABLED } from './constants'; | ||
|
||
export const isMfaFeatureEnabled = () => config.get(MFA_FEATURE_ENABLED); | ||
|
||
const isMfaFeatureDisabled = () => !isMfaFeatureEnabled(); | ||
|
||
const getUsersWithMfaEnabled = async () => | ||
Db.collections.User.count({ where: { mfaEnabled: true } }); | ||
|
||
export const handleMfaDisable = async () => { | ||
if (isMfaFeatureDisabled()) { | ||
// check for users with MFA enabled, and if there are | ||
// users, then keep the feature enabled | ||
const users = await getUsersWithMfaEnabled(); | ||
if (users) { | ||
config.set(MFA_FEATURE_ENABLED, true); | ||
} | ||
} | ||
}; |
Oops, something went wrong.