Created
September 11, 2019 05:39
-
-
Save mwallner/4136feb52e8dc30a503ce01d8a443411 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$script:_https_certs = @{} | |
function Add-HTTPSCertificateCheck { | |
param( | |
[string]$Url, | |
[TimeSpan]$ValidityTime | |
) | |
if ($script:_https_certs.Keys -contains $Url) { | |
throw "url '$Url' already added!" | |
} | |
$_https_certs[$Url] = @{ | |
Url = $Url | |
ValidityTime = $ValidityTime | |
} | |
} | |
Add-HTTPSCertificateCheck -Url "https://somesite:433" -ValidityTime $(New-TimeSpan -Days 30) | |
describe "sslchecks" { | |
foreach ($c in $script:_https_certs.Keys) { | |
it "check $c" { | |
$o = $_https_certs[$c] | |
$req = [Net.HttpWebRequest]::Create($o.Url) | |
$resp = $req.GetResponse() | |
$resp | Should -Not -BeNullOrEmpty | |
[datetime]$expiration = [System.DateTime]::Parse($req.ServicePoint.Certificate.GetExpirationDateString()) | |
$remainingTime = $expiration - (Get-Date) | |
$remainingTime | Should -BeGreaterThan $o.ValidityTime | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment