Skip to content

Commit

Permalink
tidy: remove legacy functionality for domain/V1
Browse files Browse the repository at this point in the history
  • Loading branch information
acke committed Oct 25, 2024
1 parent fd72442 commit 70370d0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 29 deletions.
15 changes: 1 addition & 14 deletions src/main/kotlin/snyk/common/CustomEndpoints.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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") ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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, "")
Expand Down
10 changes: 0 additions & 10 deletions src/test/kotlin/snyk/common/CustomEndpointsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/test/kotlin/snyk/common/lsp/SnykLanguageClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 70370d0

Please sign in to comment.