Skip to content

Commit de8b2ec

Browse files
committed
tests: simplify expect_cert_dns_names
1 parent f5ace6d commit de8b2ec

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

tests/integration.rs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ fn list_netflix_names() {
262262

263263
expect_cert_dns_names(
264264
ee,
265-
&[
265+
[
266266
"account.netflix.com",
267267
"ca.netflix.com",
268268
"netflix.ca",
@@ -288,7 +288,7 @@ fn invalid_subject_alt_names() {
288288

289289
expect_cert_dns_names(
290290
data,
291-
&[
291+
[
292292
"account.netflix.com",
293293
"ca.netflix.com",
294294
"netflix.ca",
@@ -314,7 +314,7 @@ fn wildcard_subject_alternative_names() {
314314

315315
expect_cert_dns_names(
316316
data,
317-
&[
317+
[
318318
"account.netflix.com",
319319
"*.netflix.com",
320320
"netflix.ca",
@@ -332,28 +332,15 @@ fn wildcard_subject_alternative_names() {
332332
}
333333

334334
#[cfg(feature = "alloc")]
335-
fn expect_cert_dns_names(cert_der: &[u8], expected_names: &[&str]) {
336-
use std::collections::HashSet;
337-
335+
fn expect_cert_dns_names<'name>(
336+
cert_der: &[u8],
337+
expected_names: impl IntoIterator<Item = &'name str>,
338+
) {
338339
let der = CertificateDer::from(cert_der);
339340
let cert = webpki::EndEntityCert::try_from(&der)
340341
.expect("should parse end entity certificate correctly");
341342

342-
let expected_names: HashSet<_> = expected_names.iter().cloned().collect();
343-
344-
let mut actual_names = cert
345-
.dns_names()
346-
.expect("should get all DNS names correctly for end entity cert")
347-
.collect::<Vec<_>>();
348-
349-
// Ensure that converting the list to a set doesn't throw away
350-
// any duplicates that aren't supposed to be there
351-
assert_eq!(actual_names.len(), expected_names.len());
352-
353-
let actual_names: std::collections::HashSet<&str> =
354-
actual_names.drain(..).map(|name| name.into()).collect();
355-
356-
assert_eq!(actual_names, expected_names);
343+
assert!(cert.dns_names().unwrap().eq(expected_names))
357344
}
358345

359346
#[cfg(feature = "alloc")]

0 commit comments

Comments
 (0)