This is an automated email from the ASF dual-hosted git repository.

fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-pekko-grpc.git


The following commit(s) were added to refs/heads/main by this push:
     new 14a11e22 test with sslcontext (#205)
14a11e22 is described below

commit 14a11e22869113541a1504d162a9712341173678
Author: PJ Fanning <[email protected]>
AuthorDate: Wed Dec 27 20:00:29 2023 +0100

    test with sslcontext (#205)
    
    update tests
---
 .../apache/pekko/grpc/interop/GrpcInteropSpec.scala  | 17 ++++++++++++-----
 .../grpc/interop/PekkoGrpcScalaClientTester.scala    | 20 ++++++++++++++------
 2 files changed, 26 insertions(+), 11 deletions(-)

diff --git 
a/interop-tests/src/test/scala/org/apache/pekko/grpc/interop/GrpcInteropSpec.scala
 
b/interop-tests/src/test/scala/org/apache/pekko/grpc/interop/GrpcInteropSpec.scala
index c056fba8..fedac976 100644
--- 
a/interop-tests/src/test/scala/org/apache/pekko/grpc/interop/GrpcInteropSpec.scala
+++ 
b/interop-tests/src/test/scala/org/apache/pekko/grpc/interop/GrpcInteropSpec.scala
@@ -17,9 +17,13 @@ import io.grpc.testing.integration.TestServiceHandlerFactory
 
 class GrpcInteropIoWithIoSpec extends GrpcInteropTests(Servers.IoGrpc, 
Clients.IoGrpc)
 class GrpcInteropIoWithPekkoNettyScalaSpec extends 
GrpcInteropTests(Servers.IoGrpc, Clients.PekkoNetty.Scala)
+class GrpcInteropIoWithPekkoNettyScalaWithSslContextSpec
+    extends GrpcInteropTests(Servers.IoGrpc, 
Clients.PekkoNetty.ScalaWithSslContext)
 class GrpcInteropIoWithPekkoNettyJavaSpec extends 
GrpcInteropTests(Servers.IoGrpc, Clients.PekkoNetty.Java)
 class GrpcInteropIoWithPekkkoHttpScalaSpec extends 
GrpcInteropTests(Servers.IoGrpc, Clients.PekkoHttp.Scala)
-//class GrpcInteropIoWithpekkoHttpJavaSpec extends 
GrpcInteropTests(Servers.IoGrpc, Clients.PekkoHttp.Java)
+class GrpcInteropIoWithPekkkoHttpScalaWithSslContextSpec
+    extends GrpcInteropTests(Servers.IoGrpc, 
Clients.PekkoHttp.ScalaWithSslContext)
+//class GrpcInteropIoWithPekkoHttpJavaSpec extends 
GrpcInteropTests(Servers.IoGrpc, Clients.PekkoHttp.Java)
 
 class GrpcInteropPekkoScalaWithIoSpec extends 
GrpcInteropTests(Servers.Pekko.Scala, Clients.IoGrpc)
 class GrpcInteropPekkoScalaWithPekkoNettyScalaSpec
@@ -48,12 +52,14 @@ object Clients {
   val IoGrpc = IoGrpcJavaClientProvider
   object PekkoNetty {
     val Java = PekkoNettyClientProviderJava$
-    val Scala = new PekkoClientProviderScala("netty")
+    val Scala = new PekkoClientProviderScala("netty", false)
+    val ScalaWithSslContext = new PekkoClientProviderScala("netty", true)
   }
   object PekkoHttp {
     // FIXME: let's have Scala stable and we'll do Java later.
     // val Java = PekkoHttpClientProviderJava
-    val Scala = new PekkoClientProviderScala("pekko-http")
+    val Scala = new PekkoClientProviderScala("pekko-http", false)
+    val ScalaWithSslContext = new PekkoClientProviderScala("pekko-http", true)
   }
 }
 
@@ -70,10 +76,11 @@ object PekkoHttpServerProviderJava$ extends 
PekkoHttpServerProvider {
   })
 }
 
-class PekkoClientProviderScala(backend: String) extends PekkoClientProvider {
+class PekkoClientProviderScala(backend: String, testWithSslContext: Boolean) 
extends PekkoClientProvider {
   val label: String = s"pekko-grpc scala client tester $backend"
 
-  def client = PekkoGrpcClientScala(settings => implicit sys => new 
PekkoGrpcScalaClientTester(settings, backend))
+  def client = PekkoGrpcClientScala(settings =>
+    implicit sys => new PekkoGrpcScalaClientTester(settings, backend, 
testWithSslContext))
 }
 
 object PekkoNettyClientProviderJava$ extends PekkoClientProvider {
diff --git 
a/interop-tests/src/test/scala/org/apache/pekko/grpc/interop/PekkoGrpcScalaClientTester.scala
 
b/interop-tests/src/test/scala/org/apache/pekko/grpc/interop/PekkoGrpcScalaClientTester.scala
index fb7d23ac..15ac6e32 100644
--- 
a/interop-tests/src/test/scala/org/apache/pekko/grpc/interop/PekkoGrpcScalaClientTester.scala
+++ 
b/interop-tests/src/test/scala/org/apache/pekko/grpc/interop/PekkoGrpcScalaClientTester.scala
@@ -13,8 +13,6 @@
 
 package org.apache.pekko.grpc.interop
 
-import java.io.InputStream
-
 import org.apache.pekko
 import pekko.actor.ActorSystem
 import pekko.grpc.{ GrpcClientSettings, GrpcResponseMetadata, SSLContextUtils }
@@ -29,6 +27,8 @@ import io.grpc.{ Status, StatusRuntimeException }
 import org.junit.Assert._
 import org.scalatest.matchers.should.Matchers._
 
+import java.io.InputStream
+import javax.net.ssl.SSLContext
 import scala.concurrent.duration._
 import scala.concurrent.{ Await, Future }
 import scala.util.control.NoStackTrace
@@ -41,8 +41,8 @@ import scala.util.control.NoStackTrace
  * The same implementation is also be found as part of the 'scripted' tests at
  * 
/sbt-plugin/src/sbt-test/gen-scala-server/00-interop/src/test/scala/org/apache/pekko/grpc/PekkoGrpcClientTester.scala
  */
-class PekkoGrpcScalaClientTester(val settings: Settings, backend: 
String)(implicit system: ActorSystem)
-    extends ClientTester {
+class PekkoGrpcScalaClientTester(val settings: Settings, backend: String, 
testWithSslContext: Boolean)(
+    implicit system: ActorSystem) extends ClientTester {
   private var client: TestServiceClient = null
   private var clientUnimplementedService: UnimplementedServiceClient = null
   private implicit val mat: Materializer = 
SystemMaterializer(system).materializer
@@ -50,12 +50,20 @@ class PekkoGrpcScalaClientTester(val settings: Settings, 
backend: String)(implic
   private val awaitTimeout = 15.seconds
 
   def setUp(): Unit = {
-    val grpcSettings = GrpcClientSettings
+    val trustManager = 
SSLContextUtils.trustManagerFromResource("/certs/ca.pem")
+    val baseGrpcSettings = GrpcClientSettings
       .connectToServiceAt(settings.serverHost, settings.serverPort)
       .withBackend(backend)
       .withOverrideAuthority(settings.serverHostOverride)
       .withTls(settings.useTls)
-      
.withTrustManager(SSLContextUtils.trustManagerFromResource("/certs/ca.pem"))
+
+    val grpcSettings = if (testWithSslContext) {
+      val sslContext = SSLContext.getInstance("TLS")
+      sslContext.init(null, Array(trustManager), null)
+      baseGrpcSettings.withSslContext(sslContext)
+    } else {
+      baseGrpcSettings.withTrustManager(trustManager)
+    }
 
     client = TestServiceClient(grpcSettings)
     clientUnimplementedService = UnimplementedServiceClient(grpcSettings)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to