Skip to content

Commit 1bb3068

Browse files
committed
tests: simplify expect_cert_dns_names
Now that the `GeneralDnsNameRef` type is exposed, offers constructor methods similar to `DnsNameRef` and `WildCardDnsNameRef`, and derives the `PartialEq` trait, we can greatly simplify the `expect_cert_dns_names` helper.
1 parent e3fcc0c commit 1bb3068

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

tests/integration.rs

Lines changed: 12 additions & 19 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,21 @@ 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;
335+
fn expect_cert_dns_names<'name>(
336+
cert_der: &[u8],
337+
expected_names: impl IntoIterator<Item = &'name str>,
338+
) {
339+
use webpki::GeneralDnsNameRef;
337340

338341
let der = CertificateDer::from(cert_der);
339342
let cert = webpki::EndEntityCert::try_from(&der)
340343
.expect("should parse end entity certificate correctly");
341344

342-
let expected_names: HashSet<_> = expected_names.iter().cloned().collect();
345+
let expected_names = expected_names
346+
.into_iter()
347+
.map(|name| GeneralDnsNameRef::try_from_ascii_str(name).unwrap());
343348

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);
349+
assert!(cert.dns_names().unwrap().eq(expected_names));
357350
}
358351

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

0 commit comments

Comments
 (0)