Skip to content

Commit cd0e5a2

Browse files
authored
[5.3] system test for multi-factor authentication plugins (passkey) (joomla#45048)
* [5.2] system test for multi-factor authentication * [5.3] system test for multi-factor authentication (passkey) * disable firefox
1 parent 108662f commit cd0e5a2

File tree

2 files changed

+73
-4
lines changed
  • tests/System/integration

2 files changed

+73
-4
lines changed

tests/System/integration/administrator/components/com_users/Mfa.cy.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { TOTP } from 'totp-generator';
22

3-
afterEach(() => cy.db_getUserId().then((uid) => cy.task('queryDB', `DELETE FROM #__user_mfa WHERE user_id = ${uid}`)));
4-
53
describe('Test in backend that the user', () => {
4+
afterEach(() => cy.db_getUserId().then((uid) => cy.task('queryDB', `DELETE FROM #__user_mfa WHERE user_id = ${uid}`)));
5+
66
it('can login with Multi-factor Authentication (email)', () => {
77
cy.doAdministratorLogin();
88
cy.visit('/administrator/index.php?option=com_users&view=users');
@@ -80,6 +80,44 @@ describe('Test in backend that the user', () => {
8080
cy.get('#com-users-methods-reset-message').contains('not enabled');
8181
});
8282

83+
it('can login with Multi-factor Authentication (passkey)', { browser: '!firefox' }, () => {
84+
Cypress.automation('remote:debugger:protocol', { command: 'WebAuthn.enable', params: {} }).then(() => {
85+
Cypress.automation('remote:debugger:protocol', {
86+
command: 'WebAuthn.addVirtualAuthenticator',
87+
params: {
88+
options: {
89+
protocol: 'ctap2', transport: 'internal', hasResidentKey: true, hasUserVerification: true, isUserVerified: true,
90+
},
91+
},
92+
});
93+
});
94+
cy.doAdministratorLogin();
95+
cy.visit('/administrator/index.php?option=com_users&view=users');
96+
cy.get('.header-profile:visible').click();
97+
cy.get('.header-profile a.dropdown-item').contains('Edit Account').click();
98+
cy.get('#myTab div[role="tablist"] button[aria-controls="multifactorauth"]').click();
99+
cy.get('.com-users-methods-list-method-name-webauthn a.com-users-methods-list-method-addnew').click();
100+
cy.get('#com-users-method-edit-title').clear().type('Test Passkey');
101+
cy.get('#toolbar-user-mfa-edit-save').click();
102+
cy.get('.com-users-methods-list-method-name-webauthn .com-users-methods-list-method-record').contains('Test Passkey');
103+
cy.clickToolbarButton('Cancel');
104+
cy.doAdministratorLogout();
105+
cy.get('#mod-login-username').type(Cypress.env('username'));
106+
cy.get('#mod-login-password').type(Cypress.env('password'));
107+
cy.get('#form-login').submit();
108+
cy.get('#users-mfa-title').contains('Passkey');
109+
cy.get('#toolbar-user-mfa-submit').click();
110+
cy.visit('/administrator/index.php?option=com_users&view=users');
111+
cy.get('.header-profile:visible').click();
112+
cy.get('.header-profile a.dropdown-item').contains('Edit Account').click();
113+
cy.get('#myTab div[role="tablist"] button[aria-controls="multifactorauth"]').click();
114+
cy.get('#com-users-methods-reset-message').contains('is enabled');
115+
cy.get('.com-users-methods-list-method-name-webauthn a.com-users-methods-list-method-record-delete').click();
116+
cy.on('window:confirm', (text) => expect(text).to.contains('Are you sure you want to delete?'));
117+
cy.get('#com-users-methods-reset-message').contains('not enabled');
118+
cy.then(() => Cypress.automation('remote:debugger:protocol', { command: 'WebAuthn.disable', params: {} }));
119+
});
120+
83121
it('can login with Multi-factor Authentication (backup codes)', () => {
84122
cy.doAdministratorLogin();
85123
cy.visit('/administrator/index.php?option=com_users&view=users');

tests/System/integration/site/components/com_users/Mfa.cy.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { TOTP } from 'totp-generator';
22

3-
afterEach(() => cy.db_getUserId().then((uid) => cy.task('queryDB', `DELETE FROM #__user_mfa WHERE user_id = ${uid}`)));
4-
53
describe('Test in frontend that the user', () => {
4+
afterEach(() => cy.db_getUserId().then((uid) => cy.task('queryDB', `DELETE FROM #__user_mfa WHERE user_id = ${uid}`)));
5+
66
it('can login with Multi-factor Authentication (email)', () => {
77
cy.doFrontendLogin();
88
cy.visit('/index.php?option=com_users&view=profile&layout=edit');
@@ -66,6 +66,37 @@ describe('Test in frontend that the user', () => {
6666
cy.get('#com-users-methods-reset-message').contains('not enabled');
6767
});
6868

69+
it('can login with Multi-factor Authentication (passkey)', { browser: '!firefox' }, () => {
70+
Cypress.automation('remote:debugger:protocol', { command: 'WebAuthn.enable', params: {} }).then(() => {
71+
Cypress.automation('remote:debugger:protocol', {
72+
command: 'WebAuthn.addVirtualAuthenticator',
73+
params: {
74+
options: {
75+
protocol: 'ctap2', transport: 'internal', hasResidentKey: true, hasUserVerification: true, isUserVerified: true,
76+
},
77+
},
78+
});
79+
});
80+
cy.doFrontendLogin();
81+
cy.visit('/index.php?option=com_users&view=profile&layout=edit');
82+
cy.get('.com-users-methods-list-method-name-webauthn a.com-users-methods-list-method-addnew').click();
83+
cy.get('#com-users-method-edit-title').clear().type('Test Passkey');
84+
cy.get('#com-users-method-edit button.multifactorauth_webauthn_setup').click();
85+
cy.get('.com-users-methods-list-method-name-webauthn .com-users-methods-list-method-record').contains('Test Passkey');
86+
cy.doFrontendLogout();
87+
cy.get('form.mod-login input[name="username"]').type(Cypress.env('username'));
88+
cy.get('form.mod-login input[name="password"]').type(Cypress.env('password'));
89+
cy.get('form.mod-login').submit();
90+
cy.get('#users-mfa-title').contains('Passkey');
91+
cy.get('#users-mfa-captive-button-submit').click();
92+
cy.visit('/index.php?option=com_users&view=profile&layout=edit');
93+
cy.get('#com-users-methods-reset-message').contains('is enabled');
94+
cy.get('.com-users-methods-list-method-name-webauthn a.com-users-methods-list-method-record-delete').click();
95+
cy.on('window:confirm', (text) => expect(text).to.contains('Are you sure you want to delete?'));
96+
cy.get('#com-users-methods-reset-message').contains('not enabled');
97+
cy.then(() => Cypress.automation('remote:debugger:protocol', { command: 'WebAuthn.disable', params: {} }));
98+
});
99+
69100
it('can login with Multi-factor Authentication (backup codes)', () => {
70101
cy.doFrontendLogin();
71102
cy.visit('/index.php?option=com_users&view=profile&layout=edit');

0 commit comments

Comments
 (0)