@@ -387,6 +387,7 @@ public void EnsureCreateHttpsCertificate_ReturnsExpiredCertificateIfVersionIsInc
387387 Output . WriteLine ( creation . ToString ( ) ) ;
388388 ListCertificates ( ) ;
389389
390+ _manager . AspNetHttpsCertificateVersion = 2 ;
390391 _manager . MinimumAspNetHttpsCertificateVersion = 2 ;
391392
392393 var httpsCertificateList = _manager . ListCertificates ( StoreName . My , StoreLocation . CurrentUser , isValid : true ) ;
@@ -400,17 +401,39 @@ public void EnsureCreateHttpsCertificate_ReturnsExpiredCertificateForEmptyVersio
400401
401402 var now = DateTimeOffset . UtcNow ;
402403 now = new DateTimeOffset ( now . Year , now . Month , now . Day , now . Hour , now . Minute , now . Second , 0 , now . Offset ) ;
404+ _manager . MinimumAspNetHttpsCertificateVersion = 0 ;
403405 _manager . AspNetHttpsCertificateVersion = 0 ;
404406 var creation = _manager . EnsureAspNetCoreHttpsDevelopmentCertificate ( now , now . AddYears ( 1 ) , path : null , trust : false , isInteractive : false ) ;
405407 Output . WriteLine ( creation . ToString ( ) ) ;
406408 ListCertificates ( ) ;
407409
408410 _manager . AspNetHttpsCertificateVersion = 1 ;
411+ _manager . MinimumAspNetHttpsCertificateVersion = 1 ;
409412
410413 var httpsCertificateList = _manager . ListCertificates ( StoreName . My , StoreLocation . CurrentUser , isValid : true ) ;
411414 Assert . Empty ( httpsCertificateList ) ;
412415 }
413416
417+ [ Fact ]
418+ public void EnsureCreateHttpsCertificate_DoNotOverrideValidOldCertificate ( )
419+ {
420+ _fixture . CleanupCertificates ( ) ;
421+
422+ var now = DateTimeOffset . UtcNow ;
423+ now = new DateTimeOffset ( now . Year , now . Month , now . Day , now . Hour , now . Minute , now . Second , 0 , now . Offset ) ;
424+ var creation = _manager . EnsureAspNetCoreHttpsDevelopmentCertificate ( now , now . AddYears ( 1 ) , path : null , trust : false , isInteractive : false ) ;
425+ Output . WriteLine ( creation . ToString ( ) ) ;
426+ ListCertificates ( ) ;
427+
428+ // Simulate a tool with the same min version as the already existing cert but with a more
429+ // recent generation version
430+ _manager . MinimumAspNetHttpsCertificateVersion = 1 ;
431+ _manager . AspNetHttpsCertificateVersion = 2 ;
432+ var alreadyExist = _manager . EnsureAspNetCoreHttpsDevelopmentCertificate ( now , now . AddYears ( 1 ) , path : null , trust : false , isInteractive : false ) ;
433+ Output . WriteLine ( alreadyExist . ToString ( ) ) ;
434+ Assert . Equal ( EnsureCertificateResult . ValidCertificatePresent , alreadyExist ) ;
435+ }
436+
414437 [ ConditionalFact ]
415438 [ SkipOnHelix ( "https://github.com/dotnet/aspnetcore/issues/6720" , Queues = "All.OSX" ) ]
416439 public void EnsureCreateHttpsCertificate_ReturnsValidIfVersionIsZero ( )
@@ -441,7 +464,7 @@ public void EnsureCreateHttpsCertificate_ReturnValidIfCertIsNewer()
441464 Output . WriteLine ( creation . ToString ( ) ) ;
442465 ListCertificates ( ) ;
443466
444- _manager . AspNetHttpsCertificateVersion = 1 ;
467+ _manager . MinimumAspNetHttpsCertificateVersion = 1 ;
445468 var httpsCertificateList = _manager . ListCertificates ( StoreName . My , StoreLocation . CurrentUser , isValid : true ) ;
446469 Assert . NotEmpty ( httpsCertificateList ) ;
447470 }
@@ -533,8 +556,8 @@ public CertFixture()
533556
534557 internal void CleanupCertificates ( )
535558 {
536- Manager . AspNetHttpsCertificateVersion = 1 ;
537559 Manager . MinimumAspNetHttpsCertificateVersion = 1 ;
560+ Manager . AspNetHttpsCertificateVersion = 1 ;
538561 Manager . RemoveAllCertificates ( StoreName . My , StoreLocation . CurrentUser ) ;
539562 if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) || RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
540563 {
0 commit comments