Use local server to test HTTPS instead of google.com
MODIFY
gradle/java.gradle
gradle/java.gradle
@@ -246,6 +246,14 @@ tasks.withType(Test).configureEach {
jvmArgs "-Dio.opentelemetry.context.enableStrictContext=${rootProject.findProperty('enableStrictContext') ?: false}"
// TODO(anuraaga): Have agent map unshaded to shaded.
jvmArgs "-Dio.opentelemetry.javaagent.shaded.io.opentelemetry.context.enableStrictContext=${rootProject.findProperty('enableStrictContext') ?: false}"
+
+ def trustStore = project(":testing-common").file("src/misc/testing-keystore.p12")
+ inputs.file(trustStore)
+ // Work around payara not working when this is set for some reason.
+ if (project.name != "jaxrs-2.0-payara-testing") {
+ jvmArgs "-Djavax.net.ssl.trustStore=${trustStore.absolutePath}"
+ jvmArgs "-Djavax.net.ssl.trustStorePassword=testing"
+ }
}
tasks.withType(AbstractArchiveTask).configureEach {

MODIFY
testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpClientTest.groovy
testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpClientTest.groovy
@@ -44,12 +44,14 @@ import io.opentelemetry.testing.armeria.server.ServerBuilder
import io.opentelemetry.testing.armeria.server.ServiceRequestContext
import io.opentelemetry.testing.armeria.server.logging.LoggingService
import io.opentelemetry.testing.armeria.testing.junit5.server.ServerExtension
+import java.security.KeyStore
import java.util.concurrent.CountDownLatch
import java.util.concurrent.ExecutionException
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import java.util.function.Supplier
+import javax.net.ssl.KeyManagerFactory
import spock.lang.Requires
import spock.lang.Shared
import spock.lang.Unroll
@@ -68,7 +70,14 @@ abstract class HttpClientTest<REQUEST> extends InstrumentationSpecification {
def server= new ServerExtension(false) {
@Override
protected void configure(ServerBuilder sb) throws Exception {
+ KeyStore keystore = KeyStore.getInstance("PKCS12")
+ keystore.load(new FileInputStream(new File(System.getProperty("javax.net.ssl.trustStore"))), "testing".toCharArray())
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm())
+ kmf.init(keystore, "testing".toCharArray())
+
sb.http(0)
+ .https(0)
+ .tls(kmf)
.service("/success") {ctx, req ->
ResponseHeadersBuilder headers = ResponseHeaders.builder(HttpStatus.OK)
def testRequestId = req.headers().get("test-request-id")
@@ -700,7 +709,7 @@ abstract class HttpClientTest<REQUEST> extends InstrumentationSpecification {
given:
assumeTrue(testRemoteConnection())
assumeTrue(testHttps())
- def uri = new URI("https://www.google.com/")
+ def uri = new URI("https://localhost:${server.httpsPort()}/success")
when:
def responseCode = doRequest(method, uri)
@@ -708,13 +717,14 @@ abstract class HttpClientTest<REQUEST> extends InstrumentationSpecification {
then:
responseCode == 200
assertTraces(1) {
- trace(0, 1) {
+ trace(0, 2) {
clientSpan(it, 0, null, method, uri)
+ serverSpan(it, 1, span(0))
}
}
where:
- method = "HEAD"
+ method = "GET"
}
/**

ADD
testing-common/src/misc/README.md
+testing-keystore.p12 generated with
+
+keytool -genkeypair -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore testing-keystore.p12 -validity 3650 -dname "CN=localhost" -ext "SAN=dns:localhost,ip:127.0.0.1"
+
+password = testing

ADD
testing-common/src/misc/testing-keystore.p12
testing-common/src/misc/testing-keystore.p12
Binary files /dev/null and b/testing-common/src/misc/testing-keystore.p12 differ

Use local server to test HTTPS instead of google.com (#3236)