Skip to content

Commit 0fb6a1a

Browse files
authored
Fix issue with competing SDK proxy configuration (#4291)
1 parent 4a27655 commit 0fb6a1a

File tree

5 files changed

+59
-3
lines changed

5 files changed

+59
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Fix issue with competing SDK proxy configuration (#4279)"
4+
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apache-commons-collections = "4.4"
33
apache-commons-io = "2.16.0"
44
assertJ = "3.20.2" # Upgrading leads to SAM errors: https://youtrack.jetbrains.com/issue/KT-17765
55
# match with <root>/settings.gradle.kts
6-
awsSdk = "2.21.33"
6+
awsSdk = "2.25.32"
77
commonmark = "0.17.1"
88
detekt = "1.23.6"
99
intellijGradle = "1.17.3"

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/AwsSdkClient.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ class AwsSdkClient : SdkClientProvider, Disposable {
2424
private val sdkHttpClient: SdkHttpClient by lazy {
2525
LOG.info { "Create new Apache client" }
2626
val httpClientBuilder = ApacheHttpClient.builder()
27-
.proxyConfiguration(ProxyConfiguration.builder().useSystemPropertyValues(false).build())
27+
.proxyConfiguration(
28+
ProxyConfiguration.builder()
29+
.useSystemPropertyValues(false)
30+
.useEnvironmentVariableValues(false)
31+
.build()
32+
)
2833
.httpRoutePlanner(SystemDefaultRoutePlanner(CommonProxy.getInstance()))
2934
.credentialsProvider(SystemDefaultCredentialsProvider())
3035
.tlsTrustManagersProvider { arrayOf(CertificateManager.getInstance().trustManager) }

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/credentials/ToolkitCredentialProcessProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class ToolkitCredentialProcessProvider @TestOnly constructor(
6969
} catch (e: Exception) {
7070
handleException(message("credentials.profile.credential_process.parse_exception_prefix"), output)
7171
}
72-
val credentials = when (val token = result.sessionToken) {
72+
val credentials: AwsCredentials = when (val token = result.sessionToken) {
7373
null -> AwsBasicCredentials.create(result.accessKeyId, result.secretAccessKey)
7474
else -> AwsSessionCredentials.create(result.accessKeyId, result.secretAccessKey, token)
7575
}

plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/AwsSdkClientTest.kt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import org.junit.Test
2020
import software.amazon.awssdk.http.HttpExecuteRequest
2121
import software.amazon.awssdk.http.SdkHttpFullRequest
2222
import software.amazon.awssdk.http.SdkHttpMethod
23+
import software.aws.toolkits.core.rules.EnvironmentVariableHelper
24+
import software.aws.toolkits.core.rules.SystemPropertyHelper
2325
import java.net.URI
2426

2527
class AwsSdkClientTest {
@@ -31,6 +33,14 @@ class AwsSdkClientTest {
3133
@JvmField
3234
val wireMock = createSelfSignedServer()
3335

36+
@Rule
37+
@JvmField
38+
val sysProps = SystemPropertyHelper()
39+
40+
@Rule
41+
@JvmField
42+
val environmentVariableHelper = EnvironmentVariableHelper()
43+
3444
@Before
3545
fun setUp() {
3646
stubFor(any(urlPathEqualTo("/")).willReturn(aResponse().withStatus(200)))
@@ -63,6 +73,43 @@ class AwsSdkClientTest {
6373
assertThat(trustManager.containsCertificate("selfsign")).isTrue()
6474
}
6575

76+
@Test
77+
fun systemPropertyProxyConfigurationIgnored() {
78+
System.setProperty("http.proxyHost", "foo.com")
79+
System.setProperty("http.proxyPort", Integer.toString(8888))
80+
81+
val request = mockSdkRequest("https://localhost:" + wireMock.httpsPort())
82+
83+
val awsSdkClient = AwsSdkClient()
84+
val response = try {
85+
awsSdkClient.sharedSdkClient().prepareRequest(
86+
HttpExecuteRequest.builder().request(request).build()
87+
).call()
88+
} finally {
89+
Disposer.dispose(awsSdkClient)
90+
}
91+
92+
assertThat(response.httpResponse().isSuccessful).isTrue()
93+
}
94+
95+
@Test
96+
fun environmentVariableProxyConfigurationIgnored() {
97+
environmentVariableHelper.set("HTTP_PROXY", "https://foo.com:8888")
98+
99+
val request = mockSdkRequest("https://localhost:" + wireMock.httpsPort())
100+
101+
val awsSdkClient = AwsSdkClient()
102+
val response = try {
103+
awsSdkClient.sharedSdkClient().prepareRequest(
104+
HttpExecuteRequest.builder().request(request).build()
105+
).call()
106+
} finally {
107+
Disposer.dispose(awsSdkClient)
108+
}
109+
110+
assertThat(response.httpResponse().isSuccessful).isTrue()
111+
}
112+
66113
private fun mockSdkRequest(uriString: String): SdkHttpFullRequest? {
67114
val uri = URI.create(uriString)
68115
return SdkHttpFullRequest.builder()

0 commit comments

Comments
 (0)