summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Hannah <jhannah@bytemark.co.uk>2017-03-17 11:37:53 +0000
committerJames Hannah <jhannah@bytemark.co.uk>2017-03-17 11:37:53 +0000
commit88f78a494fd0081043b45af946b12a616e143d18 (patch)
tree5164efc588c15f313b1d8fc5d2ac77a7edb9d194
parent567d8b3c419a52ccc52f35f37338514c1d8fa623 (diff)
First stab at allowing custom SSL expiry daysssl-custom-expiry
-rw-r--r--lib/custodian/protocoltest/ssl.rb14
-rwxr-xr-xt/test-custodian-parser.rb24
2 files changed, 35 insertions, 3 deletions
diff --git a/lib/custodian/protocoltest/ssl.rb b/lib/custodian/protocoltest/ssl.rb
index c58a083..bf9cff5 100644
--- a/lib/custodian/protocoltest/ssl.rb
+++ b/lib/custodian/protocoltest/ssl.rb
@@ -25,13 +25,15 @@ class SSLCheck
#
# Takes one parameter -- the URL.
#
- def initialize(uri)
+ def initialize(uri, expiry_days = 14)
raise ArgumentError, 'URI must be a string' unless uri.is_a?(String)
@uri = URI.parse(uri)
@domain = @uri.host
@key = nil
+ @expiry_days = expiry_days
+
@certificate = nil
@certificate_store = nil
@@ -352,7 +354,7 @@ class SSLCheck
days_until_expiry = (self.certificate.not_after.to_i - Time.now.to_i) / (24.0 * 3600).floor.to_i
- if days_until_expiry > 14
+ if days_until_expiry > @expiry_days
verbose "The certificate for #{self.domain} is valid until #{self.certificate.not_after}."
return true
else
@@ -440,6 +442,12 @@ module Custodian
#
@line = line
+ if @line =~ /and cannot expire within (\d+) days/ then
+ @expiry_days = $1
+ else
+ @expiry_days = 14
+ end
+
#
# Save the host
#
@@ -499,7 +507,7 @@ module Custodian
return Custodian::TestResult::TEST_SKIPPED
end
- s = SSLCheck.new(@host)
+ s = SSLCheck.new(@host,@expiry_days)
result = s.verify
if true == result
diff --git a/t/test-custodian-parser.rb b/t/test-custodian-parser.rb
index cfecbb3..a6e075f 100755
--- a/t/test-custodian-parser.rb
+++ b/t/test-custodian-parser.rb
@@ -430,7 +430,31 @@ EOF
end
end
+ #
+ # HTTP/HTTPS tests might specify custom expiry
+ #
+ def test_https_custom_expiry
+
+ parser = Custodian::Parser.new
+
+ #
+ # A series of tests to parse
+ #
+ text = []
+ text.push('https://example.com/ must run https')
+ text.push('https://example.com/ must run https and cannot expire within 14 days')
+ text.push('https://example.com/ must run https and cannot expire within 45 days')
+ text.push('https://example.com/ must run https and cannot expire within 300 days')
+ #
+ # Test the parser with this text
+ #
+ text.each do |txt|
+ assert_raise ArgumentError do
+ parser.parse_lines(txt)
+ end
+ end
+ end
#