From 9f1ffde4c07e2515bde6c0c03edb8eb6c23ae16e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 11 Aug 2022 16:23:16 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=85=20e2e:=20Make=20port=20configurab?= =?UTF-8?q?le?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cookie are port specific, so they need to be determine from the port from the base URL. --- tests/cypress/integration/login.js | 16 +++++++++++----- tests/cypress/util/util.js | 6 ++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/cypress/integration/login.js b/tests/cypress/integration/login.js index afe7307fa..1281ffd99 100644 --- a/tests/cypress/integration/login.js +++ b/tests/cypress/integration/login.js @@ -1,4 +1,10 @@ -import {prepare_server, await_coreui, await_loginui, login} from "../util/util"; +import { + prepare_server, + await_coreui, + await_loginui, + login, + get_cookie_name +} from "../util/util"; context("Login tests", () => { const username = "admin"; @@ -27,8 +33,8 @@ context("Login tests", () => { await_coreui(); cy.get("[data-test-id=login-menu-title]").should("contain", username); - cy.getCookie("session_P5000").should("exist"); - cy.getCookie("remember_token_P5000").should("not.exist"); + cy.getCookie(get_cookie_name("session")).should("exist"); + cy.getCookie(get_cookie_name("remember_token")).should("not.exist"); cy.location().should((loc) => { expect(loc.hash).to.eq("#temp"); }); @@ -45,8 +51,8 @@ context("Login tests", () => { await_coreui(); cy.get("[data-test-id=login-menu-title]").should("contain", username); - cy.getCookie("session_P5000").should("exist"); - cy.getCookie("remember_token_P5000").should(($cookie) => { + cy.getCookie(get_cookie_name("session")).should("exist"); + cy.getCookie(get_cookie_name("remember_token")).should(($cookie) => { expect($cookie).to.have.property("value"); expect($cookie.value).to.match(new RegExp("^" + username + "|")); }); diff --git a/tests/cypress/util/util.js b/tests/cypress/util/util.js index 81e769ad8..2b568e660 100644 --- a/tests/cypress/util/util.js +++ b/tests/cypress/util/util.js @@ -70,3 +70,9 @@ export const ensure_file_unknown = (location, name) => { failOnStatusCode: false }); }; + +export const get_cookie_name = (cookie) => { + const url = new URL(Cypress.config("baseUrl")); + const port = url.port || (url.protocol === "https:" ? 443 : 80); + return `${cookie}_P${port}`; +}; From ae1cba8d914f390dfa13ea569e23a2f1d30d3384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 16 Aug 2022 11:37:44 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=85=20Make=20E2E=20tests=20compatible?= =?UTF-8?q?=20to=20prefix=20paths?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/cypress/integration/login.js | 9 +++-- tests/cypress/util/util.js | 59 +++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/tests/cypress/integration/login.js b/tests/cypress/integration/login.js index 1281ffd99..f158478e0 100644 --- a/tests/cypress/integration/login.js +++ b/tests/cypress/integration/login.js @@ -3,7 +3,8 @@ import { await_coreui, await_loginui, login, - get_cookie_name + get_cookie_name, + get_full_url } from "../util/util"; context("Login tests", () => { @@ -19,7 +20,7 @@ context("Login tests", () => { cy.visit("/?l10n=en"); await_loginui(); cy.location().should((loc) => { - expect(loc.pathname).to.eq("/login/"); + expect(loc.pathname).to.eq(get_full_url("/login/")); }); }); @@ -77,7 +78,7 @@ context("Login tests", () => { await_loginui(); cy.location().should((loc) => { - expect(loc.pathname).to.eq("/login/"); + expect(loc.pathname).to.eq(get_full_url("/login/")); }); }); }); @@ -87,7 +88,7 @@ context("Login tests", () => { cy.visit("/?l10n=en"); await_loginui(); cy.location().should((loc) => { - expect(loc.pathname).to.eq("/login/"); + expect(loc.pathname).to.eq(get_full_url("/login/")); }); }); diff --git a/tests/cypress/util/util.js b/tests/cypress/util/util.js index 2b568e660..6fc9e55f5 100644 --- a/tests/cypress/util/util.js +++ b/tests/cypress/util/util.js @@ -1,12 +1,16 @@ export const prepare_server = () => { - cy.intercept("POST", "/api/login").as("login"); - cy.intercept("POST", "/api/logout").as("logout"); - cy.intercept("GET", "/api/settings").as("settings"); - cy.intercept("GET", "/api/files?recursive=true").as("files"); - cy.intercept("GET", "/plugin/softwareupdate/check").as("softwareupdate"); - cy.intercept("GET", "/plugin/pluginmanager/plugins").as("pluginmanager"); - cy.intercept("POST", "/api/connection").as("connectionCommand"); - cy.intercept("GET", "/api/connection").as("connectionDetails"); + cy.intercept("POST", get_full_url("/api/login")).as("login"); + cy.intercept("POST", get_full_url("/api/logout")).as("logout"); + cy.intercept("GET", get_full_url("/api/settings")).as("settings"); + cy.intercept("GET", get_full_url("/api/files?recursive=true")).as("files"); + cy.intercept("GET", get_full_url("/plugin/softwareupdate/check")).as( + "softwareupdate" + ); + cy.intercept("GET", get_full_url("/plugin/pluginmanager/plugins")).as( + "pluginmanager" + ); + cy.intercept("POST", get_full_url("/api/connection")).as("connectionCommand"); + cy.intercept("GET", get_full_url("/api/connection")).as("connectionDetails"); }; export const await_loginui = () => { @@ -24,7 +28,7 @@ export const await_coreui = () => { export const login = (username, password) => { cy.request({ method: "POST", - url: "/api/login", + url: get_full_url("/api/login"), body: { user: username, pass: password @@ -35,7 +39,7 @@ export const login = (username, password) => { export const logout = () => { cy.request({ method: "POST", - url: "/api/logout" + url: get_full_url("/api/logout") }); }; @@ -44,7 +48,7 @@ export const connect = (port, baudrate) => { baudrate = baudrate || 0; cy.request({ method: "POST", - url: "/api/connection", + url: get_full_url("/api/connection"), body: { command: "connect", port: port, @@ -56,7 +60,7 @@ export const connect = (port, baudrate) => { export const disconnect = () => { cy.request({ method: "POST", - url: "/api/connection", + url: get_full_url("/api/connection"), body: { command: "disconnect" } @@ -66,7 +70,7 @@ export const disconnect = () => { export const ensure_file_unknown = (location, name) => { cy.request({ method: "DELETE", - url: `/api/files/${location}/${name}`, + url: get_full_url(`/api/files/${location}/${name}`), failOnStatusCode: false }); }; @@ -74,5 +78,32 @@ export const ensure_file_unknown = (location, name) => { export const get_cookie_name = (cookie) => { const url = new URL(Cypress.config("baseUrl")); const port = url.port || (url.protocol === "https:" ? 443 : 80); - return `${cookie}_P${port}`; + if (url.pathname && url.pathname !== "/") { + let path = url.pathname; + if (path.endsWith("/")) { + path = path.substring(0, path.length - 1); + } + return `${cookie}_P${port}_R${path.replace(/\//, "|")}`; + } else { + return `${cookie}_P${port}`; + } +}; + +export const get_full_url = (url) => { + const parsed = new URL(Cypress.config("baseUrl")); + + let path = ""; + if (parsed.pathname) { + path = parsed.pathname; + } + if (path.endsWith("/")) { + path = path.substring(0, path.length - 1); + } + + let url2 = url; + if (url2.startsWith("/")) { + url2 = url2.substring(1); + } + + return path + "/" + url2; };