[tests] Tests first, fix round 2: same caddy.json reload rereads certificates, forward-auth hosts kept under Caddy as under edge, crash mid-trial under Caddy, Caddy reloaded during the watch, watching crash point, caddy-revert after a crash, TLS 1.2 device after a bad ALPN (red)
This commit is contained in:
@@ -264,4 +264,76 @@ mod unix {
|
||||
tokio::time::sleep(std::time::Duration::from_millis(250)).await;
|
||||
}
|
||||
}
|
||||
|
||||
/// QC r2: end to end through Pingora (2 worker threads, pre-TLS hook): a handshake that
|
||||
/// fails after the resolver (bad ALPN) must not break the next TLS 1.2 device handshake.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn qc_tls12_device_after_bad_alpn_handshakes_end_to_end() {
|
||||
use std::sync::Arc;
|
||||
let echo = Echo::start("app").await;
|
||||
let p = pki();
|
||||
let (phone, phone_pem) = device(&p, "phone");
|
||||
let edge = setup(&echo, &p, &[&phone_pem]).await;
|
||||
let roots = edge.roots();
|
||||
let req = Req::get("locked.test", "/");
|
||||
let mut failures = Vec::new();
|
||||
let mut poisoned = 0;
|
||||
for i in 0..40 {
|
||||
let addr = edge.https;
|
||||
let r2 = roots.clone();
|
||||
let failed = tokio::task::spawn_blocking(move || {
|
||||
let provider = Arc::new(rustls::crypto::ring::default_provider());
|
||||
let mut cfg = rustls::ClientConfig::builder_with_provider(provider)
|
||||
.with_safe_default_protocol_versions()
|
||||
.unwrap()
|
||||
.with_root_certificates(r2)
|
||||
.with_no_client_auth();
|
||||
cfg.alpn_protocols = vec![b"foo".to_vec()];
|
||||
let mut conn = rustls::ClientConnection::new(
|
||||
Arc::new(cfg),
|
||||
rustls_pki_types::ServerName::try_from("open.test".to_owned()).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
let mut sock = std::net::TcpStream::connect(addr).unwrap();
|
||||
sock.set_read_timeout(Some(std::time::Duration::from_secs(5)))
|
||||
.unwrap();
|
||||
let mut r = Ok((0, 0));
|
||||
for _ in 0..5 {
|
||||
r = conn.complete_io(&mut sock);
|
||||
if r.is_err() || !conn.is_handshaking() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
r.is_err()
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
if failed {
|
||||
poisoned += 1;
|
||||
}
|
||||
match client::https_with_cert(
|
||||
edge.https,
|
||||
"locked.test",
|
||||
roots.clone(),
|
||||
&tls12(&phone),
|
||||
&req,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(r) if r.status == 200 => {}
|
||||
other => failures.push(format!("{i}: {other:?}")),
|
||||
}
|
||||
}
|
||||
eprintln!(
|
||||
"QC poison handshakes that failed: {poisoned}/40; device failures: {}",
|
||||
failures.len()
|
||||
);
|
||||
assert_eq!(poisoned, 40, "the poison handshake must fail");
|
||||
assert!(
|
||||
failures.is_empty(),
|
||||
"{} of 40 TLS 1.2 device handshakes failed: {:?}",
|
||||
failures.len(),
|
||||
failures.first()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user