Allow selection of TLS library in Interop tests (#129)
This commit is contained in:
committed by
Lucio Franco
parent
23e7695800
commit
79996f7c93
@@ -3,6 +3,12 @@ name = "tonic-interop"
|
||||
version = "0.1.0"
|
||||
authors = ["Lucio Franco <[email protected]>"]
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
[features]
|
||||
default = ["tonic"]
|
||||
tls_openssl = ["tonic", "tonic/tls", "tonic/openssl"]
|
||||
tls_rustls = ["tonic", "tonic/tls", "tonic/rustls"]
|
||||
|
||||
[[bin]]
|
||||
name = "client"
|
||||
@@ -14,7 +20,7 @@ path = "src/bin/server.rs"
|
||||
|
||||
[dependencies]
|
||||
tokio = "=0.2.0-alpha.6"
|
||||
tonic = { path = "../tonic", features = ["rustls"] }
|
||||
tonic = { path = "../tonic", optional = true }
|
||||
prost = "0.5"
|
||||
prost-derive = "0.5"
|
||||
bytes = "0.4"
|
||||
|
||||
@@ -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?;
|
||||
|
||||
@@ -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| {
|
||||
|
||||
+17
-7
@@ -3,18 +3,28 @@
|
||||
set -eu
|
||||
set -o pipefail
|
||||
|
||||
set -x
|
||||
|
||||
echo "Running for OS: ${OSTYPE}"
|
||||
|
||||
case "$OSTYPE" in
|
||||
darwin*) OS="darwin"; EXT="" ;;
|
||||
linux*) OS="linux"; EXT="" ;;
|
||||
msys*) OS="windows"; EXT=".exe" ;;
|
||||
msys*) OS="windows"; EXT=".exe" ;;
|
||||
*) exit 2 ;;
|
||||
esac
|
||||
|
||||
cargo build -p tonic-interop --bins
|
||||
|
||||
ARG="${1:-""}"
|
||||
TLS_PROVIDER="${2:-""}"
|
||||
|
||||
if [[ -n "${TLS_PROVIDER}" ]] ; then
|
||||
FEATURES="--features ${TLS_PROVIDER}"
|
||||
else
|
||||
FEATURES=
|
||||
fi
|
||||
|
||||
(cd tonic-interop && cargo build --bins ${FEATURES})
|
||||
|
||||
SERVER="tonic-interop/bin/server_${OS}_amd64${EXT}"
|
||||
|
||||
# TLS_CA="tonic-interop/data/ca.pem"
|
||||
@@ -22,7 +32,7 @@ TLS_CRT="tonic-interop/data/server1.pem"
|
||||
TLS_KEY="tonic-interop/data/server1.key"
|
||||
|
||||
# run the test server
|
||||
./"${SERVER}" $ARG --tls_cert_file $TLS_CRT --tls_key_file $TLS_KEY &
|
||||
./"${SERVER}" ${ARG} --tls_cert_file $TLS_CRT --tls_key_file $TLS_KEY &
|
||||
SERVER_PID=$!
|
||||
echo ":; started grpc-go test server."
|
||||
|
||||
@@ -35,12 +45,12 @@ sleep 1
|
||||
./target/debug/client \
|
||||
--test_case=empty_unary,large_unary,client_streaming,server_streaming,ping_pong,\
|
||||
empty_stream,status_code_and_message,special_status_message,unimplemented_method,\
|
||||
unimplemented_service,custom_metadata $ARG
|
||||
unimplemented_service,custom_metadata ${ARG}
|
||||
|
||||
echo ":; killing test server"; kill ${SERVER_PID};
|
||||
|
||||
# run the test server
|
||||
./target/debug/server $ARG &
|
||||
./target/debug/server ${ARG} &
|
||||
SERVER_PID=$!
|
||||
echo ":; started tonic test server."
|
||||
|
||||
@@ -53,4 +63,4 @@ sleep 1
|
||||
./target/debug/client \
|
||||
--test_case=empty_unary,large_unary,client_streaming,server_streaming,ping_pong,\
|
||||
empty_stream,status_code_and_message,special_status_message,unimplemented_method,\
|
||||
unimplemented_service,custom_metadata $ARG
|
||||
unimplemented_service,custom_metadata ${ARG}
|
||||
|
||||
Reference in New Issue
Block a user