#![cfg(all(
feature = "http-json",
feature = "reqwest-rustls",
feature = "reqwest-client",
feature = "logs-otlp",
feature = "metrics",
feature = "traces"
))]
mod support;
use signal_kit::OtelShutdownFailure;
use support::{
emit_probe, otlp_json,
tls::{SelfSignedCertificate, install_empty_system_trust_anchor, serve_https},
};
#[tokio::test(flavor = "multi_thread")]
async fn https_transport_rejects_certificates_outside_the_system_trust_store() {
let certificate = SelfSignedCertificate::generate();
let (app, mut exports) = otlp_json::receiver();
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let address = listener.local_addr().unwrap();
let server = tokio::spawn(serve_https(app, listener, certificate.server_config()));
let trust_directory = tempfile::tempdir().unwrap();
install_empty_system_trust_anchor(trust_directory.path());
let guard = emit_probe(format!("https://{address}"), "http/json");
otlp_json::assert_still_queued(&mut exports).await;
let error = guard
.shutdown()
.expect_err("the system trust store must reject the self-signed certificate");
server.abort();
assert!(
error
.failures()
.iter()
.any(|failure| matches!(failure, OtelShutdownFailure::TracerProvider(_))),
"the tracer must refuse the untrusted endpoint: {error:?}"
);
}