@@ -104,3 +104,114 @@ fn read_root_with_neg_serial() {
104104#[ cfg( feature = "std" ) ]
105105#[ test]
106106fn time_constructor ( ) { let _ = webpki:: Time :: try_from ( std:: time:: SystemTime :: now ( ) ) . unwrap ( ) ; }
107+
108+ #[ cfg( feature = "std" ) ]
109+ #[ test]
110+ pub fn list_netflix_names ( )
111+ {
112+ let ee = include_bytes ! ( "netflix/ee.der" ) ;
113+
114+ expect_cert_dns_names ( ee, & [
115+ "account.netflix.com" ,
116+ "ca.netflix.com" ,
117+ "netflix.ca" ,
118+ "netflix.com" ,
119+ "signup.netflix.com" ,
120+ "www.netflix.ca" ,
121+ "www1.netflix.com" ,
122+ "www2.netflix.com" ,
123+ "www3.netflix.com" ,
124+ "develop-stage.netflix.com" ,
125+ "release-stage.netflix.com" ,
126+ "www.netflix.com" ,
127+ ] ) ;
128+ }
129+
130+ #[ cfg( feature = "std" ) ]
131+ #[ test]
132+ pub fn invalid_subject_alt_names ( )
133+ {
134+ // same as netflix ee certificate, but with the last name in the list
135+ // changed to 'www.netflix:com'
136+ let data = include_bytes ! ( "misc/invalid_subject_alternative_name.der" ) ;
137+
138+ expect_cert_dns_names ( data, & [
139+ "account.netflix.com" ,
140+ "ca.netflix.com" ,
141+ "netflix.ca" ,
142+ "netflix.com" ,
143+ "signup.netflix.com" ,
144+ "www.netflix.ca" ,
145+ "www1.netflix.com" ,
146+ "www2.netflix.com" ,
147+ "www3.netflix.com" ,
148+ "develop-stage.netflix.com" ,
149+ "release-stage.netflix.com" ,
150+ // NOT 'www.netflix:com'
151+ ] ) ;
152+ }
153+
154+ #[ cfg( feature = "std" ) ]
155+ #[ test]
156+ pub fn wildcard_subject_alternative_names ( )
157+ {
158+ // same as netflix ee certificate, but with the last name in the list
159+ // changed to 'ww*.netflix:com'
160+ let data = include_bytes ! ( "misc/dns_names_and_wildcards.der" ) ;
161+
162+ expect_cert_dns_names ( data, & [
163+ "account.netflix.com" ,
164+ // NOT "c*.netflix.com",
165+ "netflix.ca" ,
166+ "netflix.com" ,
167+ "signup.netflix.com" ,
168+ "www.netflix.ca" ,
169+ "www1.netflix.com" ,
170+ "www2.netflix.com" ,
171+ "www3.netflix.com" ,
172+ "develop-stage.netflix.com" ,
173+ "release-stage.netflix.com" ,
174+ "www.netflix.com"
175+ ] ) ;
176+ }
177+
178+ #[ cfg( feature = "std" ) ]
179+ fn expect_cert_dns_names ( data : & [ u8 ] , expected_names : & [ & str ] )
180+ {
181+ use std:: iter:: FromIterator ;
182+
183+ let input = untrusted:: Input :: from ( data) ;
184+ let cert = webpki:: EndEntityCert :: from ( input)
185+ . expect ( "should parse end entity certificate correctly" ) ;
186+
187+ let expected_names =
188+ std:: collections:: HashSet :: from_iter ( expected_names. iter ( ) . cloned ( ) ) ;
189+
190+ let mut actual_names = cert. dns_names ( )
191+ . expect ( "should get all DNS names correctly for end entity cert" ) ;
192+
193+ // Ensure that converting the list to a set doesn't throw away
194+ // any duplicates that aren't supposed to be there
195+ assert_eq ! ( actual_names. len( ) , expected_names. len( ) ) ;
196+
197+ let actual_names: std:: collections:: HashSet < & str > = actual_names. drain ( ..) . map ( |name| {
198+ name. into ( )
199+ } ) . collect ( ) ;
200+
201+ assert_eq ! ( actual_names, expected_names) ;
202+ }
203+
204+ #[ cfg( feature = "std" ) ]
205+ #[ test]
206+ pub fn no_subject_alt_names ( )
207+ {
208+ let data = include_bytes ! ( "misc/no_subject_alternative_name.der" ) ;
209+
210+ let input = untrusted:: Input :: from ( data) ;
211+ let cert = webpki:: EndEntityCert :: from ( input)
212+ . expect ( "should parse end entity certificate correctly" ) ;
213+
214+ let names = cert. dns_names ( ) . expect ( "we should get a result even without subjectAltNames" ) ;
215+
216+ assert ! ( names. is_empty( ) ) ;
217+ }
0 commit comments