Commit 47ba7fec authored by Łukasz Nowak's avatar Łukasz Nowak

check_surykatka_json: Improve tests and adapt code

Improvements:
 * use real dict in the test
 * merge test cases
 * increase test coverage
 * minimize and improve messages
 * use error state instead of error list
 * always shall full diff during test failure to ease debugging
 * fix ssl_certificate missing information
 * avoid cluttering code with test time
parent efcc40ee
...@@ -27,34 +27,31 @@ class RunPromise(GenericPromise): ...@@ -27,34 +27,31 @@ class RunPromise(GenericPromise):
self.failure_amount = int( self.failure_amount = int(
self.getConfig('failure-amount', self.getConfig('failure_amount', 1))) self.getConfig('failure-amount', self.getConfig('failure_amount', 1)))
self.result_count = self.failure_amount self.result_count = self.failure_amount
self.error_list = [] self.error = False
self.info_list = [] self.message_list = []
# Make promise test-less, as it's result is not important for instantiation # Make promise test-less, as it's result is not important for instantiation
self.setTestLess() self.setTestLess()
def appendErrorMessage(self, message): def appendMessage(self, message):
self.error_list.append(message) self.message_list.append(message)
def appendInfoMessage(self, message):
self.info_list.append(message)
def emitLog(self): def emitLog(self):
if len(self.error_list) > 0: if self.error:
emit = self.logger.error emit = self.logger.error
else: else:
emit = self.logger.info emit = self.logger.info
message_list = self.error_list + self.info_list
url = self.getConfig('url') url = self.getConfig('url')
if url: if url:
message_list.insert(0, '%s :' % (url,)) self.message_list.insert(0, '%s :' % (url,))
emit(' '.join(message_list)) emit(' '.join(self.message_list))
def senseBotStatus(self): def senseBotStatus(self):
key = 'bot_status' key = 'bot_status'
def appendError(msg, *args): def appendError(msg, *args):
self.appendErrorMessage(key + ': ERROR ' + msg % args) self.error = True
self.appendMessage(key + ': ERROR ' + msg % args)
if key not in self.surykatka_json: if key not in self.surykatka_json:
appendError("%r not in %r", key, self.json_file) appendError("%r not in %r", key, self.json_file)
...@@ -80,13 +77,14 @@ class RunPromise(GenericPromise): ...@@ -80,13 +77,14 @@ class RunPromise(GenericPromise):
appendError('Last bot datetime is more than 15 minutes old') appendError('Last bot datetime is more than 15 minutes old')
return return
self.appendInfoMessage('%s: OK Last bot status' % (key,)) self.appendMessage('%s: OK Last bot status' % (key,))
def senseSslCertificate(self): def senseSslCertificate(self):
key = 'ssl_certificate' key = 'ssl_certificate'
def appendError(msg, *args): def appendError(msg, *args):
self.appendErrorMessage(key + ': ERROR ' + msg % args) self.error = True
self.appendMessage(key + ': ERROR ' + msg % args)
url = self.getConfig('url') url = self.getConfig('url')
parsed_url = urlparse(url) parsed_url = urlparse(url)
...@@ -121,33 +119,35 @@ class RunPromise(GenericPromise): ...@@ -121,33 +119,35 @@ class RunPromise(GenericPromise):
if len(entry_list) == 0: if len(entry_list) == 0:
appendError('No data') appendError('No data')
return return
if len(entry_list) > 0:
self.appendMessage('%s:' % (key,))
def addError(msg, *args):
self.error = True
self.appendMessage('ERROR ' + msg % args)
for entry in entry_list: for entry in entry_list:
timetuple = email.utils.parsedate(entry['not_after']) timetuple = email.utils.parsedate(entry['not_after'])
if timetuple is None: if timetuple is None:
appendError('No certificate information for %s' % (entry['ip'])) addError('IP %s no information' % (entry['ip'],))
else: else:
certificate_expiration_time = datetime.datetime.fromtimestamp( certificate_expiration_time = datetime.datetime.fromtimestamp(
time.mktime(timetuple)) time.mktime(timetuple))
if certificate_expiration_time - datetime.timedelta( if certificate_expiration_time - datetime.timedelta(
days=certificate_expiration_days) < self.utcnow: days=certificate_expiration_days) < self.utcnow:
appendError( addError(
'Certificate on %s will expire on %s, which is less than %s days', 'IP %s will expire in < %s days',
entry['ip'], entry['not_after'], certificate_expiration_days) entry['ip'], certificate_expiration_days)
return
else: else:
self.appendInfoMessage( self.appendMessage(
'%s: OK Certificate on %s will expire on %s, which is more than ' 'OK IP %s will expire in > %s days' % (
'%s days' % ( entry['ip'], certificate_expiration_days))
key, entry['ip'], entry['not_after'],
certificate_expiration_days))
return
def senseHttpQuery(self): def senseHttpQuery(self):
key = 'http_query' key = 'http_query'
error = False
def appendError(msg, *args): def appendError(msg, *args):
self.appendErrorMessage(key + ': ERROR ' + msg % args) self.error = True
self.appendMessage(key + ': ERROR ' + msg % args)
if key not in self.surykatka_json: if key not in self.surykatka_json:
appendError("%r not in %r", key, self.json_file) appendError("%r not in %r", key, self.json_file)
...@@ -162,6 +162,11 @@ class RunPromise(GenericPromise): ...@@ -162,6 +162,11 @@ class RunPromise(GenericPromise):
if len(entry_list) == 0: if len(entry_list) == 0:
appendError('No data') appendError('No data')
return return
def addError(msg, *args):
self.error = True
self.appendMessage('ERROR ' + msg % args)
self.appendMessage('%s:' % (key,))
for entry in entry_list: for entry in entry_list:
entry_status_code = str(entry['status_code']) entry_status_code = str(entry['status_code'])
if entry_status_code != status_code: if entry_status_code != status_code:
...@@ -172,45 +177,44 @@ class RunPromise(GenericPromise): ...@@ -172,45 +177,44 @@ class RunPromise(GenericPromise):
entry_status_code, status_code_explanation) entry_status_code, status_code_explanation)
else: else:
status_code_explanation = entry_status_code status_code_explanation = entry_status_code
appendError( addError(
'IP %s got status code %s instead of %s' % ( 'IP %s expected status_code %s != %s' % (
entry['ip'], status_code_explanation, status_code)) entry['ip'], status_code_explanation, status_code))
error = True else:
if http_header_dict and http_header_dict != entry['http_header_dict']: self.appendMessage(
appendError( 'OK IP %s status_code %s' % (entry['ip'], status_code))
'HTTP Header dict was %s instead of %s' % ( if http_header_dict:
json.dumps(entry['http_header_dict'], sort_keys=True), if http_header_dict != entry['http_header_dict']:
json.dumps(http_header_dict, sort_keys=True),)) addError(
error = True 'IP %s expected HTTP Header %s != of %s' % (
entry['ip'],
json.dumps(http_header_dict, sort_keys=True),
json.dumps(entry['http_header_dict'], sort_keys=True)))
else:
self.appendMessage(
'OK IP %s HTTP Header %s' % (
entry['ip'], json.dumps(http_header_dict, sort_keys=True)))
db_ip_list = [q['ip'] for q in entry_list] db_ip_list = [q['ip'] for q in entry_list]
if len(ip_list): if len(ip_list):
if set(ip_list) != set(db_ip_list): if set(ip_list) != set(db_ip_list):
appendError( addError(
'expected IPs %s differes from got %s' % ( 'expected IPs %s != %s' % (
' '.join(ip_list), ' '.join(db_ip_list))) ' '.join(ip_list), ' '.join(db_ip_list)))
error = True
if error:
return
info_message = '%s: OK with status code %s' % (key, status_code)
if http_header_dict:
info_message += ' and HTTP Header dict %s' % (
json.dumps(http_header_dict, sort_keys=True),
)
if len(ip_list) > 0:
info_message += ' on IPs %s' % (' '.join(ip_list))
self.appendInfoMessage(info_message)
def senseElapsedTime(self): def senseElapsedTime(self):
key = 'elapsed_time' key = 'elapsed_time'
surykatka_key = 'http_query' surykatka_key = 'http_query'
def appendError(msg, *args): def appendError(msg, *args):
self.appendErrorMessage(key + ': ERROR ' + msg % args) self.error = True
self.appendMessage('ERROR ' + msg % args)
if surykatka_key not in self.surykatka_json: if surykatka_key not in self.surykatka_json:
appendError( self.error = True
'No key %r. If the error persist, please update surykatka.' % ( self.appendMessage(
surykatka_key,)) '%s: ERROR No key %r. If the error persist, please update '
'surykatka.' % (
key, surykatka_key,))
return return
url = self.getConfig('url') url = self.getConfig('url')
...@@ -219,43 +223,51 @@ class RunPromise(GenericPromise): ...@@ -219,43 +223,51 @@ class RunPromise(GenericPromise):
entry_list = [ entry_list = [
q for q in self.surykatka_json[surykatka_key] if q['url'] == url] q for q in self.surykatka_json[surykatka_key] if q['url'] == url]
if len(entry_list) == 0: if len(entry_list) == 0:
appendError('No data') self.error = True
self.appendMessage('%s: ERROR No data' % (key,))
return return
prefix_added = False
for entry in entry_list: for entry in entry_list:
if maximum_elapsed_time: if maximum_elapsed_time:
if 'total_seconds' in entry: if 'total_seconds' in entry:
maximum_elapsed_time = float(maximum_elapsed_time) maximum_elapsed_time = float(maximum_elapsed_time)
if entry['total_seconds'] == 0.: if entry['total_seconds'] == 0.:
if not prefix_added:
self.appendMessage('%s:' % (key,))
prefix_added = True
appendError('IP %s failed to reply' % (entry['ip'])) appendError('IP %s failed to reply' % (entry['ip']))
elif entry['total_seconds'] > maximum_elapsed_time: elif entry['total_seconds'] > maximum_elapsed_time:
if not prefix_added:
self.appendMessage('%s:' % (key,))
prefix_added = True
appendError( appendError(
'IP %s replied in more time than maximum %.2fs' % 'IP %s replied > %.2fs' %
(entry['ip'], maximum_elapsed_time)) (entry['ip'], maximum_elapsed_time))
else: else:
self.appendInfoMessage( if not prefix_added:
'%s: OK IP %s replied in less time than maximum %.2fs' % ( self.appendMessage('%s:' % (key,))
key, entry['ip'], maximum_elapsed_time)) prefix_added = True
self.appendMessage(
'OK IP %s replied < %.2fs' % (
entry['ip'], maximum_elapsed_time))
def sense(self): def sense(self):
""" """
Check if frontend URL is available Check if frontend URL is available
""" """
test_utcnow = self.getConfig('test-utcnow') self.utcnow = datetime.datetime.utcnow()
if test_utcnow:
self.utcnow = datetime.datetime.fromtimestamp(
time.mktime(email.utils.parsedate(test_utcnow)))
else:
self.utcnow = datetime.datetime.utcnow()
self.json_file = self.getConfig('json-file', '') self.json_file = self.getConfig('json-file', '')
if not os.path.exists(self.json_file): if not os.path.exists(self.json_file):
self.appendErrorMessage('ERROR File %r does not exists' % self.json_file) self.error = True
self.appendMessage('ERROR File %r does not exists' % self.json_file)
else: else:
with open(self.json_file) as fh: with open(self.json_file) as fh:
try: try:
self.surykatka_json = json.load(fh) self.surykatka_json = json.load(fh)
except Exception: except Exception:
self.appendErrorMessage( self.error = True
self.appendMessage(
"ERROR loading JSON from %r" % self.json_file) "ERROR loading JSON from %r" % self.json_file)
else: else:
report = self.getConfig('report') report = self.getConfig('report')
...@@ -266,7 +278,8 @@ class RunPromise(GenericPromise): ...@@ -266,7 +278,8 @@ class RunPromise(GenericPromise):
self.senseSslCertificate() self.senseSslCertificate()
self.senseElapsedTime() self.senseElapsedTime()
else: else:
self.appendErrorMessage( self.error = True
self.appendMessage(
"ERROR Report %r is not supported" % report) "ERROR Report %r is not supported" % report)
self.emitLog() self.emitLog()
......
from slapos.grid.promise import PromiseError from slapos.grid.promise import PromiseError
from slapos.test.promise.plugin import TestPromisePluginMixin from slapos.test.promise.plugin import TestPromisePluginMixin
import email
import json
import os import os
import shutil import shutil
import tempfile import tempfile
import time
class CheckSurykatkaJSONMixin(TestPromisePluginMixin): class CheckSurykatkaJSONMixin(TestPromisePluginMixin):
maxDiff = None # show full diffs for test readability
promise_name = 'check-surykatka-json.py' promise_name = 'check-surykatka-json.py'
def setUp(self): def setUp(self):
...@@ -15,6 +19,18 @@ class CheckSurykatkaJSONMixin(TestPromisePluginMixin): ...@@ -15,6 +19,18 @@ class CheckSurykatkaJSONMixin(TestPromisePluginMixin):
self.addCleanup(shutil.rmtree, self.working_directory) self.addCleanup(shutil.rmtree, self.working_directory)
TestPromisePluginMixin.setUp(self) TestPromisePluginMixin.setUp(self)
now = time.time()
minute = 60
day = 24 * 3600
create_date = email.utils.formatdate
self.time_past14d = create_date(now - 14 * day)
self.time_past20m = create_date(now - 20 * minute)
self.time_past2m = create_date(now - 2 * minute)
self.time_future20m = create_date(now + 20 * minute)
self.time_future3d = create_date(now + 3 * day)
self.time_future14d = create_date(now + 14 * day)
self.time_future60d = create_date(now + 60 * day)
def writeSurykatkaPromise(self, d=None): def writeSurykatkaPromise(self, d=None):
if d is None: if d is None:
d = {} d = {}
...@@ -26,10 +42,14 @@ class CheckSurykatkaJSONMixin(TestPromisePluginMixin): ...@@ -26,10 +42,14 @@ class CheckSurykatkaJSONMixin(TestPromisePluginMixin):
content_list.append('}') content_list.append('}')
self.writePromise(self.promise_name, '\n'.join(content_list)) self.writePromise(self.promise_name, '\n'.join(content_list))
def writeSurykatkaJson(self, content): def writeSurykatkaJsonDirect(self, content):
with open(self.json_file, 'w') as fh: with open(self.json_file, 'w') as fh:
fh.write(content) fh.write(content)
def writeSurykatkaJson(self, content):
with open(self.json_file, 'w') as fh:
json.dump(content, fh, indent=2)
def assertFailedMessage(self, result, message): def assertFailedMessage(self, result, message):
self.assertEqual(result['result']['failed'], True) self.assertEqual(result['result']['failed'], True)
self.assertEqual( self.assertEqual(
...@@ -43,7 +63,7 @@ class CheckSurykatkaJSONMixin(TestPromisePluginMixin): ...@@ -43,7 +63,7 @@ class CheckSurykatkaJSONMixin(TestPromisePluginMixin):
message) message)
class TestCheckSurykatkaJSON(CheckSurykatkaJSONMixin): class TestCheckSurykatkaJSONBase(CheckSurykatkaJSONMixin):
def test_no_config(self): def test_no_config(self):
self.writeSurykatkaPromise() self.writeSurykatkaPromise()
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
...@@ -64,7 +84,7 @@ class TestCheckSurykatkaJSON(CheckSurykatkaJSONMixin): ...@@ -64,7 +84,7 @@ class TestCheckSurykatkaJSON(CheckSurykatkaJSONMixin):
def test_empty_file(self): def test_empty_file(self):
self.writeSurykatkaPromise({'json-file': self.json_file}) self.writeSurykatkaPromise({'json-file': self.json_file})
self.writeSurykatkaJson('') self.writeSurykatkaJsonDirect('')
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
...@@ -72,8 +92,6 @@ class TestCheckSurykatkaJSON(CheckSurykatkaJSONMixin): ...@@ -72,8 +92,6 @@ class TestCheckSurykatkaJSON(CheckSurykatkaJSONMixin):
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"ERROR loading JSON from '%s'" % (self.json_file,)) "ERROR loading JSON from '%s'" % (self.json_file,))
class TestCheckSurykatkaJSONUnknownReport(CheckSurykatkaJSONMixin):
def test(self): def test(self):
self.writeSurykatkaPromise( self.writeSurykatkaPromise(
{ {
...@@ -81,9 +99,7 @@ class TestCheckSurykatkaJSONUnknownReport(CheckSurykatkaJSONMixin): ...@@ -81,9 +99,7 @@ class TestCheckSurykatkaJSONUnknownReport(CheckSurykatkaJSONMixin):
'json-file': self.json_file, 'json-file': self.json_file,
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({})
}
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
...@@ -98,18 +114,13 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin): ...@@ -98,18 +114,13 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
{ {
'report': 'bot_status', 'report': 'bot_status',
'json-file': self.json_file, 'json-file': self.json_file,
'test-utcnow': 'Wed, 13 Dec 2222 09:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"bot_status": [ "bot_status": [
{ {
"date": "Wed, 13 Dec 2222 09:10:11 -0000", "date": self.time_past2m,
"text": "loop" "text": "loop"}]})
}
]
}
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
self.launcher.run() self.launcher.run()
self.assertPassedMessage( self.assertPassedMessage(
...@@ -122,18 +133,13 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin): ...@@ -122,18 +133,13 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
{ {
'report': 'bot_status', 'report': 'bot_status',
'json-file': self.json_file, 'json-file': self.json_file,
'test-utcnow': 'Wed, 13 Dec 2222 09:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"bot_status": [ "bot_status": [
{ {
"date": "Wed, 13 Dec 2222 09:10:11 -0000", "date": "Wed, 13 Dec 2222 09:10:11 -0000",
"text": "error" "text": "error"}]})
}
]
}
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
...@@ -148,18 +154,13 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin): ...@@ -148,18 +154,13 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
{ {
'report': 'bot_status', 'report': 'bot_status',
'json-file': self.json_file, 'json-file': self.json_file,
'test-utcnow': 'Wed, 13 Dec 2222 09:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"bot_status": [ "bot_status": [
{ {
"date": "Wed, 13 Dec 2223 09:10:11 -0000", "date": self.time_future20m,
"text": "loop" "text": "loop"}]})
}
]
}
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
...@@ -173,18 +174,13 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin): ...@@ -173,18 +174,13 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
{ {
'report': 'bot_status', 'report': 'bot_status',
'json-file': self.json_file, 'json-file': self.json_file,
'test-utcnow': 'Wed, 13 Dec 2223 09:26:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"bot_status": [ "bot_status": [
{ {
"date": "Wed, 13 Dec 2223 09:10:11 -0000", "date": self.time_past20m,
"text": "loop" "text": "loop"}]})
}
]
}
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
...@@ -200,9 +196,7 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin): ...@@ -200,9 +196,7 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
'json-file': self.json_file, 'json-file': self.json_file,
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({})
}
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
...@@ -217,10 +211,7 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin): ...@@ -217,10 +211,7 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
'json-file': self.json_file, 'json-file': self.json_file,
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({"bot_status": []})
"bot_status": []
}
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
...@@ -238,53 +229,53 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -238,53 +229,53 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'url': 'https://www.erp5.com/', 'url': 'https://www.erp5.com/',
'status-code': '302', 'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2', 'ip-list': '127.0.0.1 127.0.0.2',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213", "ip": "176.31.129.213",
"status_code": 200, "status_code": 200,
"url": "https://www.erp5.org/" "url": "https://www.erp5.org/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
}, },
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
} }
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
self.launcher.run() self.launcher.run()
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 on IPs " "https://www.erp5.com/ : "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will " "http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days" "status_code 302 "
"ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"127.0.0.2 will expire in > 15 days"
) )
def test_maximum_elapsed_time(self): def test_maximum_elapsed_time(self):
...@@ -296,58 +287,58 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -296,58 +287,58 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'status-code': '302', 'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2', 'ip-list': '127.0.0.1 127.0.0.2',
'maximum-elapsed-time': '5', 'maximum-elapsed-time': '5',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/", "url": "https://www.erp5.com/",
"total_seconds": 4 "total_seconds": 4
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/", "url": "https://www.erp5.com/",
"total_seconds": 4 "total_seconds": 4
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213", "ip": "176.31.129.213",
"status_code": 200, "status_code": 200,
"url": "https://www.erp5.org/", "url": "https://www.erp5.org/",
"total_seconds": 4 "total_seconds": 4
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
}, },
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
} }
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
self.launcher.run() self.launcher.run()
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 on IPs " "https://www.erp5.com/ : "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will " "http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days " "status_code 302 "
"elapsed_time: OK IP 127.0.0.1 replied in less time than maximum 5.00s " "ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"elapsed_time: OK IP 127.0.0.2 replied in less time than maximum 5.00s" "127.0.0.2 will expire in > 15 days "
"elapsed_time: OK IP 127.0.0.1 replied < 5.00s OK IP 127.0.0.2 replied "
"< 5.00s"
) )
def test_maximum_elapsed_time_too_long(self): def test_maximum_elapsed_time_too_long(self):
...@@ -359,59 +350,59 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -359,59 +350,59 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'status-code': '302', 'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2', 'ip-list': '127.0.0.1 127.0.0.2',
'maximum-elapsed-time': '5', 'maximum-elapsed-time': '5',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/", "url": "https://www.erp5.com/",
"total_seconds": 6 "total_seconds": 6
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/", "url": "https://www.erp5.com/",
"total_seconds": 0 "total_seconds": 0
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213", "ip": "176.31.129.213",
"status_code": 200, "status_code": 200,
"url": "https://www.erp5.org/", "url": "https://www.erp5.org/",
"total_seconds": 4 "total_seconds": 4
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
}, },
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
} }
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : elapsed_time: ERROR IP 127.0.0.1 replied in " "https://www.erp5.com/ : "
"more time than maximum 5.00s elapsed_time: ERROR IP 127.0.0.2 failed " "http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"to reply http_query: OK with status code 302 on IPs 127.0.0.1 " "status_code 302 "
"127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will expire on " "ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days" "127.0.0.2 will expire in > 15 days "
"elapsed_time: ERROR IP 127.0.0.1 replied > 5.00s ERROR IP "
"127.0.0.2 failed to reply"
) )
def test_maximum_elapsed_time_no_total_seconds(self): def test_maximum_elapsed_time_no_total_seconds(self):
...@@ -423,53 +414,53 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -423,53 +414,53 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'status-code': '302', 'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2', 'ip-list': '127.0.0.1 127.0.0.2',
'maximum-elapsed-time': '5', 'maximum-elapsed-time': '5',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213", "ip": "176.31.129.213",
"status_code": 200, "status_code": 200,
"url": "https://www.erp5.org/" "url": "https://www.erp5.org/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
}, },
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
} }
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
self.launcher.run() self.launcher.run()
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 on IPs " "https://www.erp5.com/ : "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will " "http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days" "status_code 302 "
"ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"127.0.0.2 will expire in > 15 days"
) )
def test_http(self): def test_http(self):
...@@ -480,40 +471,39 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -480,40 +471,39 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'url': 'http://www.erp5.com/', 'url': 'http://www.erp5.com/',
'status-code': '302', 'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2', 'ip-list': '127.0.0.1 127.0.0.2',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "http://www.erp5.com/" "url": "http://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"status_code": 302, "status_code": 302,
"url": "http://www.erp5.com/" "url": "http://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213", "ip": "176.31.129.213",
"status_code": 200, "status_code": 200,
"url": "http://www.erp5.org/" "url": "http://www.erp5.org/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
self.launcher.run() self.launcher.run()
self.assertPassedMessage( self.assertPassedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"http://www.erp5.com/ : http_query: OK with status code 302 on IPs " "http://www.erp5.com/ : "
"127.0.0.1 127.0.0.2" "http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"status_code 302"
) )
def test_http_with_header_dict(self): def test_http_with_header_dict(self):
...@@ -525,32 +515,30 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -525,32 +515,30 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'status-code': '200', 'status-code': '200',
'http-header-dict': '{"Vary": "Accept-Encoding", "Cache-Control": ' 'http-header-dict': '{"Vary": "Accept-Encoding", "Cache-Control": '
'"max-age=300, public"}', '"max-age=300, public"}',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson( self.writeSurykatkaJson({
"""{ "http_query": [
"http_query": [ {
{ "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "ip": "176.31.129.213",
"ip": "176.31.129.213", "http_header_dict": {
"http_header_dict": {"Vary": "Accept-Encoding", """ "Vary": "Accept-Encoding", "Cache-Control": "max-age=300, public"},
""""Cache-Control": "max-age=300, public"}, "status_code": 200,
"status_code": 200, "url": "http://www.erp5.com/"
"url": "http://www.erp5.com/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
self.launcher.run() self.launcher.run()
self.assertPassedMessage( self.assertPassedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"http://www.erp5.com/ : http_query: OK with status code 200 " 'http://www.erp5.com/ : '
"and HTTP Header dict {\"Cache-Control\": \"max-age=300, public\", " 'http_query: OK IP 176.31.129.213 status_code 200 OK IP '
"\"Vary\": \"Accept-Encoding\"}" '176.31.129.213 HTTP Header {"Cache-Control": "max-age=300, public", '
'"Vary": "Accept-Encoding"}'
) )
def test_http_with_bad_header_dict(self): def test_http_with_bad_header_dict(self):
...@@ -562,35 +550,33 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -562,35 +550,33 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'status-code': '200', 'status-code': '200',
'http-header-dict': '{"Vary": "Accept-Encoding", "Cache-Control": ' 'http-header-dict': '{"Vary": "Accept-Encoding", "Cache-Control": '
'"max-age=300, public"}', '"max-age=300, public"}',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson( self.writeSurykatkaJson({
"""{ "http_query": [
"http_query": [ {
{ "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "ip": "176.31.129.213",
"ip": "176.31.129.213", "http_header_dict": {
"http_header_dict": {"Vary": "Accept-Encoding,Cookie", """ "Vary": "Accept-Encoding,Cookie",
""""Cache-Control": "max-age=300, public"}, "Cache-Control": "max-age=300, public"},
"status_code": 200, "status_code": 200,
"url": "http://www.erp5.com/" "url": "http://www.erp5.com/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"http://www.erp5.com/ : http_query: ERROR HTTP Header dict was " 'http://www.erp5.com/ : '
"{\"Cache-Control\": \"max-age=300, public\", \"Vary\": " 'http_query: OK IP 176.31.129.213 status_code 200 ERROR IP '
"\"Accept-Encoding,Cookie\"} " '176.31.129.213 expected HTTP Header {"Cache-Control": "max-age=300, '
"instead of {\"Cache-Control\": \"max-age=300, public\", \"Vary\": " 'public", "Vary": "Accept-Encoding"} != of {"Cache-Control": '
"\"Accept-Encoding\"}" '"max-age=300, public", "Vary": "Accept-Encoding,Cookie"}'
) )
def test_no_ip_list(self): def test_no_ip_list(self):
...@@ -600,53 +586,53 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -600,53 +586,53 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'json-file': self.json_file, 'json-file': self.json_file,
'url': 'https://www.erp5.com/', 'url': 'https://www.erp5.com/',
'status-code': '302', 'status-code': '302',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213", "ip": "176.31.129.213",
"status_code": 200, "status_code": 200,
"url": "https://www.erp5.org/" "url": "https://www.erp5.org/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
}, },
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
} }
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
self.launcher.run() self.launcher.run()
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/ : "
"ssl_certificate: OK Certificate on 127.0.0.1 will expire on Mon, 13 " "http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"Jul 2020 12:00:00 -0000, which is more than 15 days" "status_code 302 "
"ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"127.0.0.2 will expire in > 15 days"
) )
def test_good_certificate_2_day(self): def test_good_certificate_2_day(self):
...@@ -656,36 +642,34 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -656,36 +642,34 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'json-file': self.json_file, 'json-file': self.json_file,
'url': 'https://www.erp5.com/', 'url': 'https://www.erp5.com/',
'status-code': '302', 'status-code': '302',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000',
'certificate-expiration-days': '2' 'certificate-expiration-days': '2'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"not_after": "Sun, 30 Dec 2019 12:00:00 -0000" "not_after": self.time_future3d
} }
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
self.launcher.run() self.launcher.run()
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/ : "
"ssl_certificate: OK Certificate on 127.0.0.1 will expire on Sun, 30 " "http_query: OK IP 127.0.0.1 status_code 302 "
"Dec 2019 12:00:00 -0000, which is more than 2 days" "ssl_certificate: OK IP 127.0.0.1 will expire in > 2 days"
) )
def test_expired_certificate_2_day(self): def test_expired_certificate_2_day(self):
...@@ -695,37 +679,35 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -695,37 +679,35 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'json-file': self.json_file, 'json-file': self.json_file,
'url': 'https://www.erp5.com/', 'url': 'https://www.erp5.com/',
'status-code': '302', 'status-code': '302',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000',
'certificate-expiration-days': '2' 'certificate-expiration-days': '2'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"not_after": "Sat, 28 Dec 2019 12:00:00 -0000" "not_after": self.time_future1d
} }
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : ssl_certificate: ERROR Certificate on " "https://www.erp5.com/ : "
"127.0.0.1 will expire on Sat, 28 Dec 2019 12:00:00 -0000, which is " "http_query: OK IP 127.0.0.1 status_code 302 "
"less than 2 days http_query: OK with status code 302" "ssl_certificate: ERROR IP 127.0.0.1 will expire in < 2 days"
) )
def test_expired_certificate(self): def test_expired_certificate(self):
...@@ -735,36 +717,34 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -735,36 +717,34 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'json-file': self.json_file, 'json-file': self.json_file,
'url': 'https://www.erp5.com/', 'url': 'https://www.erp5.com/',
'status-code': '302', 'status-code': '302',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"not_after": "Sat, 28 Dec 2019 12:00:00 -0000" "not_after": self.time_future14d
} }
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : ssl_certificate: ERROR Certificate on " "https://www.erp5.com/ : "
"127.0.0.1 will expire on Sat, 28 Dec 2019 12:00:00 -0000, which is " "http_query: OK IP 127.0.0.1 status_code 302 "
"less than 15 days http_query: OK with status code 302" "ssl_certificate: ERROR IP 127.0.0.1 will expire in < 15 days"
) )
def test_expired_certificate_before_today(self): def test_expired_certificate_before_today(self):
...@@ -774,37 +754,34 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -774,37 +754,34 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'json-file': self.json_file, 'json-file': self.json_file,
'url': 'https://www.erp5.com/', 'url': 'https://www.erp5.com/',
'status-code': '302', 'status-code': '302',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"not_after": "Thu, 26 Dec 2019 12:00:00 -0000" "not_after": self.time_past14d
} }
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : ssl_certificate: ERROR Certificate on " "https://www.erp5.com/ : "
"127.0.0.1 will expire on Thu, 26 Dec 2019 12:00:00 -0000, which is " "http_query: OK IP 127.0.0.1 status_code 302 "
"less than 15 days http_query: OK with status code 302" "ssl_certificate: ERROR IP 127.0.0.1 will expire in < 15 days")
)
def test_no_http_query_data(self): def test_no_http_query_data(self):
self.writeSurykatkaPromise( self.writeSurykatkaPromise(
...@@ -814,36 +791,75 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -814,36 +791,75 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'url': 'https://www.erp5.com/', 'url': 'https://www.erp5.com/',
'status-code': '302', 'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2', 'ip-list': '127.0.0.1 127.0.0.2',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
], ],
"ssl_certificate": [ "ssl_certificate": [
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
},
{
"date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": self.time_future60d
}
]
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"http_query: ERROR No data "
"ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"127.0.0.2 will expire in > 15 days "
"elapsed_time: ERROR No data"
)
def test_no_http_query_present(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2',
}
)
self.writeSurykatkaJson({
"ssl_certificate": [
{
"date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_future60d
}, },
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
} }
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
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/ : "
"No data ssl_certificate: OK Certificate on 127.0.0.1 will expire on " "http_query: ERROR 'http_query' not in %(json_file)r "
"Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days" "ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"127.0.0.2 will expire in > 15 days "
"elapsed_time: ERROR No key 'http_query'. If the error persist, please "
"update surykatka." % {'json_file': self.json_file}
) )
def test_no_ssl_certificate_data(self): def test_no_ssl_certificate_data(self):
...@@ -854,41 +870,41 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -854,41 +870,41 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'url': 'https://www.erp5.com/', 'url': 'https://www.erp5.com/',
'status-code': '302', 'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2', 'ip-list': '127.0.0.1 127.0.0.2',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213", "ip": "176.31.129.213",
"status_code": 200, "status_code": 200,
"url": "https://www.erp5.org/" "url": "https://www.erp5.org/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : ssl_certificate: ERROR No data http_query: " "https://www.erp5.com/ : "
"OK with status code 302 on IPs 127.0.0.1 127.0.0.2" "http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"status_code 302 "
"ssl_certificate: ERROR No data"
) )
def test_no_ssl_certificate(self): def test_no_ssl_certificate(self):
...@@ -899,40 +915,40 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -899,40 +915,40 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'url': 'https://www.erp5.com/', 'url': 'https://www.erp5.com/',
'status-code': '302', 'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2', 'ip-list': '127.0.0.1 127.0.0.2',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213", "ip": "176.31.129.213",
"status_code": 200, "status_code": 200,
"url": "https://www.erp5.org/" "url": "https://www.erp5.org/"
} }
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : ssl_certificate: ERROR No key " "https://www.erp5.com/ : "
"'ssl_certificate'. If the error persist, please update surykatka. " "http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"http_query: OK with status code 302 on IPs 127.0.0.1 127.0.0.2" "status_code 302 "
"ssl_certificate: ERROR No key 'ssl_certificate'. If the error "
"persist, please update surykatka."
) )
def test_bad_code(self): def test_bad_code(self):
...@@ -942,54 +958,54 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -942,54 +958,54 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'json-file': self.json_file, 'json-file': self.json_file,
'url': 'https://www.erp5.com/', 'url': 'https://www.erp5.com/',
'status-code': '301', 'status-code': '301',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"status_code": 301, "status_code": 301,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213", "ip": "176.31.129.213",
"status_code": 200, "status_code": 200,
"url": "https://www.erp5.org/" "url": "https://www.erp5.org/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
}, },
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
} }
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
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/ : "
"302 instead of 301 ssl_certificate: OK Certificate on 127.0.0.1 will " "http_query: ERROR IP 127.0.0.1 expected status_code 302 != 301 OK IP "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days" "127.0.0.2 status_code 301 "
"ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"127.0.0.2 will expire in > 15 days"
) )
def _test_bad_code_explanation(self, status_code, explanation): def _test_bad_code_explanation(self, status_code, explanation):
...@@ -999,43 +1015,41 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -999,43 +1015,41 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'json-file': self.json_file, 'json-file': self.json_file,
'url': 'https://www.erp5.com/', 'url': 'https://www.erp5.com/',
'status-code': '301', 'status-code': '301',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": %s, "status_code": status_code,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
}, },
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
} }
] ]
} })
""" % status_code)
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
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/ : "
"%s instead of 301 ssl_certificate: OK Certificate on 127.0.0.1 will " "http_query: ERROR IP 127.0.0.1 expected status_code %s != 301 "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days" "ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"" % (explanation,) "127.0.0.2 will expire in > 15 days" % (explanation,)
) )
def test_bad_code_explanation_520(self): def test_bad_code_explanation_520(self):
...@@ -1058,55 +1072,55 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -1058,55 +1072,55 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'url': 'https://www.erp5.com/', 'url': 'https://www.erp5.com/',
'status-code': '301', 'status-code': '301',
'ip-list': '127.0.0.1 127.0.0.2', 'ip-list': '127.0.0.1 127.0.0.2',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 301, "status_code": 301,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.4", "ip": "127.0.0.4",
"status_code": 301, "status_code": 301,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213", "ip": "176.31.129.213",
"status_code": 200, "status_code": 200,
"url": "https://www.erp5.org/" "url": "https://www.erp5.org/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
}, },
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
} }
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
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/ : "
"127.0.0.2 differes from got 127.0.0.1 127.0.0.4 ssl_certificate: " "http_query: OK IP 127.0.0.1 status_code 301 OK IP 127.0.0.4 "
"OK Certificate on 127.0.0.1 will expire on Mon, 13 Jul 2020 12:00:00 " "status_code 301 ERROR expected IPs 127.0.0.1 127.0.0.2 != 127.0.0.1 "
"-0000, which is more than 15 days" "127.0.0.4 "
"ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"127.0.0.2 will expire in > 15 days"
) )
def test_bad_ip_status_code(self): def test_bad_ip_status_code(self):
...@@ -1117,56 +1131,55 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -1117,56 +1131,55 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'url': 'https://www.erp5.com/', 'url': 'https://www.erp5.com/',
'status-code': '301', 'status-code': '301',
'ip-list': '127.0.0.1 127.0.0.2', 'ip-list': '127.0.0.1 127.0.0.2',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.4", "ip": "127.0.0.4",
"status_code": 301, "status_code": 301,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213", "ip": "176.31.129.213",
"status_code": 200, "status_code": 200,
"url": "https://www.erp5.org/" "url": "https://www.erp5.org/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
}, },
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000" "not_after": self.time_future60d
} }
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
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/ : "
"302 instead of 301 http_query: ERROR expected IPs 127.0.0.1 127.0.0.2 " "http_query: ERROR IP 127.0.0.1 expected status_code 302 != 301 OK IP "
"differes from got 127.0.0.1 127.0.0.4 ssl_certificate: OK Certificate " "127.0.0.4 status_code 301 ERROR expected IPs 127.0.0.1 127.0.0.2 != "
"on 127.0.0.1 will expire on Mon, 13 Jul 2020 12:00:00 -0000, which is " "127.0.0.1 127.0.0.4 "
"more than 15 days" "ssl_certificate: OK IP 127.0.0.1 will expire in > 15 days OK IP "
"127.0.0.2 will expire in > 15 days"
) )
def test_https_no_cert(self): def test_https_no_cert(self):
...@@ -1177,48 +1190,47 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin): ...@@ -1177,48 +1190,47 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
'url': 'https://www.erp5.com/', 'url': 'https://www.erp5.com/',
'status-code': '301', 'status-code': '301',
'ip-list': '127.0.0.1 127.0.0.2', 'ip-list': '127.0.0.1 127.0.0.2',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
} }
) )
self.writeSurykatkaJson("""{ self.writeSurykatkaJson({
"http_query": [ "http_query": [
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"status_code": 302, "status_code": 302,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
}, },
{ {
"date": "Wed, 11 Dec 2019 09:35:28 -0000", "date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.4", "ip": "127.0.0.4",
"status_code": 301, "status_code": 301,
"url": "https://www.erp5.com/" "url": "https://www.erp5.com/"
} }
], ],
"ssl_certificate": [ "ssl_certificate": [
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.1", "ip": "127.0.0.1",
"not_after": null "not_after": None
}, },
{ {
"date": "Fri, 27 Dec 2019 14:43:26 -0000", "date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com", "hostname": "www.erp5.com",
"ip": "127.0.0.2", "ip": "127.0.0.2",
"not_after": null "not_after": None
} }
] ]
} })
""")
self.configureLauncher(enable_anomaly=True) self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError): with self.assertRaises(PromiseError):
self.launcher.run() self.launcher.run()
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/ : "
"302 instead of 301 http_query: ERROR expected IPs 127.0.0.1 127.0.0.2 " "http_query: ERROR IP 127.0.0.1 expected status_code 302 != 301 OK IP "
"differes from got 127.0.0.1 127.0.0.4 ssl_certificate: ERROR No " "127.0.0.4 status_code 301 ERROR expected IPs 127.0.0.1 127.0.0.2 != "
"certificate information for 127.0.0.1 ssl_certificate: ERROR No " "127.0.0.1 127.0.0.4 "
"certificate information for 127.0.0.2" "ssl_certificate: ERROR IP 127.0.0.1 no information ERROR IP 127.0.0.2 "
"no information"
) )
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