Skip to content

Commit

Permalink
Test configuring proxySelector doesn't fail when invalid env vars are…
Browse files Browse the repository at this point in the history
… present
  • Loading branch information
lauzadis committed Apr 12, 2024
1 parent 3c8ea58 commit f225ec1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import aws.smithy.kotlin.runtime.http.config.HttpEngineConfig
import aws.smithy.kotlin.runtime.http.engine.crt.CrtHttpEngine
import aws.smithy.kotlin.runtime.http.engine.crt.CrtHttpEngineConfig
import aws.smithy.kotlin.runtime.io.closeIfCloseable
import aws.smithy.kotlin.runtime.util.TestPlatformProvider
import org.junit.jupiter.api.Test
import kotlin.test.*

Expand Down Expand Up @@ -130,6 +131,21 @@ class HttpEngineConfigImplTest {
}
}
}

// reproduces https://github.com/awslabs/aws-sdk-kotlin/issues/1281
@Test
fun testCanConfigureProxySelectorWithInvalidEnvVarsPresent() {
val testPlatformProvider = TestPlatformProvider(env = mapOf("http_proxy" to "invalid", "https_proxy" to "invalid"))

val builder = HttpEngineConfigImpl.BuilderImpl()
builder.httpClient {
proxySelector = EnvironmentProxySelector(testPlatformProvider)
}

builder.httpClient {
proxySelector = ProxySelector.NoProxy
}
}
}

private fun config(block: HttpEngineConfig.Builder.() -> Unit): HttpEngineConfig =
Expand Down
7 changes: 7 additions & 0 deletions runtime/protocol/http-client/api/http-client.api
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ public final class aws/smithy/kotlin/runtime/http/engine/EngineAttributes {
public final fun getTimeToFirstByte ()Laws/smithy/kotlin/runtime/collections/AttributeKey;
}

public final class aws/smithy/kotlin/runtime/http/engine/EnvironmentProxySelector : aws/smithy/kotlin/runtime/http/engine/ProxySelector {
public fun <init> ()V
public fun <init> (Laws/smithy/kotlin/runtime/util/PlatformEnvironProvider;)V
public synthetic fun <init> (Laws/smithy/kotlin/runtime/util/PlatformEnvironProvider;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun select (Laws/smithy/kotlin/runtime/net/url/Url;)Laws/smithy/kotlin/runtime/http/engine/ProxyConfig;
}

public abstract interface class aws/smithy/kotlin/runtime/http/engine/HttpClientEngine : kotlinx/coroutines/CoroutineScope {
public abstract fun getConfig ()Laws/smithy/kotlin/runtime/http/engine/HttpClientEngineConfig;
public abstract fun roundTrip (Laws/smithy/kotlin/runtime/operation/ExecutionContext;Laws/smithy/kotlin/runtime/http/request/HttpRequest;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package aws.smithy.kotlin.runtime.http.engine

import aws.smithy.kotlin.runtime.ClientException
import aws.smithy.kotlin.runtime.InternalApi
import aws.smithy.kotlin.runtime.net.Host
import aws.smithy.kotlin.runtime.net.Scheme
import aws.smithy.kotlin.runtime.net.url.Url
Expand All @@ -29,7 +30,8 @@ import aws.smithy.kotlin.runtime.util.PropertyProvider
* - `https_proxy`, `HTTPS_PROXY`
* - `no_proxy`, `NO_PROXY`
*/
internal class EnvironmentProxySelector(provider: PlatformEnvironProvider = PlatformProvider.System) : ProxySelector {
@InternalApi
public class EnvironmentProxySelector(provider: PlatformEnvironProvider = PlatformProvider.System) : ProxySelector {
private val httpProxy by lazy { resolveProxyByProperty(provider, Scheme.HTTP) ?: resolveProxyByEnvironment(provider, Scheme.HTTP) }
private val httpsProxy by lazy { resolveProxyByProperty(provider, Scheme.HTTPS) ?: resolveProxyByEnvironment(provider, Scheme.HTTPS) }
private val noProxyHosts by lazy { resolveNoProxyHosts(provider) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ class EnvironmentProxySelectorTest {
fun testSelectFailures() {
failCases.forEachIndexed { idx, failCase ->
val testProvider = TestPlatformEnvironmentProvider(failCase.env, failCase.props)
val selector = EnvironmentProxySelector(testProvider)
val exception = assertFailsWith<ClientException>("[idx=$idx] expected ClientException") {
val selector = EnvironmentProxySelector(testProvider)
selector.select(Url.parse("http://localhost:8000")) // call `select` because proxy selector resolves env vars lazily
}

Expand Down

0 comments on commit f225ec1

Please sign in to comment.