forked from buehler/dotnet-operator-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): Add tests for certs and cert service
- Loading branch information
Showing
2 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
test/KubeOps.Operator.Web.Test/Certificates/CertificateGenerator.Test.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
using FluentAssertions; | ||
|
||
namespace KubeOps.Operator.Web.Test.Certificates | ||
{ | ||
public class CertificateGeneratorTest : IDisposable | ||
{ | ||
private readonly CertificateGenerator _certificateGenerator = new(Environment.MachineName); | ||
|
||
[Fact] | ||
public void Root_Should_Be_Valid() | ||
{ | ||
var (certificate, key) = _certificateGenerator.Root; | ||
|
||
certificate.Should().NotBeNull(); | ||
DateTime.Parse(certificate.GetEffectiveDateString()).Should().BeOnOrBefore(DateTime.UtcNow); | ||
certificate.Extensions.Any(e => e is X509BasicConstraintsExtension basic && basic.CertificateAuthority).Should().BeTrue(); | ||
certificate.HasPrivateKey.Should().BeTrue(); | ||
|
||
key.Should().NotBeNull(); | ||
} | ||
|
||
[Fact] | ||
public void Server_Should_Be_Valid() | ||
{ | ||
var (certificate, key) = _certificateGenerator.Server; | ||
|
||
certificate.Should().NotBeNull(); | ||
DateTime.Parse(certificate.GetEffectiveDateString()).Should().BeOnOrBefore(DateTime.UtcNow); | ||
certificate.Extensions.Any(e => e is X509BasicConstraintsExtension basic && basic.CertificateAuthority).Should().BeFalse(); | ||
certificate.HasPrivateKey.Should().BeFalse(); | ||
|
||
key.Should().NotBeNull(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_certificateGenerator.Dispose(); | ||
GC.SuppressFinalize(this); | ||
} | ||
} | ||
} |