Skip to content

Commit

Permalink
test with sslcontext (#205)
Browse files Browse the repository at this point in the history
update tests
  • Loading branch information
pjfanning authored Dec 27, 2023
1 parent 7f02848 commit 14a11e2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
Expand All @@ -41,21 +41,29 @@ 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

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)
Expand Down

0 comments on commit 14a11e2

Please sign in to comment.