Skip to content

Commit

Permalink
Merge pull request #621 from snyk/fix/IDE-663_Jetbrains-plugin-versio…
Browse files Browse the repository at this point in the history
…n-2.9.0-does-not-respect-proxy-settings

fix: respect no-proxy settings [IDE-663]
  • Loading branch information
bastiandoetsch authored Oct 9, 2024
2 parents 3ac2828 + 6d31548 commit f31902c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- if the language server listener is shut down, set initialized to false
- log error stream of language server to idea.log
- show error / warn messages if the project is null (e.g. for offline handling)
- add no_proxy environment variable, if proxy exceptions are defined

## [2.9.1]
### Fixed
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/snyk/common/EnvironmentHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ object EnvironmentHelper {
}
environment["http_proxy"] = "http://$authentication$proxyHost:${proxySettings.PROXY_PORT}"
environment["https_proxy"] = "http://$authentication$proxyHost:${proxySettings.PROXY_PORT}"
environment["no_proxy"] = proxySettings.PROXY_EXCEPTIONS
}
}

Expand Down
16 changes: 10 additions & 6 deletions src/test/kotlin/io/snyk/plugin/cli/ConsoleCommandRunnerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.snyk.plugin.cli

import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.openapi.components.service
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.progress.EmptyProgressIndicator
import com.intellij.openapi.progress.ProgressIndicator
Expand All @@ -14,20 +13,15 @@ import com.intellij.testFramework.LightPlatformTestCase
import com.intellij.util.net.HttpConfigurable
import io.mockk.every
import io.mockk.mockkObject
import io.mockk.mockkStatic
import io.mockk.unmockkAll
import io.mockk.verify
import io.sentry.protocol.SentryId
import io.snyk.plugin.DEFAULT_TIMEOUT_FOR_SCAN_WAITING_MS
import io.snyk.plugin.getCliFile
import io.snyk.plugin.getPluginPath
import io.snyk.plugin.isCliInstalled
import io.snyk.plugin.pluginSettings
import io.snyk.plugin.removeDummyCliFile
import io.snyk.plugin.resetSettings
import io.snyk.plugin.services.download.SnykCliDownloaderService
import io.snyk.plugin.setupDummyCliFile
import org.junit.Ignore
import snyk.PLUGIN_ID
import snyk.errorHandler.SentryErrorReporter
import java.net.URLEncoder
Expand Down Expand Up @@ -161,10 +155,12 @@ class ConsoleCommandRunnerTest : LightPlatformTestCase() {
val originalProxyHost = httpConfigurable.PROXY_HOST
val originalProxyPort = httpConfigurable.PROXY_PORT
val originalUseProxy = httpConfigurable.USE_HTTP_PROXY
val originalProxyExceptions = httpConfigurable.PROXY_EXCEPTIONS
try {
httpConfigurable.PROXY_PORT = 3128
httpConfigurable.PROXY_HOST = "testProxy"
httpConfigurable.USE_HTTP_PROXY = true
httpConfigurable.PROXY_EXCEPTIONS = "testExceptions"

val generalCommandLine = GeneralCommandLine("")
val expectedProxy = "http://testProxy:3128"
Expand All @@ -176,6 +172,7 @@ class ConsoleCommandRunnerTest : LightPlatformTestCase() {
httpConfigurable.USE_HTTP_PROXY = originalUseProxy
httpConfigurable.PROXY_HOST = originalProxyHost
httpConfigurable.PROXY_PORT = originalProxyPort
httpConfigurable.PROXY_EXCEPTIONS = originalProxyExceptions
}
}

Expand All @@ -187,13 +184,15 @@ class ConsoleCommandRunnerTest : LightPlatformTestCase() {
val originalProxyAuthentication = httpConfigurable.PROXY_AUTHENTICATION
val originalLogin = httpConfigurable.proxyLogin
val originalPassword = httpConfigurable.plainProxyPassword
val originalProxyExceptions = httpConfigurable.PROXY_EXCEPTIONS
try {
httpConfigurable.PROXY_PORT = 3128
httpConfigurable.PROXY_HOST = "testProxy"
httpConfigurable.USE_HTTP_PROXY = true
httpConfigurable.PROXY_AUTHENTICATION = true
httpConfigurable.proxyLogin = "testLogin"
httpConfigurable.plainProxyPassword = "test%!@Password"
httpConfigurable.PROXY_EXCEPTIONS = "testExceptions"
val encodedLogin = URLEncoder.encode(httpConfigurable.proxyLogin, "UTF-8")
val encodedPassword = URLEncoder.encode(httpConfigurable.plainProxyPassword, "UTF-8")

Expand All @@ -212,6 +211,7 @@ class ConsoleCommandRunnerTest : LightPlatformTestCase() {
httpConfigurable.PROXY_AUTHENTICATION = originalProxyAuthentication
httpConfigurable.proxyLogin = originalLogin
httpConfigurable.plainProxyPassword = originalPassword
httpConfigurable.PROXY_EXCEPTIONS = originalProxyExceptions
}
}

Expand All @@ -224,12 +224,14 @@ class ConsoleCommandRunnerTest : LightPlatformTestCase() {
val originalAuthenticationCancelled = httpConfigurable.AUTHENTICATION_CANCELLED
val originalLogin = httpConfigurable.proxyLogin
val originalPassword = httpConfigurable.plainProxyPassword
val originalProxyExceptions = httpConfigurable.PROXY_EXCEPTIONS
try {
httpConfigurable.PROXY_PORT = 3128
httpConfigurable.PROXY_HOST = "testProxy"
httpConfigurable.USE_HTTP_PROXY = true
httpConfigurable.PROXY_AUTHENTICATION = true
httpConfigurable.AUTHENTICATION_CANCELLED = true
httpConfigurable.PROXY_EXCEPTIONS = "testExceptions"

val generalCommandLine = GeneralCommandLine("")
val expectedProxy =
Expand All @@ -238,6 +240,7 @@ class ConsoleCommandRunnerTest : LightPlatformTestCase() {
ConsoleCommandRunner().setupCliEnvironmentVariables(generalCommandLine, "")

assertEquals(expectedProxy, generalCommandLine.environment["https_proxy"])
assertEquals(httpConfigurable.PROXY_EXCEPTIONS, generalCommandLine.environment["no_proxy"])
} finally {
httpConfigurable.USE_HTTP_PROXY = originalUseProxy
httpConfigurable.PROXY_HOST = originalProxyHost
Expand All @@ -246,6 +249,7 @@ class ConsoleCommandRunnerTest : LightPlatformTestCase() {
httpConfigurable.AUTHENTICATION_CANCELLED = originalAuthenticationCancelled
httpConfigurable.proxyLogin = originalLogin
httpConfigurable.plainProxyPassword = originalPassword
httpConfigurable.PROXY_EXCEPTIONS = originalProxyExceptions
}
}

Expand Down

0 comments on commit f31902c

Please sign in to comment.