Allow selection of TLS library in Interop tests (#129)

This commit is contained in:
James Nugent
2019-11-10 17:28:03 +01:00
committed by Lucio Franco
parent 23e7695800
commit 79996f7c93
6 changed files with 112 additions and 27 deletions
+29 -8
View File
@@ -1,6 +1,8 @@
use std::time::Duration;
use structopt::{clap::arg_enum, StructOpt};
use tonic::transport::{Certificate, ClientTlsConfig, Endpoint};
use tonic::transport::Endpoint;
#[cfg(any(feature = "tls_rustls", feature = "tls_openssl"))]
use tonic::transport::{Certificate, ClientTlsConfig};
use tonic_interop::client;
#[derive(StructOpt)]
@@ -25,20 +27,39 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let test_cases = matches.test_case;
#[allow(unused_mut)]
let mut endpoint = Endpoint::from_static("http://localhost:10000")
.timeout(Duration::from_secs(5))
.concurrency_limit(30)
.clone();
if matches.use_tls {
let pem = tokio::fs::read("tonic-interop/data/ca.pem").await?;
let ca = Certificate::from_pem(pem);
#[cfg(not(any(feature = "tls_rustls", feature = "tls_openssl")))]
{
panic!("No TLS libary feature selected");
}
endpoint.tls_config(
ClientTlsConfig::with_rustls()
.ca_certificate(ca)
.domain_name("foo.test.google.fr"),
);
#[cfg(feature = "tls_rustls")]
{
let pem = tokio::fs::read("tonic-interop/data/ca.pem").await?;
let ca = Certificate::from_pem(pem);
endpoint.tls_config(
ClientTlsConfig::with_rustls()
.ca_certificate(ca)
.domain_name("foo.test.google.fr"),
);
}
#[cfg(feature = "tls_openssl")]
{
let pem = tokio::fs::read("tonic-interop/data/ca.pem").await?;
let ca = Certificate::from_pem(pem);
endpoint.tls_config(
ClientTlsConfig::with_openssl()
.ca_certificate(ca)
.domain_name("foo.test.google.fr"),
);
}
}
let channel = endpoint.connect().await?;
+24 -5
View File
@@ -2,7 +2,9 @@ use http::header::HeaderName;
use structopt::StructOpt;
use tonic::body::BoxBody;
use tonic::client::GrpcService;
use tonic::transport::{Identity, Server, ServerTlsConfig};
use tonic::transport::Server;
#[cfg(any(feature = "tls_rustls", feature = "tls_openssl"))]
use tonic::transport::{Identity, ServerTlsConfig};
use tonic_interop::{server, MergeTrailers};
#[derive(StructOpt)]
@@ -22,11 +24,28 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let mut builder = Server::builder();
if matches.use_tls {
let cert = tokio::fs::read("tonic-interop/data/server1.pem").await?;
let key = tokio::fs::read("tonic-interop/data/server1.key").await?;
#[cfg(not(any(feature = "tls_rustls", feature = "tls_openssl")))]
{
panic!("No TLS libary feature selected");
}
let identity = Identity::from_pem(cert, key);
builder.tls_config(ServerTlsConfig::with_rustls().identity(identity));
#[cfg(feature = "tls_rustls")]
{
let cert = tokio::fs::read("tonic-interop/data/server1.pem").await?;
let key = tokio::fs::read("tonic-interop/data/server1.key").await?;
let identity = Identity::from_pem(cert, key);
builder.tls_config(ServerTlsConfig::with_rustls().identity(identity));
}
#[cfg(feature = "tls_openssl")]
{
let cert = tokio::fs::read("tonic-interop/data/server1.pem").await?;
let key = tokio::fs::read("tonic-interop/data/server1.key").await?;
let identity = Identity::from_pem(cert, key);
builder.tls_config(ServerTlsConfig::with_openssl().identity(identity));
}
}
builder.interceptor_fn(|svc, req| {