Skip to content

Commit

Permalink
mobile: Make ProxyPollPerformHTTPRequestWithoutUsingPACProxyTest herm…
Browse files Browse the repository at this point in the history
…etic (#36428)

Risk Level: low (test only)
Testing: `bazel test
//test/kotlin/integration/proxying:proxy_poll_perform_http_request_without_using_pac_proxy`
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

Signed-off-by: Fredy Wijaya <[email protected]>
  • Loading branch information
fredyw authored Oct 3, 2024
1 parent dc35c85 commit 0089014
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
4 changes: 1 addition & 3 deletions mobile/test/kotlin/integration/proxying/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ envoy_mobile_android_test(
srcs = [
"ProxyPollPerformHTTPRequestWithoutUsingPACProxyTest.kt",
],
exec_properties = {
"dockerNetwork": "standard",
},
native_deps = [
"//test/jni:libenvoy_jni_with_test_and_listener_extensions.so",
] + select({
Expand All @@ -148,5 +145,6 @@ envoy_mobile_android_test(
"//library/kotlin/io/envoyproxy/envoymobile:envoy_lib",
"//test/java/io/envoyproxy/envoymobile/engine/testing",
"//test/java/io/envoyproxy/envoymobile/engine/testing:http_proxy_test_server_factory_lib",
"//test/java/io/envoyproxy/envoymobile/engine/testing:http_test_server_factory_lib",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.envoyproxy.envoymobile.RequestHeadersBuilder
import io.envoyproxy.envoymobile.RequestMethod
import io.envoyproxy.envoymobile.engine.JniLibrary
import io.envoyproxy.envoymobile.engine.testing.HttpProxyTestServerFactory
import io.envoyproxy.envoymobile.engine.testing.HttpTestServerFactory
import java.util.concurrent.CountDownLatch
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -42,16 +43,32 @@ class ProxyPollPerformHTTPRequestWithoutUsingPACProxyTest {
}

private lateinit var httpProxyTestServer: HttpProxyTestServerFactory.HttpProxyTestServer
private lateinit var httpTestServer: HttpTestServerFactory.HttpTestServer

@Before
fun setUp() {
httpProxyTestServer =
HttpProxyTestServerFactory.start(HttpProxyTestServerFactory.Type.HTTP_PROXY)
httpTestServer =
HttpTestServerFactory.start(
HttpTestServerFactory.Type.HTTP1_WITHOUT_TLS,
0,
// http://go/mdn/HTTP/Proxy_servers_and_tunneling/Proxy_Auto-Configuration_PAC_file
mapOf("Content-Type" to "application/x-ns-proxy-autoconfig"),
"""
function FindProxyForURL(url, host) {
return "PROXY ${httpProxyTestServer.ipAddress}:${httpProxyTestServer.port}";
}
"""
.trimIndent(),
mapOf()
)
}

@After
fun tearDown() {
httpProxyTestServer.shutdown()
httpTestServer.shutdown()
}

@Test
Expand All @@ -63,7 +80,7 @@ class ProxyPollPerformHTTPRequestWithoutUsingPACProxyTest {
Shadows.shadowOf(connectivityManager)
.setProxyForNetwork(
connectivityManager.activeNetwork,
ProxyInfo.buildPacProxy(Uri.parse("https://example.com"))
ProxyInfo.buildPacProxy(Uri.parse("http://${httpTestServer.address}"))
)

val onEngineRunningLatch = CountDownLatch(1)
Expand All @@ -85,8 +102,8 @@ class ProxyPollPerformHTTPRequestWithoutUsingPACProxyTest {
RequestHeadersBuilder(
method = RequestMethod.GET,
scheme = "http",
authority = "api.lyft.com",
path = "/ping"
authority = httpTestServer.address,
path = "/"
)
.build()

Expand All @@ -95,7 +112,7 @@ class ProxyPollPerformHTTPRequestWithoutUsingPACProxyTest {
.newStreamPrototype()
.setOnResponseHeaders { responseHeaders, _, _ ->
val status = responseHeaders.httpStatus ?: 0L
assertThat(status).isEqualTo(301)
assertThat(status).isEqualTo(200)
assertThat(responseHeaders.value("x-proxy-response")).isNull()
onResponseHeadersLatch.countDown()
}
Expand Down

0 comments on commit 0089014

Please sign in to comment.