Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Resolve UI app test auth server url from manager info (#3135)

Koene2cc56e20f1c
diff --git a/.github/workflows/ui-app-tests.yml b/.github/workflows/ui-app-tests.yml
index 722e28a58..342c759e2 100644
--- a/.github/workflows/ui-app-tests.yml
+++ b/.github/workflows/ui-app-tests.yml
@@ -46,6 +46,9 @@ jobs:
- name: Run UI App Tests
timeout-minutes: 20
run: |
+ # Make temp dir with 777 mask as docker seems to run as root
+ mkdir -pm 777 tmp
+
# Start the stack
docker compose -f profile/dev-testing.yml up -d --no-build
diff --git a/ui/app/manager/test/fixtures/manager.ts b/ui/app/manager/test/fixtures/manager.ts
index 86ec9e28c..893a65cf9 100644
--- a/ui/app/manager/test/fixtures/manager.ts
+++ b/ui/app/manager/test/fixtures/manager.ts
@@ -65,6 +65,7 @@ function warnOnHttpError(e: unknown, message: string, ...context: unknown[]) {
export class Manager {
private readonly clientId = "openremote";
private readonly managerHost: string;
+ private authServerUrl?: string;
readonly api: RestApi["api"];
readonly axios: RestApi["_axiosInstance"];
@@ -197,7 +198,7 @@ export class Manager {
await this.page.locator("#menu > #list > li").filter({ hasText: "Log out" }).click();
}
// Wait for navigation to login page to prevent simultaneous navigation
- await this.page.waitForURL("**/auth/realms/**");
+ await this.page.waitForURL(`${await this.getAuthServerUrl()}/realms/**`);
}
async resetLocale(realm: string, username: Usernames, password: string) {
@@ -207,20 +208,35 @@ export class Manager {
});
}
+ /**
+ * Resolve the auth server URL from the manager info endpoint, the same source the apps use at startup.
+ *
+ * The manager reports either an absolute URL or one relative to itself, so it is resolved against the manager
+ * host and cached for the lifetime of the fixture.
+ */
+ async getAuthServerUrl() {
+ if (!this.authServerUrl) {
+ const { authServerUrl } = (await this.api.StatusResource.getInfo()).data;
+ this.authServerUrl = new URL(authServerUrl || "/auth", this.managerHost).toString().replace(/\/+$/, "");
+ }
+ return this.authServerUrl;
+ }
+
async getAccessToken(realm: string, username: Usernames, password: string) {
const data = new URLSearchParams();
data.append("client_id", this.clientId);
data.append("username", username);
data.append("password", password);
data.append("grant_type", "password");
- const { access_token } = (
- await this.axios.post(`${this.managerHost}/auth/realms/${realm}/protocol/openid-connect/token`, data, {
+ const authServerUrl = await this.getAuthServerUrl();
+ const { access_token: accessToken } = (
+ await this.axios.post(`${authServerUrl}/realms/${realm}/protocol/openid-connect/token`, data, {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
})
).data;
- return access_token;
+ return accessToken;
}
/**
diff --git a/ui/test/manager.cjs b/ui/test/manager.cjs
index 0d8fc5827..1d8b18121 100755
--- a/ui/test/manager.cjs
+++ b/ui/test/manager.cjs
@@ -25,7 +25,7 @@ const os = require("node:os");
process.chdir(path.resolve(__dirname, "../.."));
// --- Default Environment Variables ---
-process.env.OR_STORAGE_DIR = process.env.OR_STORAGE_DIR || "ui/test/tmp"; // Changed to relative local directory
+process.env.OR_STORAGE_DIR = process.env.OR_STORAGE_DIR || "tmp"; // Changed to relative local directory
process.env.OR_APP_DOCROOT = process.env.OR_APP_DOCROOT || "manager/build/install/manager/web";
// Variables without defaults
process.env.OR_LOGGING_CONFIG_FILE =