PyMISPWarningLists/tests/tests.py

47 lines
1.7 KiB
Python
Raw Normal View History

2017-10-29 01:40:41 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
2017-11-01 00:06:50 +01:00
from pymispwarninglists import WarningLists
2017-10-29 01:40:41 +02:00
from glob import glob
import os
import json
class TestPyMISPWarningLists(unittest.TestCase):
def setUp(self):
self.warninglists = WarningLists()
def test_dump_warninglists(self):
warninglists_from_files = {}
for warninglist_file in glob(os.path.join(self.warninglists.root_dir_warninglists, '*', 'list.json')):
with open(warninglist_file, 'r') as f:
warninglist = json.load(f)
warninglists_from_files[warninglist['name']] = warninglist
for name, w in self.warninglists.items():
2017-11-01 00:06:50 +01:00
out = w.to_dict()
2017-10-29 01:40:41 +02:00
self.assertDictEqual(out, warninglists_from_files[w.name])
def test_validate_schema_warninglists(self):
self.warninglists.validate_with_schema()
def test_json(self):
for w in self.warninglists.values():
2017-11-01 00:06:50 +01:00
w.to_json()
def test_search(self):
results = self.warninglists.search('8.8.8.8')
self.assertEqual(results[0].name, 'List of known IPv4 public DNS resolvers')
2017-11-01 01:06:50 +01:00
def test_slow_search(self):
self.warninglists = WarningLists(True)
results = self.warninglists.search('8.8.8.8')
self.assertEqual(results[0].name, 'List of known IPv4 public DNS resolvers')
results = self.warninglists.search('100.64.1.56')
self.assertEqual(results[0].name, 'List of RFC 6598 CIDR blocks')
results = self.warninglists.search('2001:DB8::34:1')
self.assertEqual(results[0].name, 'List of RFC 3849 CIDR blocks')
2017-11-01 01:28:54 +01:00
results = self.warninglists.search('1e100.net')
self.assertEqual(results[0].name, 'List of known google domains')