move badssl test

This commit is contained in:
quininer 2019-10-01 16:27:42 +08:00
parent 86171d34a8
commit 821d1c129f
2 changed files with 28 additions and 16 deletions

View File

@ -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<ClientConfig>, domain: &str, rtt0: bool)
async fn get(config: Arc<ClientConfig>, domain: &str, port: u16)
-> io::Result<(TlsStream<TcpStream>, 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<ClientConfig>, 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("<title>mozilla-modern.badssl.com</title>"));
let (io, output) = get(config.clone(), domain, true).await?;
assert!(output.contains("<title>mozilla-modern.badssl.com</title>"));
assert_eq!(io.early_data.0, 0);
let (_, output) = get(config.clone(), domain, 1012).await?;
assert!(output.contains("<title>tls-v1-2.badssl.com</title>"));
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("<title>mozilla-modern.badssl.com</title>"));
Ok(())
}

View File

@ -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<ClientConfig>)
assert_eq!(buf, FILE);
stream.shutdown().await?;
Ok(())
}