Commit b23411a9 authored by Łukasz Nowak's avatar Łukasz Nowak

promise: Support sites without certificate in check_surykatka_json

Sites with bad certificates are reported with null values in surykatka
output, thus they have to be handled correctly.
parent 4acb179f
...@@ -122,23 +122,26 @@ class RunPromise(GenericPromise): ...@@ -122,23 +122,26 @@ class RunPromise(GenericPromise):
return return
for entry in entry_list: for entry in entry_list:
timetuple = email.utils.parsedate(entry['not_after']) timetuple = email.utils.parsedate(entry['not_after'])
certificate_expiration_time = datetime.datetime.fromtimestamp( if timetuple is None:
time.mktime(timetuple)) appendError('No certificate information for %s' % (entry['ip']))
if certificate_expiration_time - datetime.timedelta(
days=certificate_expiration_days) < self.utcnow:
appendError(
'Certificate will expire on %s, which is less than %s days, '
'UTC now is %s',
entry['not_after'], certificate_expiration_days,
self.utcnow_string)
return
else: else:
self.appendInfoMessage( certificate_expiration_time = datetime.datetime.fromtimestamp(
'%s: OK Certificate will expire on %s, which is more than %s ' time.mktime(timetuple))
'days, UTC now is %s' % if certificate_expiration_time - datetime.timedelta(
(key, entry['not_after'], certificate_expiration_days, days=certificate_expiration_days) < self.utcnow:
self.utcnow_string)) appendError(
return 'Certificate on %s will expire on %s, which is less than %s days, '
'UTC now is %s',
entry['ip'], entry['not_after'], certificate_expiration_days,
self.utcnow_string)
return
else:
self.appendInfoMessage(
'%s: OK Certificate on %s will expire on %s, which is more than '
'%s days, UTC now is %s' %
(key, entry['ip'], entry['not_after'], certificate_expiration_days,
self.utcnow_string))
return
def senseHttpQuery(self): def senseHttpQuery(self):
key = 'http_query' key = 'http_query'
......
...@@ -260,9 +260,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -260,9 +260,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.assertPassedMessage( self.assertPassedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: OK status code 302 on IPs " "https://www.erp5.com/ : http_query: OK status code 302 on IPs "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate will expire on " "127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will "
"Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, UTC now " "expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, "
"is Fri, 27 Dec 2019 15:11:12 -0000" "UTC now is Fri, 27 Dec 2019 15:11:12 -0000"
) )
def test_maximum_elapsed_time(self): def test_maximum_elapsed_time(self):
...@@ -322,11 +322,12 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -322,11 +322,12 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.assertPassedMessage( self.assertPassedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: OK status code 302 on IPs " "https://www.erp5.com/ : http_query: OK status code 302 on IPs "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate will expire on " "127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will "
"Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, UTC now " "expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, "
"is Fri, 27 Dec 2019 15:11:12 -0000 elapsed_time: OK IP 127.0.0.1 " "UTC now is Fri, 27 Dec 2019 15:11:12 -0000 elapsed_time: OK IP "
"replied in 4.00s which is shorter than maximum 5.00s elapsed_time: OK " "127.0.0.1 replied in 4.00s which is shorter than maximum 5.00s "
"IP 127.0.0.2 replied in 4.00s which is shorter than maximum 5.00s" "elapsed_time: OK IP 127.0.0.2 replied in 4.00s which is shorter than "
"maximum 5.00s"
) )
def test_maximum_elapsed_time_too_long(self): def test_maximum_elapsed_time_too_long(self):
...@@ -389,9 +390,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -389,9 +390,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"https://www.erp5.com/ : elapsed_time: ERROR IP 127.0.0.1 replied in " "https://www.erp5.com/ : elapsed_time: ERROR IP 127.0.0.1 replied in "
"6.00s which is longer than maximum 5.00s elapsed_time: ERROR IP " "6.00s which is longer than maximum 5.00s elapsed_time: ERROR IP "
"127.0.0.2 failed to reply http_query: OK status code 302 on IPs " "127.0.0.2 failed to reply http_query: OK status code 302 on IPs "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate will expire on " "127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will "
"Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, UTC now " "expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, "
"is Fri, 27 Dec 2019 15:11:12 -0000" "UTC now is Fri, 27 Dec 2019 15:11:12 -0000"
) )
def test_maximum_elapsed_time_no_total_seconds(self): def test_maximum_elapsed_time_no_total_seconds(self):
...@@ -448,9 +449,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -448,9 +449,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.assertPassedMessage( self.assertPassedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: OK status code 302 on IPs " "https://www.erp5.com/ : http_query: OK status code 302 on IPs "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate will expire on " "127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will "
"Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, UTC now " "expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, "
"is Fri, 27 Dec 2019 15:11:12 -0000" "UTC now is Fri, 27 Dec 2019 15:11:12 -0000"
) )
def test_http(self): def test_http(self):
...@@ -549,9 +550,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -549,9 +550,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.assertPassedMessage( self.assertPassedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: OK with status code 302 " "https://www.erp5.com/ : http_query: OK with status code 302 "
"ssl_certificate: OK Certificate will expire on Mon, 13 Jul 2020 " "ssl_certificate: OK Certificate on 127.0.0.1 will expire on Mon, 13 "
"12:00:00 -0000, which is more than 15 days, UTC now is Fri, 27 Dec " "Jul 2020 12:00:00 -0000, which is more than 15 days, UTC now is Fri, "
"2019 15:11:12 -0000" "27 Dec 2019 15:11:12 -0000"
) )
def test_no_http_query_data(self): def test_no_http_query_data(self):
...@@ -590,9 +591,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -590,9 +591,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: ERROR No data elapsed_time: ERROR " "https://www.erp5.com/ : http_query: ERROR No data elapsed_time: ERROR "
"No data ssl_certificate: OK Certificate will expire on Mon, 13 Jul " "No data ssl_certificate: OK Certificate on 127.0.0.1 will expire on "
"2020 12:00:00 -0000, which is more than 15 days, UTC now is Fri, 27 " "Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, UTC now "
"Dec 2019 15:11:12 -0000" "is Fri, 27 Dec 2019 15:11:12 -0000"
) )
def test_no_ssl_certificate_data(self): def test_no_ssl_certificate_data(self):
...@@ -737,9 +738,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -737,9 +738,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code " "https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code "
"302 instead of 301 ssl_certificate: OK Certificate will expire on Mon, " "302 instead of 301 ssl_certificate: OK Certificate on 127.0.0.1 will "
"13 Jul 2020 12:00:00 -0000, which is more than 15 days, UTC now is " "expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, "
"Fri, 27 Dec 2019 15:11:12 -0000" "UTC now is Fri, 27 Dec 2019 15:11:12 -0000"
) )
def _test_bad_code_explanation(self, status_code, explanation): def _test_bad_code_explanation(self, status_code, explanation):
...@@ -783,9 +784,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -783,9 +784,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code " "https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code "
"%s instead of 301 ssl_certificate: OK Certificate will expire on Mon, " "%s instead of 301 ssl_certificate: OK Certificate on 127.0.0.1 will "
"13 Jul 2020 12:00:00 -0000, which is more than 15 days, UTC now is " "expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, "
"Fri, 27 Dec 2019 15:11:12 -0000" % (explanation,) "UTC now is Fri, 27 Dec 2019 15:11:12 -0000" % (explanation,)
) )
def test_bad_code_explanation_520(self): def test_bad_code_explanation_520(self):
...@@ -854,9 +855,10 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -854,9 +855,10 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: ERROR expected IPs 127.0.0.1 " "https://www.erp5.com/ : http_query: ERROR expected IPs 127.0.0.1 "
"127.0.0.2 differes from got 127.0.0.1 127.0.0.4 ssl_certificate: OK " "127.0.0.2 differes from got 127.0.0.1 127.0.0.4 ssl_certificate: "
"Certificate will expire on Mon, 13 Jul 2020 12:00:00 -0000, which is " "OK Certificate on 127.0.0.1 will expire on Mon, 13 Jul 2020 12:00:00 "
"more than 15 days, UTC now is Fri, 27 Dec 2019 15:11:12 -0000" "-0000, which is more than 15 days, UTC now is Fri, 27 Dec 2019 "
"15:11:12 -0000"
) )
def test_bad_ip_status_code(self): def test_bad_ip_status_code(self):
...@@ -915,6 +917,60 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -915,6 +917,60 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code " "https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code "
"302 instead of 301 http_query: ERROR expected IPs 127.0.0.1 127.0.0.2 " "302 instead of 301 http_query: ERROR expected IPs 127.0.0.1 127.0.0.2 "
"differes from got 127.0.0.1 127.0.0.4 ssl_certificate: OK Certificate " "differes from got 127.0.0.1 127.0.0.4 ssl_certificate: OK Certificate "
"will expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 " "on 127.0.0.1 will expire on Mon, 13 Jul 2020 12:00:00 -0000, which is "
"days, UTC now is Fri, 27 Dec 2019 15:11:12 -0000" "more than 15 days, UTC now is Fri, 27 Dec 2019 15:11:12 -0000"
)
def test_https_no_cert(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'status-code': '301',
'ip-list': '127.0.0.1 127.0.0.2',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
}
)
self.writeSurykatkaJson("""{
"http_query": [
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/"
},
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.4",
"status_code": 301,
"url": "https://www.erp5.com/"
}
],
"ssl_certificate": [
{
"date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": null
},
{
"date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": null
}
]
}
""")
self.configureLauncher()
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code "
"302 instead of 301 http_query: ERROR expected IPs 127.0.0.1 127.0.0.2 "
"differes from got 127.0.0.1 127.0.0.4 ssl_certificate: ERROR No "
"certificate information for 127.0.0.1 ssl_certificate: ERROR No "
"certificate information for 127.0.0.2"
) )
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment