Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: custom endpoint validation and default [IDE-131] #524

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ticket mentions that we should not use app.snyk.io/api but nothing about snyk.io/api. This is a legacy way of calling APIs, as far as I know, which works today with api.snyk.io too. I think we could improve the validation some more so snyk.io/api is not allowed but it's not something we were asked to do and I don't know for sure that this wouldn't break something else so I'd rather leave it out

|| (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
Loading