@@ -84,9 +84,7 @@ def test_python_intro(self) -> None:
84
84
class ProfileTestCase (TestCaseMixin , TestCase ):
85
85
"""Main tests for the profile class."""
86
86
87
- def create_cert ( # type: ignore[override]
88
- self , prof : Profile , ca : CertificateAuthority , * args : Any , ** kwargs : Any
89
- ) -> Certificate :
87
+ def create_cert (self , prof : Profile , ca : CertificateAuthority , * args : Any , ** kwargs : Any ) -> Certificate :
90
88
"""Shortcut to create a cert with the given profile."""
91
89
cert = Certificate (ca = ca )
92
90
cert .update_certificate (prof .create_cert (ca , * args , ** kwargs ))
@@ -108,10 +106,7 @@ def test_create_cert_minimal(self) -> None:
108
106
add_issuer_alternative_name = False ,
109
107
)
110
108
self .assertEqual (pre .call_count , 1 )
111
- self .assertExtensions (
112
- cert ,
113
- [ca .get_authority_key_identifier_extension (), subject_alternative_name (dns (self .hostname ))],
114
- )
109
+ self .assertExtensions (cert , [ca .get_authority_key_identifier_extension ()])
115
110
116
111
@override_tmpcadir ()
117
112
def test_alternative_values (self ) -> None :
@@ -175,7 +170,6 @@ def test_overrides(self) -> None:
175
170
subject_key_identifier (cert ),
176
171
ca .get_authority_key_identifier_extension (),
177
172
basic_constraints (),
178
- subject_alternative_name (dns (self .hostname )),
179
173
],
180
174
expect_defaults = False ,
181
175
)
@@ -199,7 +193,6 @@ def test_overrides(self) -> None:
199
193
[
200
194
ca .get_authority_key_identifier_extension (),
201
195
basic_constraints (),
202
- subject_alternative_name (dns (self .hostname )),
203
196
],
204
197
)
205
198
@@ -215,78 +208,6 @@ def test_none_extension(self) -> None:
215
208
self .assertEqual (pre .call_count , 1 )
216
209
self .assertNotIn (ExtensionOID .OCSP_NO_CHECK , cert .x509_extensions )
217
210
218
- @override_tmpcadir ()
219
- def test_cn_in_san (self ) -> None :
220
- """Test writing the common name into the SAN."""
221
- ca = self .load_ca (name = "root" , parsed = CERT_DATA ["root" ]["pub" ]["parsed" ])
222
- csr = CERT_DATA ["child-cert" ]["csr" ]["parsed" ]
223
-
224
- prof = Profile ("example" , subject = False , add_issuer_alternative_name = False , cn_in_san = False )
225
- with self .mockSignal (pre_sign_cert ) as pre :
226
- cert = self .create_cert (prof , ca , csr , subject = self .subject )
227
- self .assertEqual (pre .call_count , 1 )
228
- self .assertEqual (cert .subject , self .subject )
229
- self .assertExtensions (cert , [ca .get_authority_key_identifier_extension ()])
230
-
231
- # Create the same cert, but pass cn_in_san=True to create_cert
232
- with self .mockSignal (pre_sign_cert ) as pre :
233
- cert = self .create_cert (prof , ca , csr , subject = self .subject , cn_in_san = True )
234
- self .assertEqual (pre .call_count , 1 )
235
- self .assertEqual (cert .subject , self .subject )
236
- self .assertExtensions (
237
- cert ,
238
- [ca .get_authority_key_identifier_extension (), subject_alternative_name (dns (self .hostname ))],
239
- )
240
-
241
- # test that cn_in_san=True with a SAN that already contains the CN does not lead to a duplicate
242
- with self .mockSignal (pre_sign_cert ) as pre :
243
- cert = self .create_cert (
244
- prof ,
245
- ca ,
246
- csr ,
247
- subject = self .subject ,
248
- cn_in_san = True ,
249
- extensions = [subject_alternative_name (dns (self .hostname ))],
250
- )
251
- self .assertEqual (pre .call_count , 1 )
252
- self .assertEqual (cert .subject , self .subject )
253
- self .assertExtensions (
254
- cert ,
255
- [ca .get_authority_key_identifier_extension (), subject_alternative_name (dns (self .hostname ))],
256
- )
257
-
258
- # test that cn_in_san=True with a SAN that does NOT yet contain the CN, so it's added
259
- with self .mockSignal (pre_sign_cert ) as pre :
260
- cert = self .create_cert (
261
- prof ,
262
- ca ,
263
- csr ,
264
- subject = self .subject ,
265
- cn_in_san = True ,
266
- extensions = [subject_alternative_name (dns (self .hostname + ".added" ))],
267
- )
268
- self .assertEqual (pre .call_count , 1 )
269
- self .assertEqual (cert .subject , self .subject )
270
- self .assertExtensions (
271
- cert ,
272
- [
273
- ca .get_authority_key_identifier_extension (),
274
- subject_alternative_name (dns (self .hostname + ".added" ), dns (self .hostname )),
275
- ],
276
- )
277
-
278
- # test that the first SAN is added as CN if we don't have A CN
279
- with self .mockSignal (pre_sign_cert ) as pre :
280
- cert = self .create_cert (
281
- prof , ca , csr , cn_in_san = True , extensions = [subject_alternative_name (dns (self .hostname ))]
282
- )
283
- self .assertEqual (pre .call_count , 1 )
284
- self .assertEqual (cert .subject , self .subject )
285
- self .assertExtensions (
286
- cert ,
287
- [ca .get_authority_key_identifier_extension (), subject_alternative_name (dns (self .hostname ))],
288
- )
289
-
290
211
@override_tmpcadir ()
291
212
def test_override_ski (self ) -> None :
292
213
"""Test overriding the subject key identifier."""
@@ -314,12 +235,7 @@ def test_override_ski(self) -> None:
314
235
self .assertEqual (pre .call_count , 1 )
315
236
self .assertExtensions (
316
237
cert ,
317
- [
318
- ca .get_authority_key_identifier_extension (),
319
- basic_constraints (),
320
- subject_alternative_name (dns (self .hostname )),
321
- ski ,
322
- ],
238
+ [ca .get_authority_key_identifier_extension (), basic_constraints (), ski ],
323
239
expect_defaults = False ,
324
240
)
325
241
@@ -357,7 +273,6 @@ def test_add_distribution_point_with_ca_crldp(self) -> None:
357
273
ca .get_authority_key_identifier_extension (),
358
274
basic_constraints (),
359
275
x509 .Extension (oid = ExtensionOID .SUBJECT_KEY_IDENTIFIER , critical = False , value = ski ),
360
- subject_alternative_name (dns (self .hostname )),
361
276
added_crldp ,
362
277
],
363
278
expect_defaults = False ,
@@ -422,7 +337,6 @@ def test_issuer_alternative_name_override(self) -> None:
422
337
ca .get_authority_key_identifier_extension (),
423
338
basic_constraints (),
424
339
x509 .Extension (oid = ExtensionOID .SUBJECT_KEY_IDENTIFIER , critical = False , value = ski ),
425
- subject_alternative_name (dns (self .hostname )),
426
340
issuer_alternative_name (added_ian_uri ),
427
341
],
428
342
expect_defaults = False ,
@@ -468,7 +382,6 @@ def test_merge_authority_information_access_existing_values(self) -> None:
468
382
ca .get_authority_key_identifier_extension (),
469
383
basic_constraints (),
470
384
x509 .Extension (oid = ExtensionOID .SUBJECT_KEY_IDENTIFIER , critical = False , value = ski ),
471
- subject_alternative_name (dns (self .hostname )),
472
385
authority_information_access (
473
386
ca_issuers = [cert_issuers , cert_issuers2 ],
474
387
ocsp = [cert_ocsp ],
@@ -496,12 +409,7 @@ def test_extension_as_cryptography(self) -> None:
496
409
self .assertEqual (pre .call_count , 1 )
497
410
self .assertExtensions (
498
411
cert ,
499
- [
500
- ca .get_authority_key_identifier_extension (),
501
- basic_constraints (),
502
- ocsp_no_check (),
503
- subject_alternative_name (dns (self .hostname )),
504
- ],
412
+ [ca .get_authority_key_identifier_extension (), basic_constraints (), ocsp_no_check ()],
505
413
)
506
414
507
415
@override_tmpcadir ()
@@ -643,22 +551,9 @@ def test_no_valid_cn_in_san(self) -> None:
643
551
san = subject_alternative_name (x509 .RegisteredID (ExtensionOID .OCSP_NO_CHECK ))
644
552
645
553
with self .mockSignal (pre_sign_cert ) as pre :
646
- self .create_cert (prof , ca , csr , cn_in_san = True , extensions = [san ])
554
+ self .create_cert (prof , ca , csr , extensions = [san ])
647
555
self .assertEqual (pre .call_count , 1 )
648
556
649
- @override_tmpcadir ()
650
- def test_unparsable_cn (self ) -> None :
651
- """Try creating a profile with an unparsable Common Name."""
652
- ca = self .load_ca (name = "root" , parsed = CERT_DATA ["root" ]["pub" ]["parsed" ])
653
- csr = CERT_DATA ["child-cert" ]["csr" ]["parsed" ]
654
- cname = "foo bar"
655
-
656
- prof = Profile ("example" , subject = x509 .Name ([x509 .NameAttribute (x509 .NameOID .COMMON_NAME , cname )]))
657
- msg = rf"^{ cname } : Could not parse CommonName as subjectAlternativeName\.$"
658
- with self .mockSignal (pre_sign_cert ) as pre , self .assertRaisesRegex (ValueError , msg ):
659
- self .create_cert (prof , ca , csr )
660
- self .assertEqual (pre .call_count , 0 )
661
-
662
557
def test_unknown_signature_hash_algorithm (self ) -> None :
663
558
"""Test passing an unknown hash algorithm."""
664
559
with self .assertRaisesRegex (ValueError , r"^foo: Unknown hash algorithm\.$" ):
0 commit comments