From 6ff532ecb31866aceaeb8e40b423b771da3181c2 Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Thu, 31 Aug 2023 16:53:40 +0200 Subject: [PATCH] chore: change check for fedramp to rely on the snykgov.io domain only --- .../kotlin/snyk/common/CustomEndpoints.kt | 26 +++++++++++++------ .../kotlin/snyk/common/CustomEndpointsTest.kt | 4 +-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/snyk/common/CustomEndpoints.kt b/src/main/kotlin/snyk/common/CustomEndpoints.kt index ec3d18b3e..85a3422e9 100644 --- a/src/main/kotlin/snyk/common/CustomEndpoints.kt +++ b/src/main/kotlin/snyk/common/CustomEndpoints.kt @@ -84,12 +84,16 @@ internal fun resolveCustomEndpoint(endpointUrl: String?): String { } fun URI.isSnykTenant() = - isSnykDomain() && (host.startsWith("app.") || host == "snyk.io" || isDev()) && path.endsWith("/api") + isSnykDomain() && + path.lowercase().endsWith("/api") && + (host.lowercase().startsWith("app.") || + host.lowercase() == "snyk.io" || + isDev()) -fun URI.isSnykApi() = isSnykDomain() && (host.startsWith("api.") || path.endsWith("/api")) +fun URI.isSnykApi() = isSnykDomain() && (host.lowercase().startsWith("api.") || path.lowercase().endsWith("/api")) fun URI.toSnykAPIv1(): URI { - val host = host + val host = host.lowercase() .replaceFirst("app.", "api.") .replaceFirst("deeproxy.", "api.") .prefixIfNot("api.") @@ -97,15 +101,21 @@ fun URI.toSnykAPIv1(): URI { return URI(scheme, host, "/v1/", null) } -fun URI.isSnykDomain() = host != null && (host.endsWith("snyk.io") || host.endsWith("snykgov.io")) +fun URI.isSnykDomain() = host != null && + ( + host.lowercase().endsWith(".snyk.io") || + host.lowercase() == "snyk.io" || + host.lowercase().endsWith(".snykgov.io")) -fun URI.isDeeproxy() = isSnykDomain() && host.startsWith("deeproxy.") +fun URI.isDeeproxy() = isSnykDomain() && host.lowercase().startsWith("deeproxy.") -fun URI.isOauth() = host != null && host.endsWith(".snykgov.io") +fun URI.isSnykGov() = host != null && host.lowercase().endsWith(".snykgov.io") -fun URI.isDev() = isSnykDomain() && host.startsWith("dev.") +fun URI.isOauth() = isSnykGov() -fun URI.isFedramp() = isOauth() && host.contains("fedramp") +fun URI.isDev() = isSnykDomain() && host.lowercase().startsWith("dev.") + +fun URI.isFedramp() = isSnykGov() fun isFedramp(): Boolean { val settings = pluginSettings() diff --git a/src/test/kotlin/snyk/common/CustomEndpointsTest.kt b/src/test/kotlin/snyk/common/CustomEndpointsTest.kt index 261d81065..09e5a4d80 100644 --- a/src/test/kotlin/snyk/common/CustomEndpointsTest.kt +++ b/src/test/kotlin/snyk/common/CustomEndpointsTest.kt @@ -119,7 +119,7 @@ class CustomEndpointsTest { @Test fun `isSnykAPI false for api subdomain and not snyk domain`() { - val uri = URI("https://api.NOTSNYK.io") + val uri = URI("https://api.notsnyk.io") assertFalse(uri.isSnykApi()) } @@ -171,7 +171,7 @@ class CustomEndpointsTest { @Test fun `isFedramp false for the right URI`() { - val uri = URI("https://app.fedddramp.snykgov.io") + val uri = URI("https://app.fedddramp.snykagov.io") assertFalse(uri.isFedramp()) } }