diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 661fe2d..7bdb75b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,5 +21,7 @@ jobs: run: cargo check --all --all-features --all-targets - name: Run tests run: cargo test --all - - name: Run interop tests + - name: Run interop tests without tls run: ./tonic-interop/test.sh + - name: Run interop tests with tls + run: ./tonic-interop/test.sh --use_tls diff --git a/tonic-examples/src/helloworld/client.rs b/tonic-examples/src/helloworld/client.rs index 1200d47..097c7c4 100644 --- a/tonic-examples/src/helloworld/client.rs +++ b/tonic-examples/src/helloworld/client.rs @@ -7,10 +7,7 @@ pub mod hello_world { #[tokio::main] async fn main() -> Result<(), Box> { - let origin = vec![ - http::Uri::from_static("http://[::1]:50051").into(), - - ]; + let origin = vec![http::Uri::from_static("http://[::1]:50051").into()]; let svc = Channel::builder().balance_list(origin)?; diff --git a/tonic-interop/src/bin/client.rs b/tonic-interop/src/bin/client.rs index cfed23f..a11d4c0 100644 --- a/tonic-interop/src/bin/client.rs +++ b/tonic-interop/src/bin/client.rs @@ -1,5 +1,5 @@ use structopt::{clap::arg_enum, StructOpt}; -use tonic::transport::Channel; +use tonic::transport::{Channel, Endpoint}; use tonic_interop::client; #[derive(StructOpt)] @@ -11,6 +11,9 @@ struct Opts { raw(possible_values = r#"&Testcase::variants()"#) )] test_case: Vec, + + #[structopt(long)] + use_tls: bool } #[tokio::main] @@ -26,10 +29,15 @@ async fn main() -> Result<(), Box> { let addr = "localhost:10000"; let origin = http::Uri::from_shared(format!("http://{}", addr).into()).unwrap(); + let endpoint = if matches.use_tls { + let ca = tokio::fs::read("tonic-interop/data/ca.pem").await?; + Endpoint::with_pem(origin, ca, Some("foo.test.google.fr".into())) + } else { + Endpoint::from(origin) + }; + let channel = Channel::builder() - // .tls(ca) - // .tls_override_domain("foo.test.google.fr") - .build(origin)?; + .connect(endpoint)?; let mut client = client::TestClient::new(channel.clone()); let mut unimplemented_client = client::UnimplementedClient::new(channel); diff --git a/tonic-interop/test.sh b/tonic-interop/test.sh index 8f29c80..484a9ea 100755 --- a/tonic-interop/test.sh +++ b/tonic-interop/test.sh @@ -12,7 +12,7 @@ esac SERVER="tonic-interop/bin/server_${OS}_amd64" # run the test server -./"${SERVER}" & +./"${SERVER}" $1 & SERVER_PID=$! echo ":; started grpc-go test server." @@ -23,4 +23,4 @@ trap 'echo ":; killing test server"; kill ${SERVER_PID};' EXIT cargo run -p tonic-interop --bin 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 +unimplemented_service,custom_metadata $1 diff --git a/tonic/src/transport/channel.rs b/tonic/src/transport/channel.rs index e9a9b1b..ac42d2b 100644 --- a/tonic/src/transport/channel.rs +++ b/tonic/src/transport/channel.rs @@ -74,18 +74,6 @@ impl Builder { } } - #[cfg(any(feature = "openssl-1", feature = "rustls"))] - pub fn tls(&mut self, ca: Vec) -> &mut Self { - self.ca = Some(ca); - self - } - - #[cfg(any(feature = "openssl-1", feature = "rustls"))] - pub fn tls_override_domain>(&mut self, domain: D) -> &mut Self { - self.override_domain = Some(domain.as_ref().into()); - self - } - pub fn buffer(&mut self, size: usize) -> &mut Self { self.buffer_size = size; self @@ -110,6 +98,10 @@ impl Builder { Ok(Channel { svc }) } + pub fn connect(&mut self, endpoint: Endpoint) -> Result { + self.balance_list(vec![endpoint]) + } + pub fn build(&mut self, uri: T) -> Result where Uri: http::HttpTryFrom,