From 3672da1e1de08de7dcd0bc8b220f5f701fa9da86 Mon Sep 17 00:00:00 2001 From: artrejo Date: Fri, 21 Jan 2022 08:21:47 -0800 Subject: [PATCH] Add allowed endpoints to make unit tests pass --- src/ConfigContext.ts | 8 +------- src/Utils/EndpointValidation.ts | 32 ++++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/ConfigContext.ts b/src/ConfigContext.ts index 46c98d0a7..aed67e919 100644 --- a/src/ConfigContext.ts +++ b/src/ConfigContext.ts @@ -8,7 +8,6 @@ import { allowedEmulatorEndpoints, allowedGraphEndpoints, allowedHostedExplorerEndpoints, - allowedJunoEndpoints, allowedMongoBackendEndpoints, allowedMsalRedirectEndpoints, validateEndpoint, @@ -169,12 +168,7 @@ export function updateConfigContext(newContext: Partial): void { delete newContext.MONGO_BACKEND_ENDPOINT; } - if ( - !validateEndpoint( - newContext.JUNO_ENDPOINT, - allowedJunoEndpoints.map((endpoint) => endpoint) - ) - ) { + if (!validateEndpoint(newContext.JUNO_ENDPOINT, configContext.allowedJunoOrigins)) { delete newContext.JUNO_ENDPOINT; } diff --git a/src/Utils/EndpointValidation.ts b/src/Utils/EndpointValidation.ts index ca08a0176..fe379a9c8 100644 --- a/src/Utils/EndpointValidation.ts +++ b/src/Utils/EndpointValidation.ts @@ -2,9 +2,16 @@ export function validateEndpoint(endpointToValidate: string | undefined, allowed if (!endpointToValidate) { return true; } + const originToValidate: string = new URL(endpointToValidate).origin; const allowedOrigins: string[] = allowedEndpoints.map((allowedEndpoint) => new URL(allowedEndpoint).origin) || []; - return allowedOrigins.indexOf(originToValidate) >= 0; + const valid = allowedOrigins.indexOf(originToValidate) >= 0; + + if (!valid) { + console.error(`${endpointToValidate} not allowed`); + } + + return valid; } export const allowedArmEndpoints: ReadonlyArray = [ @@ -15,6 +22,17 @@ export const allowedArmEndpoints: ReadonlyArray = [ export const allowedAadEndpoints: ReadonlyArray = ["https://login.microsoftonline.com/"]; +export const allowedBackendEndpoints: ReadonlyArray = [ + "https://main.documentdb.ext.azure.com", + "https://localhost:12901", + "https://localhost:1234", +]; + +export const allowedMongoProxyEndpoints: ReadonlyArray = [ + "https://main.documentdb.ext.azure.com", + "https://localhost:12901", +]; + export const allowedEmulatorEndpoints: ReadonlyArray = []; export const allowedGraphEndpoints: ReadonlyArray = []; @@ -23,18 +41,12 @@ export const allowedArcadiaEndpoints: ReadonlyArray = []; export const allowedArcadiaLivyDnsZones: ReadonlyArray = []; -export const allowedBackendEndpoints: ReadonlyArray = []; - -export const allowedMongoBackendEndpoints: ReadonlyArray = []; - -export const allowedJunoEndpoints: ReadonlyArray = []; +export const allowedMongoBackendEndpoints: ReadonlyArray = [ + "https://localhost:1234" +]; export const allowedHostedExplorerEndpoints: ReadonlyArray = []; export const allowedMsalRedirectEndpoints: ReadonlyArray = []; -export const allowedMongoProxyEndpoints: ReadonlyArray = []; - -export const allowedPhoenixEndpoints: ReadonlyArray = []; - export const allowedNotebookServerUrls: ReadonlyArray = [];