mirror of https://github.com/MISP/misp-modules
31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
|
import os
|
||
|
import unittest
|
||
|
import requests
|
||
|
|
||
|
|
||
|
class TestImports(unittest.TestCase):
|
||
|
"""Unittest module for import modules"""
|
||
|
def setUp(self):
|
||
|
self.headers = {'Content-Type': 'application/json'}
|
||
|
self.url = "http://127.0.0.1:6666/"
|
||
|
|
||
|
def test_introspection(self):
|
||
|
"""checks if all import modules are offered through the misp-modules service"""
|
||
|
try:
|
||
|
response = requests.get(self.url + "modules")
|
||
|
modules = [module["name"] for module in response.json()]
|
||
|
# list modules in the export_mod folder
|
||
|
export_mod_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'misp_modules', 'modules', "import_mod")
|
||
|
module_files = [file[:-3] for file in os.listdir(export_mod_path) if file.endswith(".py") if file not in ['__init__.py', 'testimport.py']]
|
||
|
missing = []
|
||
|
for module in module_files:
|
||
|
if module not in modules:
|
||
|
missing.append(module)
|
||
|
self.assertEqual(missing, [], f"Missing modules in __init__: {missing}")
|
||
|
finally:
|
||
|
response.connection.close()
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
unittest.main()
|