From 9cd67dfcb2e58b5cdf6b324bdbd32c85ecba5193 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Thu, 20 Mar 2014 20:24:57 +0100 Subject: [PATCH] More SSL message work. --- linkcheck/plugins/sslcertcheck.py | 19 ++++++++++--------- tests/checker/test_https.py | 6 +++++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/linkcheck/plugins/sslcertcheck.py b/linkcheck/plugins/sslcertcheck.py index f2187acf..1853119a 100644 --- a/linkcheck/plugins/sslcertcheck.py +++ b/linkcheck/plugins/sslcertcheck.py @@ -84,17 +84,18 @@ class SslCertificateCheck(_ConnectionPlugin): # Calculate seconds until certifcate expires. Can be negative if # the certificate is already expired. secondsValid = notAfter - curTime + args = dict(expire=cert['notAfter']) if secondsValid < 0: - msg = _('SSL certficate is expired on %s') % cert['notAfter'] - url_data.add_warning(msg) - elif secondsValid < self.warn_ssl_cert_secs_valid: - strTimeValid = strformat.strduration_long(secondsValid) - msg = _('SSL certificate is only %s valid') % strTimeValid - url_data.add_warning(msg) + msg = _('SSL certficate is expired on %(expire)s.') + url_data.add_warning(msg % args) else: - strTimeValid = strformat.strduration_long(secondsValid) - msg = _('SSL certificate is %s valid') % strTimeValid - url_data.add_info(msg) + args['valid'] = strformat.strduration_long(secondsValid) + if secondsValid < self.warn_ssl_cert_secs_valid: + msg = _('SSL certificate expires on %(expire)s and is only %(valid)s valid.') + url_data.add_warning(msg % args) + else: + msg = _('SSL certificate expires on %(expire)s and is %(valid)s valid.') + url_data.add_info(msg % args) @classmethod def read_config(cls, configparser): diff --git a/tests/checker/test_https.py b/tests/checker/test_https.py index 9eaacb6b..818ee8eb 100644 --- a/tests/checker/test_https.py +++ b/tests/checker/test_https.py @@ -38,4 +38,8 @@ class TestHttps (LinkCheckTest): u"info Redirected to `%s'." % rurl, u"valid", ] - self.direct(url, resultlines, recursionlevel=0) + confargs = dict( + enabledplugins=['SslCertificateCheck'], + SslCertificateCheck=dict(sslcertwarndays=10), + ) + self.direct(url, resultlines, recursionlevel=0, confargs=confargs)