diff --git a/src/main/kotlin/snyk/common/CustomEndpoints.kt b/src/main/kotlin/snyk/common/CustomEndpoints.kt index b978490f9..b36738797 100644 --- a/src/main/kotlin/snyk/common/CustomEndpoints.kt +++ b/src/main/kotlin/snyk/common/CustomEndpoints.kt @@ -21,14 +21,12 @@ fun toSnykCodeApiUrl(endpointUrl: String?): String { uri.isDev() -> endpoint .replace("api.", "") - .replace("/v1", "") .replace("https://dev.", "https://$codeSubdomain.dev.") .suffixIfNot("/") uri.isSnykTenant() -> endpoint .replace("https://api.", "https://") - .replace("/v1", "") .replace("https://", "https://$codeSubdomain.") .suffixIfNot("/") @@ -76,7 +74,7 @@ fun getEndpointUrl(): String { } val customEndpointUrl = resolveCustomEndpoint(endpointUrl) // we need to set v1 here, to make the sast-enabled calls work in LS - return customEndpointUrl.removeTrailingSlashesIfPresent().suffixIfNot("/v1") + return customEndpointUrl.removeTrailingSlashesIfPresent() } fun isSnykCodeAvailable(endpointUrl: String?): Boolean { @@ -114,17 +112,6 @@ fun URI.isSnykTenant() = fun URI.isSnykApi() = isSnykDomain() && (host.lowercase().startsWith("api.") || path.lowercase().endsWith("/api")) -fun URI.toSnykAPIv1(): URI { - val host = host.lowercase() - .replaceFirst("app.", "api.") - .replaceFirst("deeproxy.", "api.") - .prefixIfNot( - "api." - ) - - return URI(scheme, host, "/v1/", null) -} - fun URI.isSnykDomain() = host != null && ( host.lowercase().endsWith(".snyk.io") || diff --git a/src/test/kotlin/io/snyk/plugin/cli/ConsoleCommandRunnerTest.kt b/src/test/kotlin/io/snyk/plugin/cli/ConsoleCommandRunnerTest.kt index 0c31a3b0c..23852ce1b 100644 --- a/src/test/kotlin/io/snyk/plugin/cli/ConsoleCommandRunnerTest.kt +++ b/src/test/kotlin/io/snyk/plugin/cli/ConsoleCommandRunnerTest.kt @@ -52,7 +52,7 @@ class ConsoleCommandRunnerTest : LightPlatformTestCase() { val oldEndpoint = pluginSettings().customEndpointUrl try { val generalCommandLine = GeneralCommandLine("") - val expectedEndpoint = "https://customerTestEndpoint/v1" + val expectedEndpoint = "https://customerTestEndpoint" pluginSettings().customEndpointUrl = expectedEndpoint ConsoleCommandRunner().setupCliEnvironmentVariables(generalCommandLine, "") @@ -82,7 +82,7 @@ class ConsoleCommandRunnerTest : LightPlatformTestCase() { val oldEndpoint = pluginSettings().customEndpointUrl try { val generalCommandLine = GeneralCommandLine("") - val expectedEndpoint = "https://api.xxx.snykgov.io/v1" + val expectedEndpoint = "https://api.xxx.snykgov.io" generalCommandLine.environment["SNYK_TOKEN"] = "IntelliJ TEST" pluginSettings().customEndpointUrl = expectedEndpoint @@ -104,7 +104,7 @@ class ConsoleCommandRunnerTest : LightPlatformTestCase() { val oldEndpoint = pluginSettings().customEndpointUrl try { val generalCommandLine = GeneralCommandLine("") - val expectedEndpoint = "https://api.snyk.io/v1" + val expectedEndpoint = "https://api.snyk.io" generalCommandLine.environment["INTERNAL_OAUTH_TOKEN_STORAGE"] = "{}" pluginSettings().customEndpointUrl = expectedEndpoint @@ -126,7 +126,7 @@ class ConsoleCommandRunnerTest : LightPlatformTestCase() { val oldEndpoint = pluginSettings().customEndpointUrl try { val generalCommandLine = GeneralCommandLine("") - val expectedEndpoint = "https://customerTestEndpoint/v1" + val expectedEndpoint = "https://customerTestEndpoint" pluginSettings().customEndpointUrl = expectedEndpoint ConsoleCommandRunner().setupCliEnvironmentVariables(generalCommandLine, "") diff --git a/src/test/kotlin/snyk/common/CustomEndpointsTest.kt b/src/test/kotlin/snyk/common/CustomEndpointsTest.kt index 6b803f268..a06a24a0b 100644 --- a/src/test/kotlin/snyk/common/CustomEndpointsTest.kt +++ b/src/test/kotlin/snyk/common/CustomEndpointsTest.kt @@ -103,14 +103,6 @@ class CustomEndpointsTest { assertEquals(true, snykCodeAvailable) } - @Test - fun `toSnykApiUrlV1 returns correct API URL`() { - assertEquals("https://api.snyk.io/v1/", URI("https://snyk.io/api").toSnykAPIv1().toString()) - assertEquals("https://api.snyk.io/v1/", URI("https://app.snyk.io/api").toSnykAPIv1().toString()) - assertEquals("https://api.eu.snyk.io/v1/", URI("https://app.eu.snyk.io/api").toSnykAPIv1().toString()) - assertEquals("https://api.dev.snyk.io/v1/", URI("https://dev.snyk.io/api").toSnykAPIv1().toString()) - } - @Test fun `toSnykCodeApiUrl returns correct deeproxy url for SaaS deployments`() { val apiUrlForProduction = toSnykCodeApiUrl("https://api.snyk.io") @@ -133,11 +125,9 @@ class CustomEndpointsTest { fun `toSnykCodeApiUrl returns correct deeproxy url for SaaS deployments using api url`() { val apiUrlForProduction = toSnykCodeApiUrl("https://api.eu.snyk.io") val apiUrlForDevelopment = toSnykCodeApiUrl("https://dev.api.eu.snyk.io") - val apiUrlForWithV1 = toSnykCodeApiUrl("https://api.eu.snyk.io/v1") assertEquals("https://deeproxy.eu.snyk.io/", apiUrlForProduction) assertEquals("https://deeproxy.dev.eu.snyk.io/", apiUrlForDevelopment) - assertEquals("https://deeproxy.eu.snyk.io/", apiUrlForWithV1) } @Test diff --git a/src/test/kotlin/snyk/common/lsp/SnykLanguageClientTest.kt b/src/test/kotlin/snyk/common/lsp/SnykLanguageClientTest.kt index c518a8b76..9bfc3edf7 100644 --- a/src/test/kotlin/snyk/common/lsp/SnykLanguageClientTest.kt +++ b/src/test/kotlin/snyk/common/lsp/SnykLanguageClientTest.kt @@ -123,7 +123,8 @@ class SnykLanguageClientTest { every { applicationMock.isDisposed } returns true val unexpected = "abc" - cut.hasAuthenticated(HasAuthenticatedParam(unexpected)) + val url = "https://snyk.api.io" + cut.hasAuthenticated(HasAuthenticatedParam(unexpected, url)) assertNotEquals(unexpected, settings.token) }