From 996527b28e9c11db61d02550fa6b5fc924c994fc Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 20 Feb 2023 11:07:44 -0300 Subject: [PATCH] Bug 32898: Avoid hardcoding user/pass in tests This patch makes the authentication parameters be configurable through env. Before this, it was hardcoded to koha/koha, which only works if the ktd defaults haven't been tweaked. If no env is defined, it fallsback to koha/koha. In order to pass the ktd configured params, the tests need to be run like: $ yarn cypress run --env KOHA_USER=$KOHA_USER,KOHA_PASS=$KOHA_PASS Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 53bebb413aec3796ce66311b0e66c872e01fee19) Signed-off-by: Jacob O'Mara --- t/cypress/integration/Agreements_spec.ts | 2 +- t/cypress/integration/Licenses_spec.ts | 2 +- t/cypress/integration/Packages_spec.ts | 2 +- t/cypress/integration/Titles_spec.ts | 2 +- t/cypress/support/commands.js | 16 ++++++++++++---- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/t/cypress/integration/Agreements_spec.ts b/t/cypress/integration/Agreements_spec.ts index f562c40809..62f666f295 100644 --- a/t/cypress/integration/Agreements_spec.ts +++ b/t/cypress/integration/Agreements_spec.ts @@ -123,7 +123,7 @@ describe("Agreement CRUD operations", () => { }); beforeEach(() => { - cy.login("koha", "koha"); + cy.login(); cy.title().should("eq", "Koha staff interface"); }); diff --git a/t/cypress/integration/Licenses_spec.ts b/t/cypress/integration/Licenses_spec.ts index 1a308a7163..f825808138 100644 --- a/t/cypress/integration/Licenses_spec.ts +++ b/t/cypress/integration/Licenses_spec.ts @@ -39,7 +39,7 @@ describe("License CRUD operations", () => { }); beforeEach(() => { - cy.login("koha", "koha"); + cy.login(); cy.title().should("eq", "Koha staff interface"); }); diff --git a/t/cypress/integration/Packages_spec.ts b/t/cypress/integration/Packages_spec.ts index c368b79a1f..48689e9a0e 100644 --- a/t/cypress/integration/Packages_spec.ts +++ b/t/cypress/integration/Packages_spec.ts @@ -30,7 +30,7 @@ describe("Package CRUD operations", () => { }); beforeEach(() => { - cy.login("koha", "koha"); + cy.login(); cy.title().should("eq", "Koha staff interface"); }); diff --git a/t/cypress/integration/Titles_spec.ts b/t/cypress/integration/Titles_spec.ts index bef33b7831..11fd825b29 100644 --- a/t/cypress/integration/Titles_spec.ts +++ b/t/cypress/integration/Titles_spec.ts @@ -73,7 +73,7 @@ describe("Title CRUD operations", () => { }); beforeEach(() => { - cy.login("koha", "koha"); + cy.login(); cy.title().should("eq", "Koha staff interface"); }); diff --git a/t/cypress/support/commands.js b/t/cypress/support/commands.js index a918c15159..bea38fb7c9 100644 --- a/t/cypress/support/commands.js +++ b/t/cypress/support/commands.js @@ -24,11 +24,19 @@ // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) +function get_fallback_login_value(param) { + + var env_var = param == 'username' ? 'KOHA_USER' : 'KOHA_PASS'; + + return typeof Cypress.env(env_var) === 'undefined' ? 'koha' : Cypress.env(env_var); +} Cypress.Commands.add('login', (username, password) => { + var user = typeof username === 'undefined' ? get_fallback_login_value('username') : username; + var pass = typeof password === 'undefined' ? get_fallback_login_value('password') : password; cy.visit('/cgi-bin/koha/mainpage.pl?logout.x=1') - cy.get("#userid").type(username) - cy.get("#password").type(password) + cy.get("#userid").type(user) + cy.get("#password").type(pass) cy.get("#submit-button").click() }) @@ -49,7 +57,7 @@ Cypress.Commands.add('set_ERM_sys_pref_value', (enable) => { }) Cypress.Commands.add('fetch_initial_ERM_sys_pref_value', () => { - cy.login("koha", "koha"); + cy.login(); cy.visit('/cgi-bin/koha/admin/admin-home.pl') cy.get("h4").contains("Global system preferences").click(); cy.get("a[title^=E-resource]").contains("E-resource management").click(); @@ -59,6 +67,6 @@ Cypress.Commands.add('fetch_initial_ERM_sys_pref_value', () => { }) Cypress.Commands.add('reset_initial_ERM_sys_pref_value', () => { - cy.login("koha", "koha"); + cy.login(); cy.set_ERM_sys_pref_value(Cypress.env("initial_ERM_Module_sys_pref_value")); }) -- 2.39.5