Skip to content

Commit b29994a

Browse files
committed
test(static-roots): return Result from store_static_roots()
1 parent 1f2c3aa commit b29994a

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

tests/suite/static_roots.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,19 @@ use webpki::{EndEntityCert, anchor_from_trusted_cert};
2222
use webpki_root_certs::TLS_SERVER_ROOT_CERTS;
2323

2424
#[tokio::test]
25-
async fn store_static_roots() {
25+
async fn store_static_roots() -> anyhow::Result<()> {
2626
let provider = Arc::new(aws_lc_rs::default_provider());
2727
let mut root_store = RootCertStore::empty();
2828
let mut roots = Vec::with_capacity(TLS_SERVER_ROOT_CERTS.len());
2929
for cert_der in TLS_SERVER_ROOT_CERTS {
30-
let ta = anchor_from_trusted_cert(cert_der).unwrap();
30+
let ta = anchor_from_trusted_cert(cert_der)?;
3131
roots.push((cert_der, ta.clone()));
3232
root_store.roots.push(ta);
3333
}
3434

3535
let root_store = Arc::new(root_store);
3636
let inner = WebPkiServerVerifier::builder_with_provider(root_store.clone(), provider.clone())
37-
.build()
38-
.unwrap();
37+
.build()?;
3938

4039
let verifier = Arc::new(TrackRootVerifier {
4140
root: Mutex::default(),
@@ -46,8 +45,7 @@ async fn store_static_roots() {
4645

4746
let config = Arc::new(
4847
rustls::ClientConfig::builder_with_provider(provider)
49-
.with_safe_default_protocol_versions()
50-
.unwrap()
48+
.with_safe_default_protocol_versions()?
5149
.dangerous()
5250
.with_custom_certificate_verifier(verifier.clone())
5351
.with_no_client_auth(),
@@ -60,11 +58,10 @@ async fn store_static_roots() {
6058
for &host in HOSTS {
6159
connector
6260
.connect(
63-
ServerName::try_from(host).unwrap(),
64-
TcpStream::connect((host, 443)).await.unwrap(),
61+
ServerName::try_from(host)?,
62+
TcpStream::connect((host, 443)).await?,
6563
)
66-
.await
67-
.unwrap();
64+
.await?;
6865

6966
let root = verifier.root.lock().unwrap().take().unwrap();
7067
let root_cert = roots
@@ -88,11 +85,13 @@ async fn store_static_roots() {
8885
}
8986
code.push_str("];\n");
9087

91-
let old = fs::read_to_string(PATH).unwrap();
88+
let old = fs::read_to_string(PATH)?;
9289
if old != code {
93-
fs::write(PATH, &code).unwrap();
90+
fs::write(PATH, &code)?;
9491
panic!("anchors.rs is outdated; updated it");
9592
}
93+
94+
Ok(())
9695
}
9796

9897
const PATH: &str = "src/anchors.rs";

0 commit comments

Comments
 (0)