mirror of https://github.com/MISP/PyTaxonomies
Package misp-taxonomies
parent
e072d30d66
commit
67063b62bb
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "pytaxonomies/data/misp-taxonomies"]
|
||||||
|
path = pytaxonomies/data/misp-taxonomies
|
||||||
|
url = https://github.com/MISP/misp-taxonomies.git
|
|
@ -188,7 +188,7 @@ class Taxonomy(collections.Mapping):
|
||||||
class Taxonomies(collections.Mapping):
|
class Taxonomies(collections.Mapping):
|
||||||
|
|
||||||
def __init__(self, manifest_url='https://raw.githubusercontent.com/MISP/misp-taxonomies/master/MANIFEST.json',
|
def __init__(self, manifest_url='https://raw.githubusercontent.com/MISP/misp-taxonomies/master/MANIFEST.json',
|
||||||
manifest_path=None):
|
manifest_path=os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data', 'misp-taxonomies', 'MANIFEST.json')):
|
||||||
if manifest_path:
|
if manifest_path:
|
||||||
self.loader = self.__load_path
|
self.loader = self.__load_path
|
||||||
self.manifest = self.loader(manifest_path)
|
self.manifest = self.loader(manifest_path)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 2723592e2d4d8d179b3cfea161a87412e5604068
|
2
setup.py
2
setup.py
|
@ -26,4 +26,6 @@ setup(
|
||||||
tests_requires=['nose'],
|
tests_requires=['nose'],
|
||||||
test_suite='nose.collector',
|
test_suite='nose.collector',
|
||||||
install_requires=['requests'],
|
install_requires=['requests'],
|
||||||
|
package_data={'pytaxonomies': ['data/misp-taxonomies/schema.json', 'data/misp-taxonomies/MANIFEST.json',
|
||||||
|
'data/misp-taxonomies/*/machinetag.json']}
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,46 +11,37 @@ import os
|
||||||
class TestPyTaxonomies(unittest.TestCase):
|
class TestPyTaxonomies(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.taxonomies = Taxonomies()
|
self.taxonomies_offline = Taxonomies()
|
||||||
self.manifest_path = "./misp-taxonomies/MANIFEST.json"
|
|
||||||
self.taxonomies_offline = Taxonomies(manifest_path=self.manifest_path)
|
|
||||||
self.json_load_taxonomies()
|
|
||||||
|
|
||||||
def __load_path(self, path):
|
|
||||||
with open(path, 'r') as f:
|
|
||||||
return json.load(f)
|
|
||||||
|
|
||||||
def json_load_taxonomies(self):
|
|
||||||
self.manifest = self.__load_path(self.manifest_path)
|
|
||||||
self.loaded_tax = {}
|
self.loaded_tax = {}
|
||||||
for t in self.manifest['taxonomies']:
|
for t in self.taxonomies_offline.manifest['taxonomies']:
|
||||||
path = '{}/{}/{}'.format(os.path.dirname(os.path.realpath(self.manifest_path)), t['name'], self.manifest['path'])
|
with open('{}/{}/{}'.format(self.taxonomies_offline.url, t['name'], 'machinetag.json'), 'r') as f:
|
||||||
self.loaded_tax[t['name']] = self.__load_path(path)
|
self.loaded_tax[t['name']] = json.load(f)
|
||||||
|
|
||||||
def test_compareOnlineOffilne(self):
|
def test_compareOnlineOffilne(self):
|
||||||
self.assertEqual(str(self.taxonomies), str(self.taxonomies_offline))
|
taxonomies_online = Taxonomies(manifest_path=None)
|
||||||
|
self.assertEqual(str(taxonomies_online), str(self.taxonomies_offline))
|
||||||
|
|
||||||
def test_expanded_machinetags(self):
|
def test_expanded_machinetags(self):
|
||||||
self.taxonomies.all_machinetags(expanded=True)
|
self.taxonomies_offline.all_machinetags(expanded=True)
|
||||||
|
|
||||||
def test_machinetags(self):
|
def test_machinetags(self):
|
||||||
self.taxonomies.all_machinetags()
|
self.taxonomies_offline.all_machinetags()
|
||||||
|
|
||||||
def test_dict(self):
|
def test_dict(self):
|
||||||
len(self.taxonomies)
|
len(self.taxonomies_offline)
|
||||||
for n, t in self.taxonomies.items():
|
for n, t in self.taxonomies_offline.items():
|
||||||
len(t)
|
len(t)
|
||||||
for p, value in t.items():
|
for p, value in t.items():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
def test_search(self):
|
def test_search(self):
|
||||||
self.taxonomies.search('phish')
|
self.taxonomies_offline.search('phish')
|
||||||
|
|
||||||
def test_search_expanded(self):
|
def test_search_expanded(self):
|
||||||
self.taxonomies.search('phish', expanded=True)
|
self.taxonomies_offline.search('phish', expanded=True)
|
||||||
|
|
||||||
def test_print_classes(self):
|
def test_print_classes(self):
|
||||||
for taxonomy in self.taxonomies.values():
|
for taxonomy in self.taxonomies_offline.values():
|
||||||
print(taxonomy)
|
print(taxonomy)
|
||||||
for predicate in taxonomy.values():
|
for predicate in taxonomy.values():
|
||||||
print(predicate)
|
print(predicate)
|
||||||
|
@ -58,36 +49,35 @@ class TestPyTaxonomies(unittest.TestCase):
|
||||||
print(entry)
|
print(entry)
|
||||||
|
|
||||||
def test_amountEntries(self):
|
def test_amountEntries(self):
|
||||||
for tax in self.taxonomies.values():
|
for tax in self.taxonomies_offline.values():
|
||||||
tax.amount_entries()
|
tax.amount_entries()
|
||||||
|
|
||||||
def test_missingDependency(self):
|
def test_missingDependency(self):
|
||||||
pytaxonomies.api.HAS_REQUESTS = False
|
pytaxonomies.api.HAS_REQUESTS = False
|
||||||
with self.assertRaises(Exception):
|
with self.assertRaises(Exception):
|
||||||
Taxonomies()
|
Taxonomies(manifest_path=None)
|
||||||
Taxonomies(manifest_path="./misp-taxonomies/MANIFEST.json")
|
Taxonomies()
|
||||||
pytaxonomies.api.HAS_REQUESTS = True
|
pytaxonomies.api.HAS_REQUESTS = True
|
||||||
|
|
||||||
def test_revert_machinetags(self):
|
def test_revert_machinetags(self):
|
||||||
for tax in self.taxonomies.values():
|
for tax in self.taxonomies_offline.values():
|
||||||
for p in tax.values():
|
for p in tax.values():
|
||||||
if tax.has_entries():
|
if tax.has_entries():
|
||||||
for e in p.values():
|
for e in p.values():
|
||||||
mt = tax.make_machinetag(p, e)
|
mt = tax.make_machinetag(p, e)
|
||||||
self.taxonomies.revert_machinetag(mt)
|
self.taxonomies_offline.revert_machinetag(mt)
|
||||||
else:
|
else:
|
||||||
mt = tax.make_machinetag(p)
|
mt = tax.make_machinetag(p)
|
||||||
self.taxonomies.revert_machinetag(mt)
|
self.taxonomies_offline.revert_machinetag(mt)
|
||||||
|
|
||||||
def test_json(self):
|
def test_json(self):
|
||||||
for key, t in self.taxonomies.items():
|
for key, t in self.taxonomies_offline.items():
|
||||||
json.dumps(t, cls=EncodeTaxonomies)
|
json.dumps(t, cls=EncodeTaxonomies)
|
||||||
|
|
||||||
def test_recreate_dump(self):
|
def test_recreate_dump(self):
|
||||||
self.maxDiff = None
|
self.maxDiff = None
|
||||||
for key, t in self.taxonomies.items():
|
for key, t in self.taxonomies_offline.items():
|
||||||
out = t._json()
|
out = t._json()
|
||||||
print(t.name)
|
|
||||||
self.assertCountEqual(out, self.loaded_tax[t.name])
|
self.assertCountEqual(out, self.loaded_tax[t.name])
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue