@@ -2,6 +2,7 @@ import { IS_EE } from './config/constants';
22import { Users } from './fixtures/userStates' ;
33import { HomeChannel , AccountProfile } from './page-objects' ;
44import { createCustomRole , deleteCustomRole } from './utils/custom-role' ;
5+ import { setSettingValueById } from './utils/setSettingValueById' ;
56import { test , expect } from './utils/test' ;
67
78test . use ( { storageState : Users . admin . state } ) ;
@@ -62,4 +63,44 @@ test.describe('enforce two factor authentication', () => {
6263 await expect ( poHomeChannel . sidenav . sidebarHomeAction ) . toBeVisible ( ) ;
6364 await expect ( poAccountProfile . securityHeader ) . not . toBeVisible ( ) ;
6465 } ) ;
66+
67+ test . describe ( 'should still redirect to 2FA setup page when email 2FA is disabled' , ( ) => {
68+ test . beforeAll ( async ( { api } ) => {
69+ await setSettingValueById ( api , 'Accounts_TwoFactorAuthentication_By_Email_Enabled' , false ) ;
70+ } ) ;
71+
72+ test . afterAll ( async ( { api } ) => {
73+ await setSettingValueById ( api , 'Accounts_TwoFactorAuthentication_By_Email_Enabled' , true ) ;
74+ } ) ;
75+
76+ test ( 'should redirect to 2FA setup page and show totp 2FA setup' , async ( { page } ) => {
77+ await page . goto ( '/home' ) ;
78+ await poAccountProfile . required2faModalSetUpButton . click ( ) ;
79+ await expect ( poHomeChannel . sidenav . sidebarHomeAction ) . not . toBeVisible ( ) ;
80+
81+ await expect ( poAccountProfile . securityHeader ) . toBeVisible ( ) ;
82+
83+ await expect ( poAccountProfile . security2FASection ) . toHaveAttribute ( 'aria-expanded' , 'true' ) ;
84+ await expect ( poAccountProfile . totp2FASwitch ) . toBeVisible ( ) ;
85+ await expect ( poAccountProfile . email2FASwitch ) . not . toBeVisible ( ) ;
86+ } ) ;
87+ } ) ;
88+
89+ test . describe ( 'should not redirect to 2FA setup page when both email and totp 2FA are disabled' , ( ) => {
90+ test . beforeAll ( async ( { api } ) => {
91+ await setSettingValueById ( api , 'Accounts_TwoFactorAuthentication_By_Email_Enabled' , false ) ;
92+ await setSettingValueById ( api , 'Accounts_TwoFactorAuthentication_By_TOTP_Enabled' , false ) ;
93+ } ) ;
94+
95+ test . afterAll ( async ( { api } ) => {
96+ await setSettingValueById ( api , 'Accounts_TwoFactorAuthentication_By_Email_Enabled' , true ) ;
97+ await setSettingValueById ( api , 'Accounts_TwoFactorAuthentication_By_TOTP_Enabled' , true ) ;
98+ } ) ;
99+
100+ test ( 'should not redirect to 2FA setup page' , async ( { page } ) => {
101+ await page . goto ( '/home' ) ;
102+ await expect ( poHomeChannel . sidenav . sidebarHomeAction ) . toBeVisible ( ) ;
103+ await expect ( poAccountProfile . securityHeader ) . not . toBeVisible ( ) ;
104+ } ) ;
105+ } ) ;
65106} ) ;
0 commit comments