2024-06-10 06:49:50 -07:00
|
|
|
import generateOTPToken from 'cypress-otp';
|
2024-09-18 00:19:33 -07:00
|
|
|
|
|
|
|
import { MainSidebar } from './../pages/sidebar/main-sidebar';
|
2023-12-06 05:31:06 -08:00
|
|
|
import { INSTANCE_OWNER, INSTANCE_ADMIN, BACKEND_BASE_URL } from '../constants';
|
2023-08-23 19:59:16 -07:00
|
|
|
import { SigninPage } from '../pages';
|
|
|
|
import { MfaLoginPage } from '../pages/mfa-login';
|
2024-09-18 00:19:33 -07:00
|
|
|
import { PersonalSettingsPage } from '../pages/settings-personal';
|
2023-08-23 19:59:16 -07:00
|
|
|
|
|
|
|
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],
|
|
|
|
};
|
|
|
|
|
2023-12-06 05:31:06 -08:00
|
|
|
const admin = {
|
|
|
|
email: INSTANCE_ADMIN.email,
|
|
|
|
password: INSTANCE_ADMIN.password,
|
|
|
|
firstName: 'Admin',
|
|
|
|
lastName: 'B',
|
|
|
|
mfaEnabled: false,
|
|
|
|
mfaSecret: MFA_SECRET,
|
|
|
|
mfaRecoveryCodes: [RECOVERY_CODE],
|
|
|
|
};
|
|
|
|
|
2023-08-23 19:59:16 -07:00
|
|
|
const mfaLoginPage = new MfaLoginPage();
|
|
|
|
const signinPage = new SigninPage();
|
|
|
|
const personalSettingsPage = new PersonalSettingsPage();
|
|
|
|
const mainSidebar = new MainSidebar();
|
|
|
|
|
2024-06-11 05:45:15 -07:00
|
|
|
describe('Two-factor authentication', { disableAutoLogin: true }, () => {
|
2023-08-23 19:59:16 -07:00
|
|
|
beforeEach(() => {
|
|
|
|
cy.request('POST', `${BACKEND_BASE_URL}/rest/e2e/reset`, {
|
|
|
|
owner: user,
|
|
|
|
members: [],
|
2023-12-06 05:31:06 -08:00
|
|
|
admin,
|
2023-08-23 19:59:16 -07:00
|
|
|
});
|
2024-06-10 06:49:50 -07:00
|
|
|
cy.on('uncaught:exception', (error) => {
|
|
|
|
expect(error.message).to.include('Not logged in');
|
2023-08-23 19:59:16 -07:00
|
|
|
return false;
|
|
|
|
});
|
2023-10-06 02:06:38 -07:00
|
|
|
cy.intercept('GET', '/rest/mfa/qr').as('getMfaQrCode');
|
2023-08-23 19:59:16 -07:00
|
|
|
});
|
|
|
|
|
2023-10-06 02:06:38 -07:00
|
|
|
it('Should be able to login with MFA token', () => {
|
2023-08-23 19:59:16 -07:00
|
|
|
const { email, password } = user;
|
|
|
|
signinPage.actions.loginWithEmailAndPassword(email, password);
|
|
|
|
personalSettingsPage.actions.enableMfa();
|
|
|
|
mainSidebar.actions.signout();
|
2023-09-01 04:29:31 -07:00
|
|
|
const token = generateOTPToken(user.mfaSecret);
|
2023-08-24 06:31:37 -07:00
|
|
|
mfaLoginPage.actions.loginWithMfaToken(email, password, token);
|
|
|
|
mainSidebar.actions.signout();
|
2023-08-23 19:59:16 -07:00
|
|
|
});
|
|
|
|
|
2023-10-06 02:06:38 -07:00
|
|
|
it('Should be able to login with recovery code', () => {
|
2023-08-23 19:59:16 -07:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2023-10-06 02:06:38 -07:00
|
|
|
it('Should be able to disable MFA in account', () => {
|
2023-08-23 19:59:16 -07:00
|
|
|
const { email, password } = user;
|
|
|
|
signinPage.actions.loginWithEmailAndPassword(email, password);
|
|
|
|
personalSettingsPage.actions.enableMfa();
|
|
|
|
mainSidebar.actions.signout();
|
2023-09-01 04:29:31 -07:00
|
|
|
const token = generateOTPToken(user.mfaSecret);
|
2023-08-24 06:31:37 -07:00
|
|
|
mfaLoginPage.actions.loginWithMfaToken(email, password, token);
|
|
|
|
personalSettingsPage.actions.disableMfa();
|
|
|
|
mainSidebar.actions.signout();
|
2023-08-23 19:59:16 -07:00
|
|
|
});
|
|
|
|
});
|