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
+34 -6
View File
@@ -29,7 +29,7 @@ jobs:
- name: Check fmt - name: Check fmt
run: cargo fmt -- --check run: cargo fmt -- --check
- name: Check features - name: Check features
run: cargo hack check --all --each-feature --no-dev-deps run: cargo hack check --all --ignore-private --each-feature --no-dev-deps
- name: Check all targets - name: Check all targets
run: cargo check --all --all-targets --all-features run: cargo check --all --all-targets --all-features
@@ -53,11 +53,12 @@ jobs:
- name: Run tests - name: Run tests
run: cargo test --all --all-features run: cargo test --all --all-features
interop: interop-unix:
name: Interop Tests (Rustls & OpenSSL)
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, macOS-latest, windows-latest] os: [ubuntu-latest, macOS-latest]
rust: [stable] rust: [stable]
env: env:
@@ -67,12 +68,39 @@ jobs:
- uses: hecrj/setup-rust-action@master - uses: hecrj/setup-rust-action@master
with: with:
rust-version: ${{ matrix.rust }} rust-version: ${{ matrix.rust }}
- uses: actions/checkout@master
- name: Install rustfmt - name: Install rustfmt
run: rustup component add rustfmt run: rustup component add rustfmt
- uses: actions/checkout@master
- name: Run interop tests - name: Run interop tests
run: ./tonic-interop/test.sh run: ./tonic-interop/test.sh
shell: bash shell: bash
- name: Run interop tests with tls - name: Run interop tests with Rustls
run: ./tonic-interop/test.sh --use_tls run: ./tonic-interop/test.sh --use_tls tls_rustls
shell: bash shell: bash
- name: Run interop tests with OpenSSL
run: ./tonic-interop/test.sh --use_tls tls_openssl
shell: bash
interop-windows:
name: Interop Tests (Rustls)
runs-on: windows-latest
strategy:
matrix:
rust: [stable]
env:
RUSTFLAGS: "-D warnings"
steps:
- uses: hecrj/setup-rust-action@master
with:
rust-version: ${{ matrix.rust }}
- name: Install rustfmt
run: rustup component add rustfmt
- uses: actions/checkout@master
- name: Run interop tests
run: ./tonic-interop/test.sh
shell: bash
- name: Run interop tests with Rustls
run: ./tonic-interop/test.sh --use_tls tls_rustls
shell: bash
+1
View File
@@ -3,6 +3,7 @@ name = "tonic-examples"
version = "0.1.0" version = "0.1.0"
authors = ["Lucio Franco <[email protected]>"] authors = ["Lucio Franco <[email protected]>"]
edition = "2018" edition = "2018"
publish = false
[[bin]] [[bin]]
name = "helloworld-server" name = "helloworld-server"
+7 -1
View File
@@ -3,6 +3,12 @@ name = "tonic-interop"
version = "0.1.0" version = "0.1.0"
authors = ["Lucio Franco <[email protected]>"] authors = ["Lucio Franco <[email protected]>"]
edition = "2018" edition = "2018"
publish = false
[features]
default = ["tonic"]
tls_openssl = ["tonic", "tonic/tls", "tonic/openssl"]
tls_rustls = ["tonic", "tonic/tls", "tonic/rustls"]
[[bin]] [[bin]]
name = "client" name = "client"
@@ -14,7 +20,7 @@ path = "src/bin/server.rs"
[dependencies] [dependencies]
tokio = "=0.2.0-alpha.6" tokio = "=0.2.0-alpha.6"
tonic = { path = "../tonic", features = ["rustls"] } tonic = { path = "../tonic", optional = true }
prost = "0.5" prost = "0.5"
prost-derive = "0.5" prost-derive = "0.5"
bytes = "0.4" bytes = "0.4"
+29 -8
View File
@@ -1,6 +1,8 @@
use std::time::Duration; use std::time::Duration;
use structopt::{clap::arg_enum, StructOpt}; 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; use tonic_interop::client;
#[derive(StructOpt)] #[derive(StructOpt)]
@@ -25,20 +27,39 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let test_cases = matches.test_case; let test_cases = matches.test_case;
#[allow(unused_mut)]
let mut endpoint = Endpoint::from_static("http://localhost:10000") let mut endpoint = Endpoint::from_static("http://localhost:10000")
.timeout(Duration::from_secs(5)) .timeout(Duration::from_secs(5))
.concurrency_limit(30) .concurrency_limit(30)
.clone(); .clone();
if matches.use_tls { if matches.use_tls {
let pem = tokio::fs::read("tonic-interop/data/ca.pem").await?; #[cfg(not(any(feature = "tls_rustls", feature = "tls_openssl")))]
let ca = Certificate::from_pem(pem); {
panic!("No TLS libary feature selected");
}
endpoint.tls_config( #[cfg(feature = "tls_rustls")]
ClientTlsConfig::with_rustls() {
.ca_certificate(ca) let pem = tokio::fs::read("tonic-interop/data/ca.pem").await?;
.domain_name("foo.test.google.fr"), 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?; let channel = endpoint.connect().await?;
+24 -5
View File
@@ -2,7 +2,9 @@ use http::header::HeaderName;
use structopt::StructOpt; use structopt::StructOpt;
use tonic::body::BoxBody; use tonic::body::BoxBody;
use tonic::client::GrpcService; 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}; use tonic_interop::{server, MergeTrailers};
#[derive(StructOpt)] #[derive(StructOpt)]
@@ -22,11 +24,28 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let mut builder = Server::builder(); let mut builder = Server::builder();
if matches.use_tls { if matches.use_tls {
let cert = tokio::fs::read("tonic-interop/data/server1.pem").await?; #[cfg(not(any(feature = "tls_rustls", feature = "tls_openssl")))]
let key = tokio::fs::read("tonic-interop/data/server1.key").await?; {
panic!("No TLS libary feature selected");
}
let identity = Identity::from_pem(cert, key); #[cfg(feature = "tls_rustls")]
builder.tls_config(ServerTlsConfig::with_rustls().identity(identity)); {
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| { builder.interceptor_fn(|svc, req| {
+17 -7
View File
@@ -3,18 +3,28 @@
set -eu set -eu
set -o pipefail set -o pipefail
set -x
echo "Running for OS: ${OSTYPE}" echo "Running for OS: ${OSTYPE}"
case "$OSTYPE" in case "$OSTYPE" in
darwin*) OS="darwin"; EXT="" ;; darwin*) OS="darwin"; EXT="" ;;
linux*) OS="linux"; EXT="" ;; linux*) OS="linux"; EXT="" ;;
msys*) OS="windows"; EXT=".exe" ;; msys*) OS="windows"; EXT=".exe" ;;
*) exit 2 ;; *) exit 2 ;;
esac esac
cargo build -p tonic-interop --bins
ARG="${1:-""}" 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}" SERVER="tonic-interop/bin/server_${OS}_amd64${EXT}"
# TLS_CA="tonic-interop/data/ca.pem" # 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" TLS_KEY="tonic-interop/data/server1.key"
# run the test server # 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=$! SERVER_PID=$!
echo ":; started grpc-go test server." echo ":; started grpc-go test server."
@@ -35,12 +45,12 @@ sleep 1
./target/debug/client \ ./target/debug/client \
--test_case=empty_unary,large_unary,client_streaming,server_streaming,ping_pong,\ --test_case=empty_unary,large_unary,client_streaming,server_streaming,ping_pong,\
empty_stream,status_code_and_message,special_status_message,unimplemented_method,\ 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}; echo ":; killing test server"; kill ${SERVER_PID};
# run the test server # run the test server
./target/debug/server $ARG & ./target/debug/server ${ARG} &
SERVER_PID=$! SERVER_PID=$!
echo ":; started tonic test server." echo ":; started tonic test server."
@@ -53,4 +63,4 @@ sleep 1
./target/debug/client \ ./target/debug/client \
--test_case=empty_unary,large_unary,client_streaming,server_streaming,ping_pong,\ --test_case=empty_unary,large_unary,client_streaming,server_streaming,ping_pong,\
empty_stream,status_code_and_message,special_status_message,unimplemented_method,\ empty_stream,status_code_and_message,special_status_message,unimplemented_method,\
unimplemented_service,custom_metadata $ARG unimplemented_service,custom_metadata ${ARG}