From 8856d8f812154424835a77c8099eb9a1c6925906 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Fri, 12 Feb 2021 11:22:39 -0500 Subject: [PATCH] add another test Signed-off-by: Sebastian Malton --- src/common/__tests__/cluster-store.test.ts | 18 ++++++++++++++++-- src/common/cluster-store.ts | 7 +++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/common/__tests__/cluster-store.test.ts b/src/common/__tests__/cluster-store.test.ts index 72073fef6e..6ee34388a2 100644 --- a/src/common/__tests__/cluster-store.test.ts +++ b/src/common/__tests__/cluster-store.test.ts @@ -448,11 +448,25 @@ describe("pre 3.6.0-beta.1 config with an existing cluster", () => { }); describe("getClusterIdFromHost", () => { + const clusterFakeId = "fe540901-0bd6-4f6c-b472-bce1559d7c4a"; + it("should return undefined for non cluster frame hosts", () => { expect(getClusterIdFromHost("localhost:45345")).toBeUndefined(); }); - it("should return undefined for non cluster frame hosts", () => { - expect(getClusterIdFromHost("fe540901-0bd6-4f6c-b472-bce1559d7c4a.localhost:59110")).toBe("fe540901-0bd6-4f6c-b472-bce1559d7c4a"); + it("should return ClusterId for cluster frame hosts", () => { + expect(getClusterIdFromHost(`${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId); + }); + + it("should return ClusterId for cluster frame hosts with additional subdomains", () => { + expect(getClusterIdFromHost(`abc.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId); + expect(getClusterIdFromHost(`abc.def.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId); + expect(getClusterIdFromHost(`abc.def.ghi.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId); + expect(getClusterIdFromHost(`abc.def.ghi.jkl.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId); + expect(getClusterIdFromHost(`abc.def.ghi.jkl.mno.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId); + expect(getClusterIdFromHost(`abc.def.ghi.jkl.mno.pqr.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId); + expect(getClusterIdFromHost(`abc.def.ghi.jkl.mno.pqr.stu.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId); + expect(getClusterIdFromHost(`abc.def.ghi.jkl.mno.pqr.stu.vwx.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId); + expect(getClusterIdFromHost(`abc.def.ghi.jkl.mno.pqr.stu.vwx.yz.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId); }); }); diff --git a/src/common/cluster-store.ts b/src/common/cluster-store.ts index e80684d54c..c68692edd3 100644 --- a/src/common/cluster-store.ts +++ b/src/common/cluster-store.ts @@ -357,12 +357,11 @@ export const clusterStore = ClusterStore.getInstance(); export function getClusterIdFromHost(host: string): ClusterId | undefined { // e.g host == "%clusterId.localhost:45345" const subDomains = host.split(":")[0].split("."); + const lastTwoParts = subDomains.slice(-2); - if (subDomains.length >= 2) { - return subDomains[0]; - } + lastTwoParts.pop(); // remove last entry (namely "localhost") - return undefined; + return lastTwoParts[0]; // ClusterId or undefined } export function getClusterFrameUrl(clusterId: ClusterId) {