Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix early-data test #132

Merged
merged 5 commits into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ jobs:
toolchain: ${{ matrix.rust }}

- name: Test
run: cargo test --all
run: |
cargo test --all
cargo test -p tokio-rustls --features early-data --test early-data

lints:
name: Lints
Expand Down
15 changes: 14 additions & 1 deletion tokio-rustls/tests/early-data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::pin::Pin;
use std::process::{Child, Command, Stdio};
use std::sync::Arc;
use std::task::{Context, Poll};
use std::thread;
use std::time::Duration;
use tokio::io::{split, AsyncRead, AsyncWriteExt, ReadBuf};
use tokio::net::TcpStream;
Expand All @@ -34,6 +35,7 @@ impl<T: AsyncRead + Unpin> Future for Read1<T> {
if buf.filled().is_empty() {
Poll::Ready(Ok(()))
} else {
cx.waker().wake_by_ref();
Poll::Pending
}
}
Expand All @@ -46,7 +48,7 @@ async fn send(
) -> io::Result<TlsStream<TcpStream>> {
let connector = TlsConnector::from(config).early_data(true);
let stream = TcpStream::connect(&addr).await?;
let domain = rustls::ServerName::try_from("testserver.com").unwrap();
let domain = rustls::ServerName::try_from("foobar.com").unwrap();

let stream = connector.connect(domain, stream).await?;
let (mut rd, mut wd) = split(stream);
Expand Down Expand Up @@ -140,6 +142,17 @@ async fn test_0rtt() -> io::Result<()> {
let config = Arc::new(config);
let addr = SocketAddr::from(([127, 0, 0, 1], 12354));

// workaround: write to openssl s_server standard input periodically, to
// get it unstuck on Windows
let stdin = handle.0.stdin.take().unwrap();
thread::spawn(move || {
let mut stdin = stdin;
loop {
thread::sleep(std::time::Duration::from_secs(5));
std::io::Write::write_all(&mut stdin, b"\n").unwrap();
}
});

let io = send(config.clone(), addr, b"hello").await?;
assert!(!io.get_ref().1.is_early_data_accepted());

Expand Down