Skip to content

Commit a859ba3

Browse files
committed
Rename option name and add a test
1 parent b19bebd commit a859ba3

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

src/Shared/CertificateGeneration/CertificateManager.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,28 @@ public int AspNetHttpsCertificateVersion
5555
{
5656
get;
5757
// For testing purposes only
58-
internal set;
58+
internal set
59+
{
60+
ArgumentOutOfRangeException.ThrowIfLessThan(
61+
value,
62+
MinimumAspNetHttpsCertificateVersion,
63+
$"{nameof(AspNetHttpsCertificateVersion)} cannot be lesser than {nameof(MinimumAspNetHttpsCertificateVersion)}");
64+
field = value;
65+
}
5966
}
6067

6168
public int MinimumAspNetHttpsCertificateVersion
6269
{
6370
get;
6471
// For testing purposes only
65-
internal set;
72+
internal set
73+
{
74+
ArgumentOutOfRangeException.ThrowIfGreaterThan(
75+
value,
76+
AspNetHttpsCertificateVersion,
77+
$"{nameof(MinimumAspNetHttpsCertificateVersion)} cannot be greater than {nameof(AspNetHttpsCertificateVersion)}");
78+
field = value;
79+
}
6680
}
6781

6882
public string Subject { get; }

src/Tools/FirstRunCertGenerator/test/CertificateManagerTests.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
{

src/Tools/dotnet-dev-certs/src/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static int Main(string[] args)
114114
"Display warnings and errors only.",
115115
CommandOptionType.NoValue);
116116

117-
var checkJsonOutput = c.Option("--check-json-output",
117+
var checkJsonOutput = c.Option("--check-trust-machine-readable",
118118
"Same as running --check --trust, but output the results in json.",
119119
CommandOptionType.NoValue);
120120

0 commit comments

Comments
 (0)