From 67f819e2e4c17d144a3d5f12e14cec60157ee10b Mon Sep 17 00:00:00 2001 From: Yin Yue Date: Mon, 16 Sep 2024 11:22:41 +0530 Subject: [PATCH 1/3] SCAL-103002 check TS host response --- src/embed/ts-embed.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/embed/ts-embed.ts b/src/embed/ts-embed.ts index b7c02805..670396ff 100644 --- a/src/embed/ts-embed.ts +++ b/src/embed/ts-embed.ts @@ -164,6 +164,7 @@ export class TsEmbed { if (!this.embedConfig.authTriggerContainer && !this.embedConfig.useEventForSAMLPopup) { this.embedConfig.authTriggerContainer = domSelector; } + this.checkThoughtSpotHost(); this.thoughtSpotHost = getThoughtSpotHost(this.embedConfig); this.thoughtSpotV2Base = getV2BasePath(this.embedConfig); this.eventHandlerMap = new Map(); @@ -180,6 +181,19 @@ export class TsEmbed { }); } + private async checkThoughtSpotHost() { + try { + this.thoughtSpotHost = this.embedConfig.thoughtSpotHost; + const response = await fetch(`${this.thoughtSpotHost}/config`); + if (response.status !== 200) { + this.handleError(ERROR_MESSAGE.INVALID_THOUGHTSPOT_HOST) + } else { + logger.log("ThoughtSpot host is valid."); + } + } catch (error) { + this.handleError(ERROR_MESSAGE.INVALID_THOUGHTSPOT_HOST) + } + } /** * Throws error encountered during initialization. */ From 03e17eb1267a764e084a1575ac097f279b171661 Mon Sep 17 00:00:00 2001 From: Yin Yue Date: Wed, 18 Sep 2024 16:18:42 +0530 Subject: [PATCH 2/3] SCAL-103002 check TS host response --- src/auth.ts | 1 + src/embed/base.ts | 16 ++++++++++++++++ src/embed/ts-embed.ts | 14 -------------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/auth.ts b/src/auth.ts index 02c3f1e0..7024527b 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -36,6 +36,7 @@ export const SSO_REDIRECTION_MARKER_GUID = '5e16222e-ef02-43e9-9fbd-24226bf3ce5b */ export enum AuthFailureType { SDK = 'SDK', + INVALID_TS_HOST = 'INVALID_TS_HOST', NO_COOKIE_ACCESS = 'NO_COOKIE_ACCESS', EXPIRY = 'EXPIRY', OTHER = 'OTHER', diff --git a/src/embed/base.ts b/src/embed/base.ts index 9f3b1df6..ca133637 100644 --- a/src/embed/base.ts +++ b/src/embed/base.ts @@ -209,9 +209,25 @@ export const init = (embedConfig: EmbedConfig): AuthEventEmitter => { if (getEmbedConfig().callPrefetch) { prefetch(getEmbedConfig().thoughtSpotHost); } + validateThoughtSpotHost(embedConfig.thoughtSpotHost, authEE); return authEE as AuthEventEmitter; }; + +const validateThoughtSpotHost = async (thoughtSpotHost: string, authEE: EventEmitter) => { + try { + const response = await fetch(`${thoughtSpotHost}/config`); + if (response.status !== 200) { + logger.error(`Check if Thoughtspot Host is Valid: ${response.statusText}`); + notifyAuthFailure(AuthFailureType.INVALID_TS_HOST); + } else { + logger.info("ThoughtSpot host is valid."); + } + } catch (error) { + logger.error("Error validating ThoughtSpot host:", error); + notifyAuthFailure(AuthFailureType.INVALID_TS_HOST); + } +}; /** * */ diff --git a/src/embed/ts-embed.ts b/src/embed/ts-embed.ts index 670396ff..b7c02805 100644 --- a/src/embed/ts-embed.ts +++ b/src/embed/ts-embed.ts @@ -164,7 +164,6 @@ export class TsEmbed { if (!this.embedConfig.authTriggerContainer && !this.embedConfig.useEventForSAMLPopup) { this.embedConfig.authTriggerContainer = domSelector; } - this.checkThoughtSpotHost(); this.thoughtSpotHost = getThoughtSpotHost(this.embedConfig); this.thoughtSpotV2Base = getV2BasePath(this.embedConfig); this.eventHandlerMap = new Map(); @@ -181,19 +180,6 @@ export class TsEmbed { }); } - private async checkThoughtSpotHost() { - try { - this.thoughtSpotHost = this.embedConfig.thoughtSpotHost; - const response = await fetch(`${this.thoughtSpotHost}/config`); - if (response.status !== 200) { - this.handleError(ERROR_MESSAGE.INVALID_THOUGHTSPOT_HOST) - } else { - logger.log("ThoughtSpot host is valid."); - } - } catch (error) { - this.handleError(ERROR_MESSAGE.INVALID_THOUGHTSPOT_HOST) - } - } /** * Throws error encountered during initialization. */ From 4f9b7f3eacb33151adf1f60da476bc6c53bb8ddf Mon Sep 17 00:00:00 2001 From: Yin Yue Date: Wed, 18 Sep 2024 16:56:47 +0530 Subject: [PATCH 3/3] SCAL-103002 check direct ping to host --- src/embed/base.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/embed/base.ts b/src/embed/base.ts index ca133637..624f44ea 100644 --- a/src/embed/base.ts +++ b/src/embed/base.ts @@ -209,14 +209,14 @@ export const init = (embedConfig: EmbedConfig): AuthEventEmitter => { if (getEmbedConfig().callPrefetch) { prefetch(getEmbedConfig().thoughtSpotHost); } - validateThoughtSpotHost(embedConfig.thoughtSpotHost, authEE); + validateThoughtSpotHost(embedConfig.thoughtSpotHost); return authEE as AuthEventEmitter; }; -const validateThoughtSpotHost = async (thoughtSpotHost: string, authEE: EventEmitter) => { +const validateThoughtSpotHost = async (thoughtSpotHost: string) => { try { - const response = await fetch(`${thoughtSpotHost}/config`); + const response = await fetch(`${thoughtSpotHost}`); if (response.status !== 200) { logger.error(`Check if Thoughtspot Host is Valid: ${response.statusText}`); notifyAuthFailure(AuthFailureType.INVALID_TS_HOST);