From 03f405e14f6bb674c1a09442c71b6f563a4397cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9verine=20Bonnech=C3=A8re?= Date: Mon, 30 Dec 2024 14:54:19 +0100 Subject: [PATCH] fix: use urls from official doc --- src/lib/ggshield-configuration.ts | 9 +++++++- .../lib/ggshield-configuration-utils.test.ts | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/lib/ggshield-configuration.ts b/src/lib/ggshield-configuration.ts index 9408f3c..39f7ff3 100644 --- a/src/lib/ggshield-configuration.ts +++ b/src/lib/ggshield-configuration.ts @@ -9,8 +9,15 @@ export class GGShieldConfiguration { allowSelfSigned: boolean = false ) { this.ggshieldPath = ggshieldPath; - this.apiUrl = apiUrl; this.allowSelfSigned = allowSelfSigned; + if (apiUrl === "https://api.gitguardian.com/v1") { + this.apiUrl = "https://dashboard.gitguardian.com/v1"; + } else if (apiUrl === "https://api.eu1.gitguardian.com/v1") { + this.apiUrl = "https://dashboard.eu1.gitguardian.com/v1"; + } + else { + this.apiUrl = apiUrl; + } } } diff --git a/src/test/suite/lib/ggshield-configuration-utils.test.ts b/src/test/suite/lib/ggshield-configuration-utils.test.ts index 653b10f..daac328 100644 --- a/src/test/suite/lib/ggshield-configuration-utils.test.ts +++ b/src/test/suite/lib/ggshield-configuration-utils.test.ts @@ -40,4 +40,27 @@ suite("getConfiguration", () => { assert.strictEqual(configuration.apiUrl, "https://custom-url.com"); assert.strictEqual(configuration.allowSelfSigned, true); }); + + test("API url is correctly replaced with dashboard urlg for EU customers", () => { + const context = {} as ExtensionContext; + simple.mock(context, "asAbsolutePath").returnWith(""); + getConfigurationMock.returnWith({ + get: (key: string) => { + if (key === "apiUrl") { + return "https://api.eu1.gitguardian.com/v1"; + } + }, + }); + const configuration = getConfiguration(context); + + // Assert both workspace.getConfiguration and GGShieldConfiguration constructor were called + assert( + getConfigurationMock.called, + "getConfiguration should be called once" + ); + + // Assert that the configuration has the expected values + assert.strictEqual(configuration.apiUrl, "https://dashboard.eu1.gitguardian.com/v1"); + }); + });