Skip to content

Commit

Permalink
fix: respect prefix/suffix wildcards in nonProxyHosts (#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianbotsf authored May 16, 2024
1 parent 14ae580 commit 04774f5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .changes/cbfc3f67-c8b3-49ad-8e06-0e9bdece01e9.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "cbfc3f67-c8b3-49ad-8e06-0e9bdece01e9",
"type": "bugfix",
"description": "Respect `*` wildcard in `http.nonProxyHosts` when used as prefix or suffix",
"issues": [
"smithy-lang/smithy-kotlin#1092"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ internal data class NonProxyHost(val hostMatch: String, val port: Int? = null) {

val name = url.host.toString()

// handle start/end wildcard cases
if (hostMatch.endsWith("*")) return name.startsWith(hostMatch.removeSuffix("*"))
if (hostMatch.startsWith("*")) return name.endsWith(hostMatch.removePrefix("*"))

if (hostMatch.length > name.length) return false

val match = name.endsWith(hostMatch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class EnvironmentProxySelectorTest {
"https.proxyPort" to "80",
)
private val httpProxyProps = mapOf("http.proxyHost" to "test.proxy.aws")
private val wildcardPrefixNonProxyProps = mapOf("http.nonProxyHosts" to "*amazon.com")
private val wildcardSuffixNonProxyProps = mapOf("http.nonProxyHosts" to "amazon.co*")

private val expectedProxyConfig = ProxyConfig.Http(Url.parse("http://test.proxy.aws"))

Expand All @@ -58,6 +60,20 @@ class EnvironmentProxySelectorTest {
TestCase(ProxyConfig.Direct, props = mapOf("http.nonProxyHosts" to "aws.amazon.com") + httpsProxyProps),
TestCase(ProxyConfig.Direct, props = mapOf("http.nonProxyHosts" to ".amazon.com") + httpsProxyProps),

// no proxy w/ wildcards

TestCase(ProxyConfig.Direct, "https://aws.amazon.com", props = wildcardPrefixNonProxyProps + httpsProxyProps),
TestCase(ProxyConfig.Direct, "https://blamazon.com", props = wildcardPrefixNonProxyProps + httpsProxyProps),
TestCase(ProxyConfig.Direct, "https://amazon.com", props = wildcardPrefixNonProxyProps + httpsProxyProps),
TestCase(expectedProxyConfig, "https://aws.com", props = wildcardPrefixNonProxyProps + httpsProxyProps),
TestCase(expectedProxyConfig, "https://amazon.com.br", props = wildcardPrefixNonProxyProps + httpsProxyProps),

TestCase(ProxyConfig.Direct, "https://amazon.com", props = wildcardSuffixNonProxyProps + httpsProxyProps),
TestCase(ProxyConfig.Direct, "https://amazon.com.br", props = wildcardSuffixNonProxyProps + httpsProxyProps),
TestCase(ProxyConfig.Direct, "https://amazon.co.jp", props = wildcardSuffixNonProxyProps + httpsProxyProps),
TestCase(expectedProxyConfig, "https://aws.amazon.com", props = wildcardSuffixNonProxyProps + httpsProxyProps),
TestCase(expectedProxyConfig, "https://blamazon.com", props = wildcardSuffixNonProxyProps + httpsProxyProps),

// multiple no proxy hosts normalization
TestCase(ProxyConfig.Direct, env = mapOf("no_proxy" to "example.com,.amazon.com") + httpsProxyEnv),
TestCase(ProxyConfig.Direct, props = mapOf("http.noProxyHosts" to "example.com|.amazon.com") + httpsProxyProps),
Expand Down

0 comments on commit 04774f5

Please sign in to comment.