2019-02-20 16:15:56 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-02-28 10:58:49 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
2019-02-20 16:15:56 +01:00
|
|
|
import unittest
|
2019-02-22 10:18:44 +01:00
|
|
|
|
2019-02-28 10:58:49 +01:00
|
|
|
from pymisp import MISPEvent
|
2019-02-22 10:18:44 +01:00
|
|
|
|
2019-03-01 09:06:01 +01:00
|
|
|
manual_testing = False
|
2019-02-25 15:49:53 +01:00
|
|
|
|
2019-05-07 11:04:25 +02:00
|
|
|
import logging
|
|
|
|
logging.disable(logging.CRITICAL)
|
|
|
|
|
2019-03-12 16:05:03 +01:00
|
|
|
try:
|
|
|
|
from pymisp.tools import reportlab_generator
|
2019-03-12 16:22:36 +01:00
|
|
|
except Exception:
|
2019-03-12 16:05:03 +01:00
|
|
|
if sys.version_info < (3, 6):
|
|
|
|
print('This test suite requires Python 3.6+, breaking.')
|
|
|
|
sys.exit(0)
|
|
|
|
else:
|
|
|
|
raise
|
2019-02-20 16:15:56 +01:00
|
|
|
|
2019-03-12 16:05:03 +01:00
|
|
|
|
|
|
|
class TestPDFExport(unittest.TestCase):
|
2019-02-20 16:15:56 +01:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.maxDiff = None
|
|
|
|
self.mispevent = MISPEvent()
|
2019-02-28 10:58:49 +01:00
|
|
|
if not manual_testing:
|
2019-02-25 15:49:53 +01:00
|
|
|
self.root = "tests/"
|
2019-02-28 10:58:49 +01:00
|
|
|
else:
|
2019-02-25 15:49:53 +01:00
|
|
|
self.root = ""
|
|
|
|
self.test_folder = self.root + "reportlab_testfiles/"
|
|
|
|
self.test_batch_folder = self.root + "OSINT_output/"
|
2019-02-28 10:58:49 +01:00
|
|
|
self.storage_folder_OSINT = self.root + "OSINT_PDF/"
|
2019-02-26 14:03:25 +01:00
|
|
|
self.test_image_folder = self.root + "image_json/"
|
2019-02-25 15:49:53 +01:00
|
|
|
self.storage_folder = self.root + "reportlab_testoutputs/"
|
2019-02-26 14:03:25 +01:00
|
|
|
self.storage_image_folder = self.root + "reportlab_test_image_outputs/"
|
2019-02-28 10:58:49 +01:00
|
|
|
self.moduleconfig = ["MISP_base_url_for_dynamic_link", "MISP_name_for_metadata", "Activate_textual_description",
|
2019-03-05 11:37:01 +01:00
|
|
|
"Activate_galaxy_description", "Activate_related_events", "Activate_internationalization_fonts", "Custom_fonts_path"]
|
2019-02-20 16:15:56 +01:00
|
|
|
|
|
|
|
def init_event(self):
|
|
|
|
self.mispevent.info = 'This is a test'
|
|
|
|
self.mispevent.distribution = 1
|
|
|
|
self.mispevent.threat_level_id = 1
|
|
|
|
self.mispevent.analysis = 1
|
|
|
|
self.mispevent.set_date("2017-12-31") # test the set date method
|
|
|
|
|
2019-02-22 17:47:22 +01:00
|
|
|
def check_python_2(self):
|
|
|
|
if sys.version_info.major < 3:
|
|
|
|
# we want Python2 test to pass
|
2019-02-25 15:49:53 +01:00
|
|
|
return True
|
2019-02-22 17:47:22 +01:00
|
|
|
|
2019-02-20 16:15:56 +01:00
|
|
|
def test_basic_event(self):
|
2019-02-25 15:49:53 +01:00
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
self.init_event()
|
|
|
|
reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent),
|
|
|
|
self.storage_folder + "basic_event.pdf")
|
2019-02-20 16:15:56 +01:00
|
|
|
|
|
|
|
def test_event(self):
|
2019-02-25 15:49:53 +01:00
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
self.init_event()
|
|
|
|
self.mispevent.load_file(self.test_folder + 'to_delete1.json')
|
|
|
|
reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent),
|
2019-02-26 15:35:40 +01:00
|
|
|
self.storage_folder + "normal_event.pdf")
|
2019-02-20 16:15:56 +01:00
|
|
|
|
2019-02-22 17:47:22 +01:00
|
|
|
def test_HTML_json(self):
|
2019-02-25 15:49:53 +01:00
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
self.init_event()
|
2019-02-26 15:35:40 +01:00
|
|
|
self.mispevent.load_file(self.test_folder + 'HTML_event.json')
|
2019-02-25 15:49:53 +01:00
|
|
|
reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent),
|
2019-02-26 15:35:40 +01:00
|
|
|
self.storage_folder + "HTML_event.pdf")
|
2019-02-22 17:47:22 +01:00
|
|
|
|
|
|
|
def test_long_json(self):
|
2019-02-25 15:49:53 +01:00
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
self.init_event()
|
2019-02-26 15:35:40 +01:00
|
|
|
self.mispevent.load_file(self.test_folder + 'long_event.json')
|
2019-02-25 15:49:53 +01:00
|
|
|
reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent),
|
2019-02-26 15:35:40 +01:00
|
|
|
self.storage_folder + "long_event.pdf")
|
2019-02-25 15:49:53 +01:00
|
|
|
# Issue report : "We are not smart enough" : https://pairlist2.pair.net/pipermail/reportlab-users/2010-May/009529.html
|
2019-02-26 15:35:40 +01:00
|
|
|
# Not nice but working solution exposed there: https://pairlist2.pair.net/pipermail/reportlab-users/2016-March/011525.html
|
2019-02-22 17:47:22 +01:00
|
|
|
|
|
|
|
def test_very_long_json(self):
|
2019-02-25 15:49:53 +01:00
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
self.init_event()
|
2019-02-26 15:35:40 +01:00
|
|
|
self.mispevent.load_file(self.test_folder + 'very_long_event.json')
|
2019-02-25 15:49:53 +01:00
|
|
|
reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent),
|
2019-02-26 15:35:40 +01:00
|
|
|
self.storage_folder + "very_long_event.pdf")
|
2019-02-25 15:49:53 +01:00
|
|
|
|
|
|
|
def test_full_config_json(self):
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
|
|
|
|
config = {}
|
2019-02-27 11:48:56 +01:00
|
|
|
config[self.moduleconfig[0]] = "http://localhost:8080"
|
2019-02-28 10:58:49 +01:00
|
|
|
config[self.moduleconfig[1]] = "My Wonderful CERT"
|
2019-02-25 15:49:53 +01:00
|
|
|
|
|
|
|
self.init_event()
|
2019-02-26 15:35:40 +01:00
|
|
|
self.mispevent.load_file(self.test_folder + 'very_long_event.json')
|
2019-02-28 10:58:49 +01:00
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
|
|
|
self.storage_folder + "config_complete_event.pdf")
|
2019-02-25 15:49:53 +01:00
|
|
|
|
|
|
|
def test_partial_0_config_json(self):
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
|
|
|
|
config = {}
|
2019-02-27 11:48:56 +01:00
|
|
|
config[self.moduleconfig[0]] = "http://localhost:8080"
|
2019-02-25 15:49:53 +01:00
|
|
|
|
|
|
|
self.init_event()
|
2019-02-26 15:35:40 +01:00
|
|
|
self.mispevent.load_file(self.test_folder + 'very_long_event.json')
|
2019-02-28 10:58:49 +01:00
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
|
|
|
self.storage_folder + "config_partial_0_event.pdf")
|
2019-02-25 15:49:53 +01:00
|
|
|
|
|
|
|
def test_partial_1_config_json(self):
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
|
|
|
|
config = {}
|
2019-02-28 10:58:49 +01:00
|
|
|
config[self.moduleconfig[1]] = "My Wonderful CERT"
|
2019-02-25 15:49:53 +01:00
|
|
|
|
|
|
|
self.init_event()
|
2019-02-26 15:35:40 +01:00
|
|
|
self.mispevent.load_file(self.test_folder + 'very_long_event.json')
|
2019-02-28 10:58:49 +01:00
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
|
|
|
self.storage_folder + "config_partial_1_event.pdf")
|
2019-02-25 15:49:53 +01:00
|
|
|
|
2019-02-26 11:13:24 +01:00
|
|
|
def test_image_json(self):
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
|
|
|
|
config = {}
|
2019-02-27 11:48:56 +01:00
|
|
|
config[self.moduleconfig[0]] = "http://localhost:8080"
|
2019-02-28 10:58:49 +01:00
|
|
|
config[self.moduleconfig[1]] = "My Wonderful CERT"
|
2019-02-26 11:13:24 +01:00
|
|
|
|
|
|
|
self.init_event()
|
|
|
|
self.mispevent.load_file(self.test_folder + 'image_event.json')
|
2019-02-28 10:58:49 +01:00
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
|
|
|
self.storage_folder + "image_event.pdf")
|
2019-02-26 11:13:24 +01:00
|
|
|
|
2019-02-26 15:35:40 +01:00
|
|
|
def test_objects_1_json(self):
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
|
|
|
|
config = {}
|
2019-02-27 11:48:56 +01:00
|
|
|
config[self.moduleconfig[0]] = "http://localhost:8080"
|
2019-02-28 10:58:49 +01:00
|
|
|
config[self.moduleconfig[1]] = "My Wonderful CERT"
|
2019-02-26 15:35:40 +01:00
|
|
|
|
|
|
|
self.init_event()
|
|
|
|
self.mispevent.load_file(self.test_folder + 'mainly_objects_1.json')
|
2019-02-28 10:58:49 +01:00
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
|
|
|
self.storage_folder + "mainly_objects_1.pdf")
|
2019-02-26 15:35:40 +01:00
|
|
|
|
|
|
|
def test_objects_2_json(self):
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
|
|
|
|
config = {}
|
2019-02-27 11:48:56 +01:00
|
|
|
config[self.moduleconfig[0]] = "http://localhost:8080"
|
2019-02-28 10:58:49 +01:00
|
|
|
config[self.moduleconfig[1]] = "My Wonderful CERT"
|
2019-02-26 15:35:40 +01:00
|
|
|
|
|
|
|
self.init_event()
|
|
|
|
self.mispevent.load_file(self.test_folder + 'mainly_objects_2.json')
|
2019-02-28 10:58:49 +01:00
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
|
|
|
self.storage_folder + "mainly_objects_2.pdf")
|
2019-02-26 15:35:40 +01:00
|
|
|
|
2019-02-27 11:48:56 +01:00
|
|
|
def test_sightings_1_json(self):
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
|
|
|
|
config = {}
|
|
|
|
config[self.moduleconfig[0]] = "http://localhost:8080"
|
2019-02-28 10:58:49 +01:00
|
|
|
config[self.moduleconfig[1]] = "My Wonderful CERT"
|
2019-02-27 11:48:56 +01:00
|
|
|
|
|
|
|
self.init_event()
|
|
|
|
self.mispevent.load_file(self.test_folder + 'sighting_1.json')
|
2019-02-28 10:58:49 +01:00
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
|
|
|
self.storage_folder + "sighting_1.pdf")
|
2019-02-27 11:48:56 +01:00
|
|
|
|
|
|
|
def test_sightings_2_json(self):
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
|
|
|
|
config = {}
|
|
|
|
config[self.moduleconfig[0]] = "http://localhost:8080"
|
2019-02-28 10:58:49 +01:00
|
|
|
config[self.moduleconfig[1]] = "My Wonderful CERT"
|
2019-02-27 11:48:56 +01:00
|
|
|
|
|
|
|
self.init_event()
|
|
|
|
self.mispevent.load_file(self.test_folder + 'sighting_2.json')
|
2019-02-28 10:58:49 +01:00
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
|
|
|
self.storage_folder + "sighting_2.pdf")
|
2019-02-27 11:48:56 +01:00
|
|
|
|
|
|
|
def test_textual_json(self):
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
|
|
|
|
config = {}
|
|
|
|
config[self.moduleconfig[0]] = "http://localhost:8080"
|
2019-02-28 10:58:49 +01:00
|
|
|
config[self.moduleconfig[1]] = "My Wonderful CERT"
|
|
|
|
config[self.moduleconfig[2]] = True
|
2019-02-27 11:48:56 +01:00
|
|
|
|
|
|
|
self.init_event()
|
|
|
|
self.mispevent.load_file(self.test_folder + 'very_long_event.json')
|
2019-02-28 10:58:49 +01:00
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
|
|
|
self.storage_folder + "textual.pdf")
|
2019-02-27 11:48:56 +01:00
|
|
|
|
2019-02-28 10:58:49 +01:00
|
|
|
def test_galaxy_1(self):
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
config = {}
|
|
|
|
config[self.moduleconfig[0]] = "http://localhost:8080"
|
|
|
|
config[self.moduleconfig[1]] = "My Wonderful CERT"
|
|
|
|
config[self.moduleconfig[2]] = True
|
|
|
|
config[self.moduleconfig[3]] = True
|
|
|
|
|
|
|
|
self.init_event()
|
|
|
|
self.mispevent.load_file(self.test_folder + 'galaxy_1.json')
|
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
|
|
|
self.storage_folder + "galaxy_1.pdf")
|
2019-02-26 14:03:25 +01:00
|
|
|
|
2019-03-05 01:06:38 +01:00
|
|
|
def test_related_events(self):
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
config = {}
|
|
|
|
config[self.moduleconfig[0]] = "http://localhost:8080"
|
|
|
|
config[self.moduleconfig[1]] = "My Wonderful CERT"
|
|
|
|
config[self.moduleconfig[2]] = True
|
|
|
|
config[self.moduleconfig[3]] = True
|
|
|
|
config[self.moduleconfig[4]] = True
|
|
|
|
|
|
|
|
self.init_event()
|
|
|
|
self.mispevent.load_file(self.test_folder + 'galaxy_1.json')
|
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
|
|
|
self.storage_folder + "related_events.pdf")
|
|
|
|
|
|
|
|
def test_related_events_too_simple(self):
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
config = {}
|
|
|
|
config[self.moduleconfig[0]] = "http://localhost:8080"
|
|
|
|
config[self.moduleconfig[1]] = "My Wonderful CERT"
|
|
|
|
config[self.moduleconfig[2]] = True
|
|
|
|
config[self.moduleconfig[3]] = True
|
|
|
|
config[self.moduleconfig[4]] = True
|
|
|
|
|
|
|
|
self.init_event()
|
|
|
|
self.mispevent.load_file(self.test_folder + 'to_delete1.json')
|
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
|
|
|
self.storage_folder + "related_events_no_related.pdf")
|
|
|
|
|
|
|
|
def test_utf(self):
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
config = {}
|
|
|
|
config[self.moduleconfig[0]] = "http://localhost:8080"
|
|
|
|
config[self.moduleconfig[1]] = "My Wonderful CERT"
|
|
|
|
config[self.moduleconfig[2]] = True
|
|
|
|
config[self.moduleconfig[3]] = True
|
|
|
|
config[self.moduleconfig[4]] = True
|
|
|
|
config[self.moduleconfig[5]] = True
|
|
|
|
|
|
|
|
self.init_event()
|
|
|
|
self.mispevent.load_file(self.test_folder + 'japanese_test.json')
|
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
|
|
|
self.storage_folder + "japanese_test.pdf")
|
|
|
|
|
2019-03-05 11:37:01 +01:00
|
|
|
def test_utf_heavy(self):
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
config = {}
|
|
|
|
config[self.moduleconfig[0]] = "http://localhost:8080"
|
|
|
|
config[self.moduleconfig[1]] = "My Wonderful CERT"
|
|
|
|
config[self.moduleconfig[2]] = True
|
|
|
|
config[self.moduleconfig[3]] = True
|
|
|
|
config[self.moduleconfig[4]] = True
|
|
|
|
config[self.moduleconfig[5]] = True
|
|
|
|
|
|
|
|
self.init_event()
|
|
|
|
self.mispevent.load_file(self.test_folder + 'japanese_test_heavy.json')
|
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
|
|
|
self.storage_folder + "japanese_test_heavy.pdf")
|
|
|
|
|
|
|
|
def test_utf_ArialUNI_custompath(self):
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
|
|
|
elif not manual_testing:
|
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
config = {}
|
|
|
|
config[self.moduleconfig[0]] = "http://localhost:8080"
|
|
|
|
config[self.moduleconfig[1]] = "My Wonderful CERT"
|
|
|
|
config[self.moduleconfig[2]] = True
|
|
|
|
config[self.moduleconfig[3]] = True
|
|
|
|
config[self.moduleconfig[4]] = True
|
|
|
|
config[self.moduleconfig[5]] = True
|
|
|
|
config[self.moduleconfig[6]] = "/home/user/Desktop/PyMISP/pymisp/tools/pdf_fonts/arial-unicode-ms/ARIALUNI.TTF"
|
|
|
|
|
|
|
|
self.init_event()
|
|
|
|
self.mispevent.load_file(self.test_folder + 'japanese_test_heavy.json')
|
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
|
|
|
self.storage_folder + "custom_path.pdf")
|
|
|
|
|
2019-02-26 14:03:25 +01:00
|
|
|
def test_batch_image_events(self):
|
|
|
|
# Test case ONLY for manual testing. Needs to download a full list of image events !
|
|
|
|
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
2019-02-28 10:58:49 +01:00
|
|
|
elif not manual_testing:
|
2019-02-26 14:03:25 +01:00
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
self.init_event()
|
|
|
|
|
|
|
|
file_nb = str(len(os.listdir(self.test_image_folder)))
|
|
|
|
i = 0
|
|
|
|
t = time.time()
|
|
|
|
for curr_file in os.listdir(self.test_image_folder):
|
|
|
|
self.mispevent = MISPEvent()
|
|
|
|
file_path = self.test_image_folder + curr_file
|
|
|
|
|
|
|
|
print("Current file : " + file_path + " " + str(i) + " over " + file_nb)
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
self.mispevent.load_file(file_path)
|
|
|
|
|
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent),
|
|
|
|
self.storage_image_folder + curr_file + ".pdf")
|
|
|
|
print("Elapsed time : " + str(time.time() - t))
|
2019-02-26 15:35:40 +01:00
|
|
|
# Local run : 73.061s for 102 files
|
2019-02-26 14:03:25 +01:00
|
|
|
|
2019-02-25 15:49:53 +01:00
|
|
|
def test_batch_OSINT_events(self):
|
|
|
|
# Test case ONLY for manual testing. Needs to download a full list of OSINT events !
|
|
|
|
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
2019-02-28 10:58:49 +01:00
|
|
|
elif not manual_testing:
|
2019-02-25 15:49:53 +01:00
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
self.init_event()
|
|
|
|
|
|
|
|
file_nb = str(len(os.listdir(self.test_batch_folder)))
|
|
|
|
i = 0
|
|
|
|
t = time.time()
|
|
|
|
for curr_file in os.listdir(self.test_batch_folder):
|
|
|
|
self.mispevent = MISPEvent()
|
|
|
|
file_path = self.test_batch_folder + curr_file
|
|
|
|
|
|
|
|
print("Current file : " + file_path + " " + str(i) + " over " + file_nb)
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
self.mispevent.load_file(file_path)
|
|
|
|
|
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent),
|
2019-02-28 10:58:49 +01:00
|
|
|
self.storage_folder_OSINT + curr_file + ".pdf")
|
2019-02-25 15:49:53 +01:00
|
|
|
print("Elapsed time : " + str(time.time() - t))
|
2019-02-26 11:13:24 +01:00
|
|
|
# Local run : 1958.930s for 1064 files
|
2019-02-27 11:48:56 +01:00
|
|
|
|
|
|
|
def test_batch_OSINT_with_config_events(self):
|
|
|
|
# Test case ONLY for manual testing. Needs to download a full list of OSINT events !
|
|
|
|
|
|
|
|
if self.check_python_2():
|
|
|
|
self.assertTrue(True)
|
2019-02-28 10:58:49 +01:00
|
|
|
elif not manual_testing:
|
2019-02-27 11:48:56 +01:00
|
|
|
self.assertTrue(True)
|
|
|
|
else:
|
|
|
|
self.init_event()
|
|
|
|
|
|
|
|
config = {}
|
|
|
|
config[self.moduleconfig[0]] = "http://localhost:8080"
|
2019-02-28 10:58:49 +01:00
|
|
|
config[self.moduleconfig[1]] = "My Wonderful CERT"
|
|
|
|
config[self.moduleconfig[2]] = True
|
2019-03-01 09:06:01 +01:00
|
|
|
config[self.moduleconfig[3]] = True
|
2019-03-05 01:06:38 +01:00
|
|
|
config[self.moduleconfig[4]] = True
|
|
|
|
config[self.moduleconfig[5]] = True
|
2019-03-01 09:06:01 +01:00
|
|
|
|
2019-02-27 11:48:56 +01:00
|
|
|
file_nb = str(len(os.listdir(self.test_batch_folder)))
|
|
|
|
i = 0
|
|
|
|
t = time.time()
|
|
|
|
for curr_file in os.listdir(self.test_batch_folder):
|
|
|
|
self.mispevent = MISPEvent()
|
|
|
|
file_path = self.test_batch_folder + curr_file
|
|
|
|
|
|
|
|
print("Current file : " + file_path + " " + str(i) + " over " + file_nb)
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
self.mispevent.load_file(file_path)
|
|
|
|
|
|
|
|
reportlab_generator.register_value_to_file(
|
|
|
|
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
|
2019-02-28 10:58:49 +01:00
|
|
|
self.storage_folder_OSINT + curr_file + ".pdf")
|
2019-02-27 11:48:56 +01:00
|
|
|
print("Elapsed time : " + str(time.time() - t))
|
2019-02-28 10:58:49 +01:00
|
|
|
# Local run : 1513.283s for 1064 files
|