Created
March 3, 2020 21:31
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
[Fact] | |
public void IsSSLExpiring() | |
{ | |
var handler = new HttpClientHandler | |
{ | |
ServerCertificateCustomValidationCallback = CustomCallback | |
}; | |
var client = new HttpClient(handler); | |
HttpResponseMessage response = client.GetAsync("https://www.example.com").GetAwaiter().GetResult(); | |
Assert.True(response.IsSuccessStatusCode); | |
} | |
private bool CustomCallback(HttpRequestMessage arg1, X509Certificate2 arg2, X509Chain arg3, SslPolicyErrors arg4) | |
{ | |
var now = DateTime.UtcNow; | |
var expire = arg2.NotAfter; | |
var diff = (expire - now).TotalDays; | |
Assert.InRange(diff, 30, 1000); | |
return arg4 == SslPolicyErrors.None; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment