Skip to content

Commit 96697bf

Browse files
heelc29laoneo
andauthored
[5.3][cypress] Use generated API bearer token (joomla#45796)
Co-authored-by: Allon Moritz <[email protected]>
1 parent cd0e5a2 commit 96697bf

File tree

2 files changed

+17
-30
lines changed

2 files changed

+17
-30
lines changed

tests/System/integration/install/Installation.cy.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ describe('Install Joomla', () => {
2828
cy.setErrorReportingToDevelopment();
2929
cy.doAdministratorLogout();
3030

31-
// Update to the correct secret for the API tests because of the bearer token
32-
cy.config_setParameter('secret', 'tEstValue');
33-
3431
// Setup mailing
3532
cy.config_setParameter('mailonline', true);
3633
cy.config_setParameter('mailer', 'smtp');

tests/System/support/commands/api.mjs

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,20 @@ Cypress.Commands.add('api_patch', (path, body) => cy.api_getBearerToken().then((
1515

1616
Cypress.Commands.add('api_delete', (path) => cy.api_getBearerToken().then((token) => cy.request({ method: 'DELETE', url: `/api/index.php/v1${path}`, headers: { Authorization: `Bearer ${token}` } })));
1717

18-
Cypress.Commands.add('api_getBearerToken', () => cy.task('queryDB', "SELECT id FROM #__users WHERE username = 'api'").then((user) => {
19-
if (user.length > 0) {
20-
return 'c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==';
21-
}
22-
23-
return cy.db_createUser({
24-
id: 3,
25-
name: 'API',
26-
27-
username: 'api',
28-
password: '123',
29-
block: 0,
30-
registerDate: '2000-01-01',
31-
params: '{}',
32-
group_id: 8,
33-
}).then((id) => {
34-
cy.task(
35-
'queryDB',
36-
'INSERT INTO #__user_profiles (user_id, profile_key, profile_value) VALUES '
37-
+ `('${id}', 'joomlatoken.token', 'dOi2m1NRrnBHlhaWK/WWxh3B5tqq1INbdf4DhUmYTI4=')`,
38-
);
39-
return cy.task(
40-
'queryDB',
41-
`INSERT INTO #__user_profiles (user_id, profile_key, profile_value) VALUES ('${id}', 'joomlatoken.enabled', 1)`,
42-
);
43-
}).then(() => 'c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
44-
}));
18+
Cypress.Commands.add('api_getBearerToken', () => {
19+
cy.session('apiToken', () => {
20+
cy.db_getUserId().then((uid) => {
21+
cy.doAdministratorLogin();
22+
cy.visit(`/administrator/index.php?option=com_users&task=user.edit&id=${uid}#attrib-joomlatoken`);
23+
cy.get('#fieldset-joomlatoken').then((fieldset) => {
24+
if (fieldset.find('#jform_joomlatoken_reset1').length > 0) {
25+
cy.get('#jform_joomlatoken_reset1').click();
26+
}
27+
});
28+
cy.clickToolbarButton('Save');
29+
cy.get('#jform_joomlatoken_token').invoke('val').then((token) => {
30+
window.localStorage.setItem('authToken', token);
31+
});
32+
});
33+
}).then(() => window.localStorage.getItem('authToken'));
34+
});

0 commit comments

Comments
 (0)