Skip to content

Instantly share code, notes, and snippets.

@mwallner
Created September 11, 2019 05:39
Show Gist options
  • Save mwallner/4136feb52e8dc30a503ce01d8a443411 to your computer and use it in GitHub Desktop.
Save mwallner/4136feb52e8dc30a503ce01d8a443411 to your computer and use it in GitHub Desktop.
$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