public async Task ValidateAsync_ReturnsFalse_WithInvalidCNCertificate() { var clientCertificateWithInvalidEuiPath = await BasicsStationNetworkServerTests.CreatePfxCertificateAsync(false, InvalidStationEui); try { using var cert = new X509Certificate2(clientCertificateWithInvalidEuiPath); using var chain = X509Chain.Create(); _ = this.stationConfigService.Setup(x => x.GetAllowedClientThumbprintsAsync(It.IsAny <StationEui>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(new[] { cert.Thumbprint })); var result = await this.clientCertValidatorSvc.ValidateAsync(cert, chain, System.Net.Security.SslPolicyErrors.None, default); Assert.False(result); Assert.Contains(this.logger.Invocations, i => i.Arguments.Any(a => a.ToString() !.Contains(InvalidStationEui, StringComparison.OrdinalIgnoreCase))); } finally { if (!string.IsNullOrEmpty(clientCertificateWithInvalidEuiPath)) { File.Delete(clientCertificateWithInvalidEuiPath); } } }
public async Task InitializeAsync() { this.clientCertificateWithEuiPath = await BasicsStationNetworkServerTests.CreatePfxCertificateAsync(false); }