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