Skip to content

Commit

Permalink
fix: custom endpoint validation and default
Browse files Browse the repository at this point in the history
  • Loading branch information
teodora-sandu committed May 1, 2024
1 parent 95d9210 commit 672388c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
### Added
- Improved theming in the Code Issue Panel by applying IntelliJ theme colors dynamically to JCEF components. This ensures consistency of UI elements with the rest of the IDE.

### Fixed
- Don't add /v1 to all API calls through the Language Server
- Default to using the correct API for the custom endpoint.

## [2.7.17]
### Fixed
- Fixed problem in re-enablement of scan types when only one scan type was selected
- Don't add /v1 to all API calls through the Language Server

### Added
- Use https://api.XXX.snyk.io/v1 and https://api.XXX.snykgov.io/v1 as endpoint URLs
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/snyk/common/CustomEndpoints.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ internal fun resolveCustomEndpoint(endpointUrl: String?): String {

fun URI.isSnykTenant() =
isSnykDomain()
&& ((host.lowercase().startsWith("app.") && path.lowercase().endsWith("/api"))
|| (host.lowercase() == "snyk.io" && path.lowercase().endsWith("/api"))
&& ((host.lowercase() == "snyk.io" && path.lowercase().endsWith("/api"))
|| (host.lowercase().startsWith("api.") && !path.lowercase().endsWith("/api"))
|| isDev())

Expand Down Expand Up @@ -134,7 +133,7 @@ fun URI.isOauth() = isSnykGov()
fun URI.isDev() = isSnykDomain() && host.lowercase().startsWith("dev.")

fun URI.isAnalyticsPermitted() = host != null &&
(host.lowercase() == "app.snyk.io" || host.lowercase() == "app.us.snyk.io" || host.lowercase() == "snyk.io")
(host.lowercase() == "api.snyk.io" || host.lowercase() == "api.us.snyk.io" || host.lowercase() == "snyk.io")

fun isAnalyticsPermitted(): Boolean {
val settings = pluginSettings()
Expand Down
14 changes: 7 additions & 7 deletions src/test/kotlin/snyk/common/CustomEndpointsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ class CustomEndpointsTest {
@Test
fun `isAnalyticsPermitted false for URIs not allowed`() {
val uris = listOf(
"https://app.fedramp.snykgov.io",
"https://app.eu.snyk.io/api",
"https://app.au.snyk.io/api"
"https://api.fedramp.snykgov.io",
"https://api.eu.snyk.io",
"https://api.au.snyk.io"
)
uris.forEach { uri ->
assertFalse(URI(uri).isAnalyticsPermitted())
Expand All @@ -221,10 +221,10 @@ class CustomEndpointsTest {
fun `isAnalyticsPermitted true for the right URIs`() {
val uris = listOf(
"https://snyk.io/api",
"https://app.snyk.io",
"https://app.us.snyk.io",
"https://app.snyk.io/api",
"https://app.snyk.io/v1"
"https://api.snyk.io",
"https://api.us.snyk.io",
"https://api.snyk.io",
"https://api.snyk.io/v1"
)

uris.forEach { uri ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SentryErrorReporterTest {
val settings = mockPluginInformation()
setUnitTesting(false)
settings.crashReportingEnabled = true
settings.customEndpointUrl = "https://app.snyk.io"
settings.customEndpointUrl = "https://api.snyk.io"

SentryErrorReporter.captureException(RuntimeException("test"))

Expand Down

0 comments on commit 672388c

Please sign in to comment.