From 821d1c129f88e9847b28071c4efe8ef842eb0351 Mon Sep 17 00:00:00 2001 From: quininer Date: Tue, 1 Oct 2019 16:27:42 +0800 Subject: [PATCH] move badssl test --- src/test_0rtt.rs => tests/badssl.rs | 42 +++++++++++++++++++---------- tests/test.rs | 2 -- 2 files changed, 28 insertions(+), 16 deletions(-) rename src/test_0rtt.rs => tests/badssl.rs (53%) diff --git a/src/test_0rtt.rs b/tests/badssl.rs similarity index 53% rename from src/test_0rtt.rs rename to tests/badssl.rs index 898deef..74bd294 100644 --- a/src/test_0rtt.rs +++ b/tests/badssl.rs @@ -4,16 +4,16 @@ use std::net::ToSocketAddrs; use tokio::prelude::*; use tokio::net::TcpStream; use rustls::ClientConfig; -use crate::{ TlsConnector, client::TlsStream }; +use tokio_rustls::{ TlsConnector, client::TlsStream }; -async fn get(config: Arc, domain: &str, rtt0: bool) +async fn get(config: Arc, domain: &str, port: u16) -> io::Result<(TlsStream, String)> { - let connector = TlsConnector::from(config).early_data(rtt0); + let connector = TlsConnector::from(config); let input = format!("GET / HTTP/1.0\r\nHost: {}\r\n\r\n", domain); - let addr = (domain, 443) + let addr = (domain, port) .to_socket_addrs()? .next().unwrap(); let domain = webpki::DNSNameRef::try_from_ascii_str(&domain).unwrap(); @@ -29,20 +29,34 @@ async fn get(config: Arc, domain: &str, rtt0: bool) } #[tokio::test] -async fn test_0rtt() -> io::Result<()> { +async fn test_tls12() -> io::Result<()> { let mut config = ClientConfig::new(); config.root_store.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS); - config.enable_early_data = true; + config.versions = vec![rustls::ProtocolVersion::TLSv1_2]; let config = Arc::new(config); - let domain = "mozilla-modern.badssl.com"; + let domain = "tls-v1-2.badssl.com"; - let (_, output) = get(config.clone(), domain, false).await?; - assert!(output.contains("mozilla-modern.badssl.com")); - - let (io, output) = get(config.clone(), domain, true).await?; - assert!(output.contains("mozilla-modern.badssl.com")); - - assert_eq!(io.early_data.0, 0); + let (_, output) = get(config.clone(), domain, 1012).await?; + assert!(output.contains("tls-v1-2.badssl.com")); + + Ok(()) +} + +#[should_panic] +#[test] +fn test_tls13() { + unimplemented!("todo https://github.com/chromium/badssl.com/pull/373"); +} + +#[tokio::test] +async fn test_modern() -> io::Result<()> { + let mut config = ClientConfig::new(); + config.root_store.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS); + let config = Arc::new(config); + let domain = "mozilla-modern.badssl.com"; + + let (_, output) = get(config.clone(), domain, 443).await?; + assert!(output.contains("mozilla-modern.badssl.com")); Ok(()) } diff --git a/tests/test.rs b/tests/test.rs index 74918ca..6ebdee9 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -53,7 +53,6 @@ lazy_static!{ let n = stream.read(&mut buf).await?; stream.write(&buf[..n]).await?; stream.flush().await?; - let _ = stream.read(&mut buf).await?; Ok(()) as io::Result<()> }.unwrap_or_else(|err| eprintln!("server: {:?}", err)); @@ -91,7 +90,6 @@ async fn start_client(addr: SocketAddr, domain: &str, config: Arc) assert_eq!(buf, FILE); - stream.shutdown().await?; Ok(()) }