Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eventually fixing cleartext code #2488

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bazel/kotlin_test.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@build_bazel_rules_android//android:rules.bzl", "android_library")
load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_local_test")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_test")
load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_local_test")
load("//bazel:kotlin_lib.bzl", "native_lib_name")

def _internal_kt_test(name, srcs, deps = [], data = [], jvm_flags = [], repository = "", exec_properties = {}):
Expand All @@ -14,16 +15,19 @@ def _internal_kt_test(name, srcs, deps = [], data = [], jvm_flags = [], reposito
elif dep.startswith(repository + "//library/java/io/envoyproxy/envoymobile"):
dep_srcs.append(dep + "_srcs")

kt_jvm_test(
kt_android_local_test(
name = name,
test_class = "io.envoyproxy.envoymobile.bazel.EnvoyMobileTestSuite",
srcs = srcs + dep_srcs,
manifest = repository + "//bazel:test_manifest.xml",
deps = [
repository + "//bazel:envoy_mobile_test_suite",
"@maven//:org_assertj_assertj_core",
"@maven//:junit_junit",
"@maven//:org_mockito_mockito_inline",
"@maven//:org_mockito_mockito_core",
"@maven//:org_robolectric_robolectric",
"@robolectric//bazel:android-all",
] + deps,
data = data,
jvm_flags = jvm_flags,
Expand Down
2 changes: 1 addition & 1 deletion examples/kotlin/hello_world/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit
private const val REQUEST_HANDLER_THREAD_NAME = "hello_envoy_kt"
private const val REQUEST_AUTHORITY = "api.lyft.com"
private const val REQUEST_PATH = "/ping"
private const val REQUEST_SCHEME = "https"
private const val REQUEST_SCHEME = "http"
private val FILTERED_HEADERS = setOf(
"server",
"filter-demo",
Expand Down
14 changes: 14 additions & 0 deletions test/kotlin/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,17 @@ envoy_mobile_jni_kt_test(
"//library/kotlin/io/envoyproxy/envoymobile:envoy_interfaces_lib",
],
)

envoy_mobile_jni_kt_test(
name = "http_request_test",
srcs = [
"HTTPRequestTest.kt",
],
native_deps = [
"//library/common/jni:libjava_jni_lib.so",
"//library/common/jni:java_jni_lib.jnilib",
],
deps = [
"//library/kotlin/io/envoyproxy/envoymobile:envoy_interfaces_lib",
],
)
226 changes: 226 additions & 0 deletions test/kotlin/integration/HTTPRequestTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
package test.kotlin.integration

import io.envoyproxy.envoymobile.Custom
import io.envoyproxy.envoymobile.EngineBuilder
import io.envoyproxy.envoymobile.EnvoyError
import io.envoyproxy.envoymobile.FilterDataStatus
import io.envoyproxy.envoymobile.FilterHeadersStatus
import io.envoyproxy.envoymobile.FilterTrailersStatus
import io.envoyproxy.envoymobile.FinalStreamIntel
import io.envoyproxy.envoymobile.RequestHeadersBuilder
import io.envoyproxy.envoymobile.RequestMethod
import io.envoyproxy.envoymobile.ResponseFilter
import io.envoyproxy.envoymobile.ResponseHeaders
import io.envoyproxy.envoymobile.ResponseTrailers
import io.envoyproxy.envoymobile.StreamIntel
import io.envoyproxy.envoymobile.UpstreamHttpProtocol
import io.envoyproxy.envoymobile.engine.JniLibrary
import java.nio.ByteBuffer
import java.util.concurrent.CountDownLatch
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.fail
import org.junit.Test

import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

private val apiListenerType = "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.EnvoyMobileHttpConnectionManager"
private val assertionFilterType = "type.googleapis.com/envoymobile.extensions.filters.http.assertion.Assertion"
private val config =
"""
static_resources:
listeners:
- name: base_api_listener
address:
socket_address:
protocol: TCP
address: 0.0.0.0
port_value: 10000
api_listener:
api_listener:
"@type": $apiListenerType
config:
stat_prefix: hcm
route_config:
name: api_router
virtual_hosts:
- name: api
domains:
- "*"
routes:
- match:
prefix: "/"
direct_response:
status: 200
http_filters:
- name: envoy.filters.http.assertion
typed_config:
"@type": $assertionFilterType
match_config:
http_request_headers_match:
headers:
- name: ":authority"
exact_match: example.com
- name: envoy.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
"""

// private const val ehcmType =
// "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.EnvoyMobileHttpConnectionManager"
// private const val lefType =
// "type.googleapis.com/envoymobile.extensions.filters.http.local_error.LocalError"
// private const val pbfType = "type.googleapis.com/envoymobile.extensions.filters.http.platform_bridge.PlatformBridge"
// private const val filterName = "idle_timeout_validation_filter"
// private val remotePort = (10001..11000).random()
// private val config =
// """
// static_resources:
// listeners:
// - name: fake_remote_listener
// address:
// socket_address: { protocol: TCP, address: 127.0.0.1, port_value: $remotePort }
// filter_chains:
// - filters:
// - name: envoy.filters.network.http_connection_manager
// typed_config:
// "@type": $ehcmType
// stat_prefix: remote_hcm
// route_config:
// name: remote_route
// virtual_hosts:
// - name: remote_service
// domains: ["*"]
// routes:
// - match: { prefix: "/" }
// direct_response: { status: 200 }
// http_filters:
// - name: envoy.router
// typed_config:
// "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
// - name: base_api_listener
// address:
// socket_address: { protocol: TCP, address: 0.0.0.0, port_value: 10000 }
// api_listener:
// api_listener:
// "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.EnvoyMobileHttpConnectionManager
// config:
// route_config:
// name: api_router
// virtual_hosts:
// - name: api
// domains: ["*"]
// routes:
// - match: { prefix: "/" }
// route: { cluster: fake_remote }
// http_filters:
// - name: envoy.filters.http.local_error
// typed_config:
// "@type": $lefType
// - name: envoy.filters.http.platform_bridge
// typed_config:
// "@type": $pbfType
// platform_filter_name: $filterName
// - name: envoy.router
// typed_config:
// "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
// clusters:
// - name: fake_remote
// connect_timeout: 0.25s
// type: STATIC
// lb_policy: ROUND_ROBIN
// load_assignment:
// cluster_name: fake_remote
// endpoints:
// - lb_endpoints:
// - endpoint:
// address:
// socket_address: { address: 127.0.0.1, port_value: $remotePort }
// """

@RunWith(RobolectricTestRunner::class)
class HTTPRequestTest {

init {
JniLibrary.loadTestLibrary()
}

// private val filterExpectation = CountDownLatch(1)
val callbackExpectation = CountDownLatch(1)

class IdleTimeoutValidationFilter(
private val latch: CountDownLatch
) : ResponseFilter {
override fun onResponseHeaders(
headers: ResponseHeaders,
endStream: Boolean,
streamIntel: StreamIntel
): FilterHeadersStatus<ResponseHeaders> {
return FilterHeadersStatus.StopIteration()
}

override fun onResponseData(
body: ByteBuffer,
endStream: Boolean,
streamIntel: StreamIntel
): FilterDataStatus<ResponseHeaders> {
return FilterDataStatus.StopIterationNoBuffer()
}

override fun onResponseTrailers(
trailers: ResponseTrailers,
streamIntel: StreamIntel
): FilterTrailersStatus<ResponseHeaders, ResponseTrailers> {
return FilterTrailersStatus.StopIteration()
}

override fun onError(error: EnvoyError, finalStreamIntel: FinalStreamIntel) {
assertThat(error.errorCode).isEqualTo(4)
latch.countDown()
}
override fun onComplete(finalStreamIntel: FinalStreamIntel) {}

override fun onCancel(finalStreamIntel: FinalStreamIntel) {
fail<HTTPRequestTest>("Unexpected call to onCancel filter callback")
}
}

@Test
fun `stream idle timeout triggers onError callbacks`() {
val engine = EngineBuilder(Custom(config))
.setOnEngineRunning {}
.build()

val client = engine.streamClient()

val requestHeaders = RequestHeadersBuilder(
method = RequestMethod.GET,
scheme = "http",
authority = "example.com",
path = "/test"
)
.addUpstreamHttpProtocol(UpstreamHttpProtocol.HTTP2)
.build()

client.newStreamPrototype()
.setOnError { error, _ ->
assertThat(error.errorCode).isEqualTo(4)
callbackExpectation.countDown()
}
.setOnResponseHeaders { _, _, _ ->
callbackExpectation.countDown()
}
.start(Executors.newSingleThreadExecutor())
.sendHeaders(requestHeaders, true)

// filterExpectation.await(10, TimeUnit.SECONDS)
callbackExpectation.await(10, TimeUnit.SECONDS)

engine.terminate()

// assertThat(filterExpectation.count).isEqualTo(0)
assertThat(callbackExpectation.count).isEqualTo(0)
}
}