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

check_surykatka_json: Rewrite tests and improve code

Tests are rewritten for easier coverage of all cases, including all-ok case.
In the same time code has been improved while detecting inconsistencies.
parent b904068c
......@@ -107,9 +107,9 @@ class RunPromise(GenericPromise):
self.appendError('url is incorrect')
return
if key not in self.surykatka_json:
self.appendError(
'No key %r. If the error persist, please update surykatka.' % (key,))
self.appendError("%r not in %r" % (key, self.json_file))
return
entry_list = [
q for q in self.surykatka_json[key] if q['hostname'] == hostname]
if len(entry_list) == 0:
......@@ -169,7 +169,7 @@ class RunPromise(GenericPromise):
if http_header_dict:
if http_header_dict != entry['http_header_dict']:
self.appendError(
'IP %s expected HTTP Header %s != of %s' % (
'IP %s expected HTTP Header %s != %s' % (
entry['ip'],
json.dumps(http_header_dict, sort_keys=True),
json.dumps(entry['http_header_dict'], sort_keys=True)))
......@@ -193,11 +193,11 @@ class RunPromise(GenericPromise):
entry_list = [
q for q in self.surykatka_json[key]
if q['domain'] == hostname and q['rdtype'] == 'A']
if len(entry_list) == 0:
self.appendError('No data')
return
if len(ip_set):
if len(entry_list) == 0:
self.appendError('No data')
return
for entry in sorted(entry_list, key=operator.itemgetter('resolver_ip')):
response_ip_set = set([
q.strip() for q in entry['response'].split(",") if q.strip()])
......@@ -232,6 +232,9 @@ class RunPromise(GenericPromise):
else:
port = 80
ip_set = set(self.getConfig('ip-list', '').split())
if len(ip_set) == 0:
self.appendOk('No check configured')
return
entry_list = [
q for q in self.surykatka_json[key]
......@@ -240,22 +243,19 @@ class RunPromise(GenericPromise):
if len(entry_list) == 0:
self.appendError('No data')
return
if len(ip_set) > 0:
for ip in sorted(ip_set):
ok = False
for entry in sorted(entry_list, key=operator.itemgetter('ip')):
if entry['ip'] == ip:
if entry['state'] == 'closed':
ok = False
break
if entry['state'] == 'open':
ok = True
if ok:
self.appendOk('IP %s:%s' % (ip, port))
else:
self.appendError('IP %s:%s' % (ip, port))
else:
self.appendOk('No check configured')
for ip in sorted(ip_set):
ok = False
for entry in sorted(entry_list, key=operator.itemgetter('ip')):
if entry['ip'] == ip:
if entry['state'] == 'closed':
ok = False
break
if entry['state'] == 'open':
ok = True
if ok:
self.appendOk('IP %s:%s' % (ip, port))
else:
self.appendError('IP %s:%s' % (ip, port))
def senseElapsedTime(self):
key = 'elapsed_time'
......@@ -263,9 +263,7 @@ class RunPromise(GenericPromise):
surykatka_key = 'http_query'
if surykatka_key not in self.surykatka_json:
self.appendError(
'No key %r. If the error persist, please update surykatka.' % (
surykatka_key,))
self.appendError("%r not in %r" % (surykatka_key, self.json_file))
return
url = self.getConfig('url')
......
......@@ -221,168 +221,237 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
def test(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',
}
)
def setUp(self):
super().setUp()
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/"
"url": "https://www.allok.com/",
"total_seconds": 4
},
{
"ip": "127.0.0.2",
"status_code": 302,
"url": "https://www.erp5.com/"
"url": "https://www.allok.com/",
"total_seconds": 4
},
{
"ip": "176.31.129.213",
"status_code": 200,
"url": "https://www.erp5.org/"
}
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_future60d
"status_code": 302,
"url": "http://www.httpallok.com/",
"total_seconds": 4
},
{
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": self.time_future60d
}
],
"dns_query": [
{
"domain": "www.erp5.com",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
"status_code": 302,
"url": "http://www.httpallok.com/",
"total_seconds": 4
},
{
"domain": "www.erp5.org",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.elapsedtoolong.com/",
"total_seconds": 6
},
],
"tcp_server": [
{
"ip": "127.0.0.1",
"state": "open",
"port": 443,
"domain": "www.erp5.com"
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.elapsednototal.com/",
},
{
"ip": "127.0.0.2",
"state": "open",
"port": 443,
"domain": "www.erp5.com"
"ip": "127.0.0.1",
"status_code": 200,
"url": "http://www.httpheader.com/",
"http_header_dict": {
"Vary": "Accept-Encoding", "Cache-Control": "max-age=300, public"},
},
]
})
self.configureLauncher(enable_anomaly=True)
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"dns_query: OK resolver 1.2.3.4 returned expected set of IPs 127.0.0.1 "
"127.0.0.2 "
"tcp_server: OK IP 127.0.0.1:443 OK IP 127.0.0.2:443 "
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"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 "
"elapsed_time: OK No check configured"
)
def test_maximum_elapsed_time(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',
'maximum-elapsed-time': '5',
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/",
"url": "https://www.cert3.com/",
"total_seconds": 4
},
{
"ip": "127.0.0.2",
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/",
"url": "https://www.cert14.com/",
"total_seconds": 4
},
{
"ip": "176.31.129.213",
"status_code": 200,
"url": "https://www.erp5.org/",
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.certminus14.com/",
"total_seconds": 4
}
},
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.nosslcertificatedata.com/",
},
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "http://www.badip.com/",
},
{
"ip": "127.0.0.4",
"status_code": 302,
"url": "http://www.badip.com/",
},
{
"ip": "127.0.0.1",
"status_code": 301,
"url": "https://www.sslcertnoinfo.com/",
},
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"hostname": "www.allok.com",
"ip": "127.0.0.1",
"not_after": self.time_future60d
},
{
"hostname": "www.erp5.com",
"hostname": "www.allok.com",
"ip": "127.0.0.2",
"not_after": self.time_future60d
}
},
{
"hostname": "www.cert3.com",
"ip": "127.0.0.1",
"not_after": self.time_future3d
},
{
"hostname": "www.cert14.com",
"ip": "127.0.0.1",
"not_after": self.time_future14d
},
{
"hostname": "www.certminus14.com",
"ip": "127.0.0.1",
"not_after": self.time_past14d
},
{
"hostname": "www.sslcertnoinfo.com",
"ip": "127.0.0.1",
"not_after": None
},
],
"dns_query": [
{
"domain": "www.erp5.com",
"domain": "www.allok.com",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
},
{
"domain": "www.erp5.org",
"domain": "www.httpallok.com",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
},
{
"domain": "www.badip.com",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.4"
},
{
"domain": "www.dnsquerynoreply.com",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": ""
},
],
"tcp_server": [
{
"ip": "127.0.0.1",
"state": "open",
"port": 443,
"domain": "www.erp5.com"
"domain": "www.allok.com"
},
{
"ip": "127.0.0.2",
"state": "open",
"port": 443,
"domain": "www.erp5.com"
"domain": "www.allok.com"
},
{
"ip": "127.0.0.1",
"state": "open",
"port": 80,
"domain": "www.httpallok.com"
},
{
"ip": "127.0.0.2",
"state": "open",
"port": 80,
"domain": "www.httpallok.com"
},
{
"ip": "127.0.0.1",
"state": "open",
"port": 80,
"domain": "www.httpheader.com"
},
{
"ip": "127.0.0.1",
"state": "open",
"port": 80,
"domain": "www.badip.com"
},
{
"ip": "127.0.0.4",
"state": "open",
"port": 80,
"domain": "www.badip.com"
},
{
"ip": "127.0.0.2",
"state": "open",
"port": 80,
"domain": "www.tcpservernoip.com"
},
{
"ip": "127.0.0.1",
"state": "filtered",
"port": 80,
"domain": "www.tcpserverfiltered.com"
},
]
})
def runAndAssertPassedMessage(self, message):
self.configureLauncher(enable_anomaly=True)
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
message
)
def runAndAssertFailedMessage(self, message):
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
message
)
def test_all_ok(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.allok.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2',
'maximum-elapsed-time': '5',
}
)
self.runAndAssertPassedMessage(
"https://www.allok.com/ : "
"dns_query: OK resolver 1.2.3.4 returned expected set of IPs 127.0.0.1 "
"127.0.0.2 "
"tcp_server: OK IP 127.0.0.1:443 OK IP 127.0.0.2:443 "
......@@ -399,62 +468,19 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'url': 'https://www.elapsedtoolong.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2',
'ip-list': '127.0.0.1',
'maximum-elapsed-time': '5',
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/",
"total_seconds": 6
},
{
"ip": "127.0.0.2",
"status_code": 302,
"url": "https://www.erp5.com/",
"total_seconds": 0
},
{
"ip": "176.31.129.213",
"status_code": 200,
"url": "https://www.erp5.org/",
"total_seconds": 4
}
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_future60d
},
{
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": self.time_future60d
}
],
"dns_query": [],
"tcp_server": [],
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
self.runAndAssertFailedMessage(
"https://www.elapsedtoolong.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"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 "
"elapsed_time: ERROR IP 127.0.0.1 replied > 5.00s ERROR IP "
"127.0.0.2 failed to reply"
"http_query: OK IP 127.0.0.1 status_code 302 "
"ssl_certificate: ERROR No data "
"elapsed_time: ERROR IP 127.0.0.1 replied > 5.00s"
)
def test_maximum_elapsed_no_match(self):
......@@ -462,221 +488,43 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'url': 'https://www.elapsednototal.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2',
'ip-list': '127.0.0.1',
'maximum-elapsed-time': '5',
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/",
},
{
"ip": "127.0.0.2",
"status_code": 302,
"url": "https://www.erp5.com/",
},
{
"ip": "176.31.129.213",
"status_code": 200,
"url": "https://www.erp5.org/",
}
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_future60d
},
{
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": self.time_future60d
}
],
"dns_query": [],
"tcp_server": [],
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
self.runAndAssertFailedMessage(
"https://www.elapsednototal.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"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 "
"http_query: OK IP 127.0.0.1 status_code 302 "
"ssl_certificate: ERROR No data "
"elapsed_time: ERROR No entry with total_seconds found. If the error "
"persist, please update surykatka"
)
def test_maximum_elapsed_time_no_total_seconds(self):
def test_http_all_ok(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'url': 'http://www.httpallok.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2',
'maximum-elapsed-time': '5',
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/",
"total_seconds": 4
},
{
"ip": "127.0.0.2",
"status_code": 302,
"url": "https://www.erp5.com/",
"total_seconds": 4
},
{
"ip": "176.31.129.213",
"status_code": 200,
"url": "https://www.erp5.org/",
"total_seconds": 4
}
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_future60d
},
{
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": self.time_future60d
}
],
"dns_query": [
{
"domain": "www.erp5.com",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
},
{
"domain": "www.erp5.org",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
},
],
"tcp_server": [
{
"ip": "127.0.0.1",
"state": "open",
"port": 443,
"domain": "www.erp5.com"
},
{
"ip": "127.0.0.2",
"state": "open",
"port": 443,
"domain": "www.erp5.com"
},
]
})
self.configureLauncher(enable_anomaly=True)
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
self.runAndAssertPassedMessage(
"http://www.httpallok.com/ : "
"dns_query: OK resolver 1.2.3.4 returned expected set of IPs 127.0.0.1 "
"127.0.0.2 "
"tcp_server: OK IP 127.0.0.1:443 OK IP 127.0.0.2:443 "
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"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 "
"elapsed_time: OK IP 127.0.0.1 replied < 5.00s OK IP 127.0.0.2 replied "
"< 5.00s"
)
def test_http(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'http://www.erp5.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2',
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "http://www.erp5.com/"
},
{
"ip": "127.0.0.2",
"status_code": 302,
"url": "http://www.erp5.com/"
},
{
"ip": "176.31.129.213",
"status_code": 200,
"url": "http://www.erp5.org/"
}
],
"ssl_certificate": [
],
"dns_query": [
{
"domain": "www.erp5.com",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
},
{
"domain": "www.erp5.org",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
},
],
"tcp_server": [
{
"ip": "127.0.0.1",
"state": "open",
"port": 80,
"domain": "www.erp5.com"
},
{
"ip": "127.0.0.2",
"state": "open",
"port": 80,
"domain": "www.erp5.com"
},
]
})
self.configureLauncher(enable_anomaly=True)
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"http://www.erp5.com/ : "
"dns_query: OK resolver 1.2.3.4 returned expected set of IPs "
"127.0.0.1 127.0.0.2 "
"tcp_server: OK IP 127.0.0.1:80 OK IP 127.0.0.2:80 "
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"status_code 302 "
"ssl_certificate: OK No check needed "
"elapsed_time: OK No check configured"
"elapsed_time: OK IP 127.0.0.1 replied < 5.00s OK IP 127.0.0.2 replied "
"< 5.00s"
)
def test_http_with_header_dict(self):
......@@ -684,209 +532,57 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'http://www.erp5.com/',
'url': 'http://www.httpheader.com/',
'status-code': '200',
'http-header-dict': '{"Vary": "Accept-Encoding", "Cache-Control": '
'"max-age=300, public"}',
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "176.31.129.213",
"http_header_dict": {
"Vary": "Accept-Encoding", "Cache-Control": "max-age=300, public"},
"status_code": 200,
"url": "http://www.erp5.com/"
}
],
"ssl_certificate": [
],
"dns_query": [
{
"domain": "www.erp5.com",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
},
{
"domain": "www.erp5.org",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
},
],
"tcp_server": [
{
"ip": "127.0.0.1",
"state": "open",
"port": 80,
"domain": "www.erp5.com"
},
{
"ip": "127.0.0.2",
"state": "open",
"port": 80,
"domain": "www.erp5.com"
},
]
})
self.configureLauncher(enable_anomaly=True)
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
'http://www.erp5.com/ : '
self.runAndAssertPassedMessage(
'http://www.httpheader.com/ : '
'dns_query: OK No check configured '
'tcp_server: OK No check configured '
'http_query: OK IP 176.31.129.213 status_code 200 OK IP '
'176.31.129.213 HTTP Header {"Cache-Control": "max-age=300, public", '
'"Vary": "Accept-Encoding"} '
'http_query: OK IP 127.0.0.1 status_code 200 OK IP 127.0.0.1 HTTP '
'Header {"Cache-Control": "max-age=300, public", "Vary": '
'"Accept-Encoding"} '
'ssl_certificate: OK No check needed '
'elapsed_time: OK No check configured'
)
def test_http_with_bad_header_dict(self):
def test_http_with_header_dict_mismatch(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'http://www.erp5.com/',
'url': 'http://www.httpheader.com/',
'status-code': '200',
'http-header-dict': '{"Vary": "Accept-Encoding", "Cache-Control": '
'"max-age=300, public"}',
'"max-age=300"}',
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "176.31.129.213",
"http_header_dict": {
"Vary": "Accept-Encoding,Cookie",
"Cache-Control": "max-age=300, public"},
"status_code": 200,
"url": "http://www.erp5.com/"
}
],
"ssl_certificate": [
],
"dns_query": [
{
"domain": "www.erp5.com",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
},
{
"domain": "www.erp5.org",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
},
],
"tcp_server": [
{
"ip": "127.0.0.1",
"state": "open",
"port": 80,
"domain": "www.erp5.com"
},
{
"ip": "127.0.0.2",
"state": "open",
"port": 80,
"domain": "www.erp5.com"
},
]
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
'http://www.erp5.com/ : '
self.runAndAssertFailedMessage(
'http://www.httpheader.com/ : '
'dns_query: OK No check configured '
'tcp_server: OK No check configured '
'http_query: OK IP 176.31.129.213 status_code 200 ERROR IP '
'176.31.129.213 expected HTTP Header {"Cache-Control": "max-age=300, '
'public", "Vary": "Accept-Encoding"} != of {"Cache-Control": '
'"max-age=300, public", "Vary": "Accept-Encoding,Cookie"} '
'http_query: OK IP 127.0.0.1 status_code 200 ERROR IP 127.0.0.1 '
'expected HTTP Header {"Cache-Control": "max-age=300", "Vary": '
'"Accept-Encoding"} != {"Cache-Control": "max-age=300, public", "Vary": '
'"Accept-Encoding"} '
'ssl_certificate: OK No check needed '
'elapsed_time: OK No check configured'
)
def test_no_ip_list(self):
def test_configuration_no_ip_list(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'url': 'https://www.allok.com/',
'status-code': '302',
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/"
},
{
"ip": "127.0.0.2",
"status_code": 302,
"url": "https://www.erp5.com/"
},
{
"ip": "176.31.129.213",
"status_code": 200,
"url": "https://www.erp5.org/"
}
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_future60d
},
{
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": self.time_future60d
}
],
"dns_query": [
{
"domain": "www.erp5.com",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
},
{
"domain": "www.erp5.org",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "176.31.129.213"
},
],
"tcp_server": [
{
"ip": "127.0.0.1",
"state": "open",
"port": 443,
"domain": "www.erp5.com"
},
{
"ip": "127.0.0.2",
"state": "open",
"port": 443,
"domain": "www.erp5.com"
},
]
})
self.configureLauncher(enable_anomaly=True)
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
self.runAndAssertPassedMessage(
"https://www.allok.com/ : "
"dns_query: OK No check configured "
"tcp_server: OK No check configured "
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
......@@ -901,60 +597,13 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'url': 'https://www.cert3.com/',
'status-code': '302',
'certificate-expiration-days': '2'
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/"
}
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_future3d
}
],
"dns_query": [
{
"domain": "www.erp5.com",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
},
{
"domain": "www.erp5.org",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
},
],
"tcp_server": [
{
"ip": "127.0.0.1",
"state": "open",
"port": 443,
"domain": "www.erp5.com"
},
{
"ip": "127.0.0.2",
"state": "open",
"port": 443,
"domain": "www.erp5.com"
},
]
})
self.configureLauncher(enable_anomaly=True)
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
self.runAndAssertPassedMessage(
"https://www.cert3.com/ : "
"dns_query: OK No check configured "
"tcp_server: OK No check configured "
"http_query: OK IP 127.0.0.1 status_code 302 "
......@@ -962,484 +611,130 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"elapsed_time: OK No check configured"
)
def test_expired_certificate_2_day(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'status-code': '302',
'certificate-expiration-days': '2'
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/"
}
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_future1d
}
],
"dns_query": [],
"tcp_server": [],
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"http_query: OK IP 127.0.0.1 status_code 302 "
"ssl_certificate: ERROR IP 127.0.0.1 will expire in < 2 days "
"elapsed_time: OK No check configured"
)
def test_expired_certificate(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'status-code': '302',
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/"
}
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_future14d
}
],
"dns_query": [],
"tcp_server": [],
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"http_query: OK IP 127.0.0.1 status_code 302 "
"ssl_certificate: ERROR IP 127.0.0.1 will expire in < 15 days "
"elapsed_time: OK No check configured"
)
def test_expired_certificate_before_today(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'status-code': '302',
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/"
}
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_past14d
}
],
"dns_query": [],
"tcp_server": []
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"http_query: OK IP 127.0.0.1 status_code 302 "
"ssl_certificate: ERROR IP 127.0.0.1 will expire in < 15 days "
"elapsed_time: OK No check configured")
def test_no_http_query_data(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({
"http_query": [
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_future60d
},
{
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": self.time_future60d
}
],
"dns_query": [],
"tcp_server": [],
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"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": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_future60d
},
{
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": self.time_future60d
}
],
"dns_query": [],
"tcp_server": [],
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"http_query: ERROR 'http_query' not in %(json_file)r "
"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_expired_certificate_4_day(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'url': 'https://www.cert3.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2',
'certificate-expiration-days': '4'
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/"
},
{
"ip": "127.0.0.2",
"status_code": 302,
"url": "https://www.erp5.com/"
},
{
"ip": "176.31.129.213",
"status_code": 200,
"url": "https://www.erp5.org/"
}
],
"ssl_certificate": [
],
"dns_query": [
],
"tcp_server": []
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"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 "
self.runAndAssertFailedMessage(
"https://www.cert3.com/ : "
"dns_query: OK No check configured "
"tcp_server: OK No check configured "
"http_query: OK IP 127.0.0.1 status_code 302 "
"ssl_certificate: ERROR IP 127.0.0.1 will expire in < 4 days "
"elapsed_time: OK No check configured"
)
def test_no_ssl_certificate(self):
def test_expired_certificate(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'url': 'https://www.cert14.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2',
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/"
},
{
"ip": "127.0.0.2",
"status_code": 302,
"url": "https://www.erp5.com/"
},
{
"ip": "176.31.129.213",
"status_code": 200,
"url": "https://www.erp5.org/"
}
],
"dns_query": [],
"tcp_server": []
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"status_code 302 "
"ssl_certificate: ERROR No key 'ssl_certificate'. If the error "
"persist, please update surykatka. "
self.runAndAssertFailedMessage(
"https://www.cert14.com/ : "
"dns_query: OK No check configured "
"tcp_server: OK No check configured "
"http_query: OK IP 127.0.0.1 status_code 302 "
"ssl_certificate: ERROR IP 127.0.0.1 will expire in < 15 days "
"elapsed_time: OK No check configured"
)
def test_bad_code(self):
def test_expired_certificate_before_today(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'status-code': '301',
'url': 'https://www.certminus14.com/',
'status-code': '302',
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/"
},
{
"ip": "127.0.0.2",
"status_code": 301,
"url": "https://www.erp5.com/"
},
{
"ip": "176.31.129.213",
"status_code": 200,
"url": "https://www.erp5.org/"
}
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_future60d
},
{
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": self.time_future60d
}
],
"dns_query": [],
"tcp_server": []
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"http_query: ERROR IP 127.0.0.1 expected status_code 302 != 301 OK IP "
"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 "
self.runAndAssertFailedMessage(
"https://www.certminus14.com/ : "
"dns_query: OK No check configured "
"tcp_server: OK No check configured "
"http_query: OK IP 127.0.0.1 status_code 302 "
"ssl_certificate: ERROR IP 127.0.0.1 will expire in < 15 days "
"elapsed_time: OK No check configured"
)
def _test_bad_code_explanation(self, status_code, explanation):
def test_no_http_query_data(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'status-code': '301',
'url': 'http://www.httpquerynodata.com/',
'status-code': '302',
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": status_code,
"url": "https://www.erp5.com/"
}
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_future60d
},
{
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": self.time_future60d
}
],
"dns_query": [],
"tcp_server": [],
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"http_query: ERROR IP 127.0.0.1 expected status_code %s != 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 "
"elapsed_time: OK No check configured" % (explanation,)
self.runAndAssertFailedMessage(
"http://www.httpquerynodata.com/ : "
"dns_query: OK No check configured "
"tcp_server: OK No check configured "
"http_query: ERROR No data "
"ssl_certificate: OK No check needed "
"elapsed_time: ERROR No data"
)
def test_bad_code_explanation_520(self):
self._test_bad_code_explanation(520, '520 (Too many redirects)')
def test_bad_code_explanation_523(self):
self._test_bad_code_explanation(523, '523 (Connection error)')
def test_bad_code_explanation_524(self):
self._test_bad_code_explanation(524, '524 (Connection timeout)')
def test_bad_code_explanation_526(self):
self._test_bad_code_explanation(526, '526 (SSL Error)')
def test_bad_ip(self):
def test_no_http_query_present(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',
'url': 'http://www.httpquerynopresent.com/',
'status-code': '302',
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 301,
"url": "https://www.erp5.com/"
},
{
"ip": "127.0.0.4",
"status_code": 301,
"url": "https://www.erp5.com/"
},
{
"ip": "176.31.129.213",
"status_code": 200,
"url": "https://www.erp5.org/"
}
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_future60d
},
{
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": self.time_future60d
}
],
"ssl_certificate": [],
"dns_query": [],
"tcp_server": [],
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"http_query: OK IP 127.0.0.1 status_code 301 OK IP 127.0.0.4 "
"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 "
self.runAndAssertFailedMessage(
"http://www.httpquerynopresent.com/ : "
"dns_query: OK No check configured "
"tcp_server: OK No check configured "
"http_query: ERROR 'http_query' not in %(json_file)r "
"ssl_certificate: OK No check needed "
"elapsed_time: ERROR 'http_query' not in %(json_file)r" % {
'json_file': self.json_file}
)
def test_no_ssl_certificate_data(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.nosslcertificatedata.com/',
'status-code': '302',
}
)
self.runAndAssertFailedMessage(
"https://www.nosslcertificatedata.com/ : "
"dns_query: OK No check configured "
"tcp_server: OK No check configured "
"http_query: OK IP 127.0.0.1 "
"status_code 302 "
"ssl_certificate: ERROR No data "
"elapsed_time: OK No check configured"
)
def test_bad_ip_status_code(self):
def test_no_ssl_certificate(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',
'url': 'https://www.nosslcertificate.com/',
'status-code': '302',
}
)
self.writeSurykatkaJson({
......@@ -1447,99 +742,123 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/"
"url": "https://www.nosslcertificate.com/"
},
{
"ip": "127.0.0.4",
"status_code": 301,
"url": "https://www.erp5.com/"
},
{
"ip": "176.31.129.213",
"status_code": 200,
"url": "https://www.erp5.org/"
}
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": self.time_future60d
},
{
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": self.time_future60d
}
],
"dns_query": [],
"tcp_server": [],
"tcp_server": []
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"http_query: ERROR IP 127.0.0.1 expected status_code 302 != 301 OK IP "
"127.0.0.4 status_code 301 "
self.runAndAssertFailedMessage(
"https://www.nosslcertificate.com/ : "
"dns_query: OK No check configured "
"tcp_server: OK No check configured "
"http_query: OK IP 127.0.0.1 status_code 302 "
"ssl_certificate: ERROR 'ssl_certificate' not in %(json_file)r "
"elapsed_time: OK No check configured" % {'json_file': self.json_file}
)
def test_bad_code(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.allok.com/',
'status-code': '301',
}
)
self.runAndAssertFailedMessage(
"https://www.allok.com/ : "
"dns_query: OK No check configured "
"tcp_server: OK No check configured "
"http_query: ERROR IP 127.0.0.1 expected status_code 302 != 301 ERROR "
"IP 127.0.0.2 expected status_code 302 != 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 "
"elapsed_time: OK No check configured"
)
def test_https_no_cert(self):
def _test_bad_code_explanation(self, status_code, explanation):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'url': 'http://www.statuscode.com/',
'status-code': '301',
'ip-list': '127.0.0.1 127.0.0.2',
}
)
self.writeSurykatkaJson({
"http_query": [
{
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/"
},
{
"ip": "127.0.0.4",
"status_code": 301,
"url": "https://www.erp5.com/"
}
],
"ssl_certificate": [
{
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": None
},
{
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": None
"status_code": status_code,
"url": "http://www.statuscode.com/"
}
],
"ssl_certificate": [],
"dns_query": [],
"tcp_server": [],
})
self.runAndAssertFailedMessage(
"http://www.statuscode.com/ : "
"dns_query: OK No check configured "
"tcp_server: OK No check configured "
"http_query: ERROR IP 127.0.0.1 expected status_code %s != 301 "
"ssl_certificate: OK No check needed "
"elapsed_time: OK No check configured" % (explanation,)
)
def test_bad_code_explanation_520(self):
self._test_bad_code_explanation(520, '520 (Too many redirects)')
def test_bad_code_explanation_523(self):
self._test_bad_code_explanation(523, '523 (Connection error)')
def test_bad_code_explanation_524(self):
self._test_bad_code_explanation(524, '524 (Connection timeout)')
def test_bad_code_explanation_526(self):
self._test_bad_code_explanation(526, '526 (SSL Error)')
def test_bad_ip(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'http://www.badip.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2',
}
)
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"http_query: ERROR IP 127.0.0.1 expected status_code 302 != 301 OK IP "
"127.0.0.4 status_code 301 "
"ssl_certificate: ERROR IP 127.0.0.1 no information ERROR IP 127.0.0.2 "
"no information "
"http://www.badip.com/ : "
"dns_query: ERROR resolver 1.2.3.4 expected 127.0.0.1 127.0.0.2 != "
"127.0.0.1 127.0.0.4 "
"tcp_server: OK IP 127.0.0.1:80 ERROR IP 127.0.0.2:80 "
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.4 "
"status_code 302 "
"ssl_certificate: OK No check needed "
"elapsed_time: OK No check configured"
)
def test_https_no_cert(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.sslcertnoinfo.com/',
'status-code': '301',
}
)
self.runAndAssertFailedMessage(
"https://www.sslcertnoinfo.com/ : "
"dns_query: OK No check configured "
"tcp_server: OK No check configured "
"http_query: OK IP 127.0.0.1 status_code 301 "
"ssl_certificate: ERROR IP 127.0.0.1 no information "
"elapsed_time: OK No check configured"
)
......@@ -1548,29 +867,17 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'url': 'http://www.dnsquerynoentry.com/',
'status-code': '301',
'ip-list': '127.0.0.1 127.0.0.2',
'ip-list': '127.0.0.1'
}
)
self.writeSurykatkaJson({
"http_query": [
],
"ssl_certificate": [
],
"dns_query": [],
"tcp_server": [],
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
self.runAndAssertFailedMessage(
"http://www.dnsquerynoentry.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"http_query: ERROR No data "
"ssl_certificate: ERROR No data "
"ssl_certificate: OK No check needed "
"elapsed_time: ERROR No data"
)
......@@ -1579,9 +886,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'url': 'http://www.dnsquerynokey.com/',
'status-code': '301',
'ip-list': '127.0.0.1 127.0.0.2',
'ip-list': '127.0.0.1',
}
)
self.writeSurykatkaJson({
......@@ -1591,16 +898,12 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
],
"tcp_server": []
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
self.runAndAssertFailedMessage(
"http://www.dnsquerynokey.com/ : "
"dns_query: ERROR 'dns_query' not in %(json_file)r "
"tcp_server: ERROR No data "
"http_query: ERROR No data "
"ssl_certificate: ERROR No data "
"ssl_certificate: OK No check needed "
"elapsed_time: ERROR No data" % {'json_file': self.json_file}
)
......@@ -1609,44 +912,20 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
{
'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',
'url': 'http://www.httpallok.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.9',
}
)
self.writeSurykatkaJson({
"http_query": [
],
"ssl_certificate": [
],
"dns_query": [
{
"domain": "www.erp5.com",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.2, 127.0.0.3"
},
{
"domain": "www.erp5.org",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
},
],
"tcp_server": []
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"dns_query: ERROR resolver 1.2.3.4 expected 127.0.0.1 127.0.0.2 != "
"127.0.0.2 127.0.0.3 "
"tcp_server: ERROR No data "
"http_query: ERROR No data "
"ssl_certificate: ERROR No data "
"elapsed_time: ERROR No data"
self.runAndAssertFailedMessage(
"http://www.httpallok.com/ : "
"dns_query: ERROR resolver 1.2.3.4 expected 127.0.0.1 127.0.0.9 != "
"127.0.0.1 127.0.0.2 "
"tcp_server: OK IP 127.0.0.1:80 ERROR IP 127.0.0.9:80 "
"http_query: OK IP 127.0.0.1 status_code 302 OK IP 127.0.0.2 "
"status_code 302 "
"ssl_certificate: OK No check needed "
"elapsed_time: OK No check configured"
)
def test_dns_query_no_reply(self):
......@@ -1654,56 +933,18 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'url': 'http://www.dnsquerynoreply.com/',
'status-code': '301',
'ip-list': '127.0.0.1 127.0.0.2',
'ip-list': '127.0.0.1',
}
)
self.writeSurykatkaJson({
"http_query": [
],
"ssl_certificate": [
],
"dns_query": [
{
"domain": "www.erp5.com",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": ""
},
{
"domain": "www.erp5.org",
"rdtype": "A",
"resolver_ip": "1.2.3.4",
"response": "127.0.0.1, 127.0.0.2"
},
],
"tcp_server": [
{
"ip": "127.0.0.1",
"state": "open",
"port": 443,
"domain": "www.erp5.com"
},
{
"ip": "127.0.0.2",
"state": "open",
"port": 443,
"domain": "www.erp5.com"
},
]
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
"dns_query: ERROR resolver 1.2.3.4 expected 127.0.0.1 127.0.0.2 != "
self.runAndAssertFailedMessage(
"http://www.dnsquerynoreply.com/ : "
"dns_query: ERROR resolver 1.2.3.4 expected 127.0.0.1 != "
"empty-reply "
"tcp_server: OK IP 127.0.0.1:443 OK IP 127.0.0.2:443 "
"tcp_server: ERROR No data "
"http_query: ERROR No data "
"ssl_certificate: ERROR No data "
"ssl_certificate: OK No check needed "
"elapsed_time: ERROR No data"
)
......@@ -1712,88 +953,36 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'url': 'http://www.tcpservernoip.com/',
'status-code': '301',
'ip-list': '127.0.0.1 127.0.0.2',
'ip-list': '127.0.0.1',
}
)
self.writeSurykatkaJson({
"http_query": [
],
"ssl_certificate": [
],
"dns_query": [
],
"tcp_server": [
{
"ip": "127.0.0.3",
"state": "filtered",
"port": 443,
"domain": "www.erp5.com"
},
{
"ip": "127.0.0.4",
"state": "open",
"port": 80,
"domain": "www.erp5.com"
},
]
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
self.runAndAssertFailedMessage(
"http://www.tcpservernoip.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR IP 127.0.0.1:443 ERROR IP 127.0.0.2:443 "
"tcp_server: ERROR IP 127.0.0.1:80 "
"http_query: ERROR No data "
"ssl_certificate: ERROR No data "
"ssl_certificate: OK No check needed "
"elapsed_time: ERROR No data"
)
def test_tcp_server_mismatch(self):
def test_tcp_server_filtered(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'url': 'http://www.tcpserverfiltered.com/',
'status-code': '301',
'ip-list': '127.0.0.1 127.0.0.2',
'ip-list': '127.0.0.1',
}
)
self.writeSurykatkaJson({
"http_query": [
],
"ssl_certificate": [
],
"dns_query": [
],
"tcp_server": [
{
"ip": "127.0.0.1",
"state": "filtered",
"port": 443,
"domain": "www.erp5.com"
},
{
"ip": "127.0.0.2",
"state": "open",
"port": 80,
"domain": "www.erp5.com"
},
]
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
self.runAndAssertFailedMessage(
"http://www.tcpserverfiltered.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR IP 127.0.0.1:443 ERROR IP 127.0.0.2:443 "
"tcp_server: ERROR IP 127.0.0.1:80 "
"http_query: ERROR No data "
"ssl_certificate: ERROR No data "
"ssl_certificate: OK No check needed "
"elapsed_time: ERROR No data"
)
......@@ -1802,31 +991,17 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'url': 'http://www.tcpservernoentry.com/',
'status-code': '301',
'ip-list': '127.0.0.1 127.0.0.2',
'ip-list': '127.0.0.1',
}
)
self.writeSurykatkaJson({
"http_query": [
],
"ssl_certificate": [
],
"dns_query": [
],
"tcp_server": [
]
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
self.runAndAssertFailedMessage(
"http://www.tcpservernoentry.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR No data "
"http_query: ERROR No data "
"ssl_certificate: ERROR No data "
"ssl_certificate: OK No check needed "
"elapsed_time: ERROR No data"
)
......@@ -1835,9 +1010,9 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'url': 'http://www.tcpservernokey.com/',
'status-code': '301',
'ip-list': '127.0.0.1 127.0.0.2',
'ip-list': '127.0.0.1',
}
)
self.writeSurykatkaJson({
......@@ -1848,15 +1023,11 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
"dns_query": [
],
})
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : "
self.runAndAssertFailedMessage(
"http://www.tcpservernokey.com/ : "
"dns_query: ERROR No data "
"tcp_server: ERROR 'tcp_server' not in %(json_file)r "
"http_query: ERROR No data "
"ssl_certificate: ERROR No data "
"ssl_certificate: OK No check needed "
"elapsed_time: ERROR No data" % {'json_file': self.json_file}
)
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