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

test with sslcontext #205

Merged
merged 1 commit into from
Dec 27, 2023
Merged
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
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)(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better with a trait
SslContextProvider, and the false can be expressed by returning None.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is test code. And the SSL context is created inside this class. Not outside.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we have a use case for creating the SSL context outside - we can change then. Seems bad to overengineer test code

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