1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2025-04-12 21:04:05 +00:00

test server with rust-tls

This commit is contained in:
Marat Safin 2019-07-27 14:19:30 +03:00
parent 753c1f646c
commit bbcd7a22d5
2 changed files with 35 additions and 5 deletions

View file

@ -28,6 +28,7 @@ default = []
# openssl
ssl = ["openssl", "actix-server/ssl", "awc/ssl"]
rust-tls = ["rustls", "webpki", "actix-server/rust-tls", "awc/rust-tls"]
[dependencies]
actix-codec = "0.1.2"
@ -53,7 +54,5 @@ time = "0.1"
tokio-tcp = "0.1"
tokio-timer = "0.2"
openssl = { version="0.10", optional = true }
[dev-dependencies]
actix-web = "1.0.0"
actix-http = "0.2.4"
rustls = { version = "0.15.2", optional = true, features = ["dangerous_configuration"] }
webpki = { version = "0.19", optional = true }

View file

@ -67,6 +67,21 @@ where
R: IntoFuture,
{
RT.with(move |rt| rt.borrow_mut().get_mut().block_on(lazy(f)))
} pub struct NoCertificateVerification {}
#[cfg(feature = "rust-tls")]
mod danger {
pub struct NoCertificateVerification {}
impl rustls::ServerCertVerifier for NoCertificateVerification {
fn verify_server_cert(&self,
_roots: &rustls::RootCertStore,
_presented_certs: &[rustls::Certificate],
_dns_name: webpki::DNSNameRef<'_>,
_ocsp: &[u8]) -> Result<rustls::ServerCertVerified, rustls::TLSError> {
Ok(rustls::ServerCertVerified::assertion())
}
}
}
/// The `TestServer` type.
@ -151,7 +166,23 @@ impl TestServer {
.ssl(builder.build())
.finish()
}
#[cfg(not(feature = "ssl"))]
#[cfg(feature = "rust-tls")]
{
use rustls::ClientConfig;
use std::sync::Arc;
let mut config = ClientConfig::new();
let protos = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
config.set_protocols(&protos);
config.dangerous().set_certificate_verifier(Arc::new(danger::NoCertificateVerification{}));
Connector::new()
.conn_lifetime(time::Duration::from_secs(0))
.timeout(time::Duration::from_millis(500))
.ssl(Arc::new(config))
.finish()
}
#[cfg(not(any(feature = "ssl", feature = "rust-tls")))]
{
Connector::new()
.conn_lifetime(time::Duration::from_secs(0))