Merge pull request #352 from Vincent-CIRCL/master

chg: [exportpdf] Add image and objects handling + testcases
pull/362/head
Alexandre Dulaunoy 2019-02-26 15:55:30 +01:00 committed by GitHub
commit 62e047f3c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 4865 additions and 57 deletions

View File

@ -12,6 +12,7 @@ import sys
if sys.version_info.major >= 3:
from html import escape
# import PIL
else:
print(
"ExportPDF running with Python < 3 : stability and output not guaranteed. Please run exportPDF with at least Python3")
@ -24,8 +25,9 @@ try:
from reportlab.pdfbase.pdfmetrics import stringWidth
from reportlab.pdfbase.pdfdoc import PDFDictionary, PDFInfo
from reportlab.lib import colors
from reportlab.lib.utils import ImageReader
from reportlab.platypus import SimpleDocTemplate, Paragraph, PageBreak, Spacer, Table, TableStyle, Flowable
from reportlab.platypus import SimpleDocTemplate, Paragraph, PageBreak, Spacer, Table, TableStyle, Flowable, Image
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import mm
@ -159,10 +161,16 @@ FRAME_MAX_HEIGHT = 500 # 650 # Ad hoc value for a A4 page
FRAME_MAX_WIDTH = 356
STR_TOO_LONG_WARNING = "<br/><b><font color=red>[Too long to fit on a single page. Cropped]</font></b>"
# == Parameters for error handling for image too big to fit on a page ==
FRAME_PICTURE_MAX_WIDTH = 88 * mm
FRAME_PICTURE_MAX_HEIGHT = 195 * mm
# == Parameters for links management ==
LINK_TYPE = "link" # Name of the type that define 'good' links
URL_TYPE = "url" # Name of the type that define 'bad' links
IMAGE_TYPE = "attachment" # /!\ Not only pictures ! Can be PDF, ...
WARNING_MESSAGE_URL = "'https://Please_consider_that_this_may_be_a_harmful_link'"
NOT_A_PICTURE_MESSAGE = "This attachment is not recognized as an image. Please access this attachment directly from your MISP instance."
GOOD_LINK_COLOR = 'blue'
BAD_LINK_COLOR = 'red'
@ -301,11 +309,11 @@ def get_value_link_to_event(misp_event, item, col2_style, config=None, color=Tru
'''
# Does MispEven has the attribute ?
if hasattr(misp_event, item[1]):
if is_safe_attribute(misp_event, item[1]):
# It has the requested attribute .. building upon it.
# Does misp_object has an uuid and do we know the baseurl ?
if hasattr(misp_event, "uuid") and config is not None and moduleconfig[0] in config:
if is_safe_attribute(misp_event, "uuid") and config is not None and moduleconfig[0] in config:
# We can build links
curr_uuid = str(getattr(misp_event, "uuid"))
curr_baseurl = config[moduleconfig[0]]
@ -340,7 +348,7 @@ def get_timestamp_value(misp_event, item, col2_style):
:param col2_style: style to be applied on the returned paragraph
:return: a Paragraph to add in the pdf, regarding the values of "timestamp"
'''
if hasattr(misp_event, item[1]):
if is_safe_attribute(misp_event, item[1]):
return Paragraph(str(getattr(misp_event, item[1]).strftime(EXPORT_DATE_FORMAT)), col2_style)
return Paragraph(item[2], col2_style)
@ -355,7 +363,7 @@ def get_creator_organisation_value(misp_event, item, col2_style):
:param col2_style: style to be applied on the returned paragraph
:return: a Paragraph to add in the pdf, regarding the values of "creator organisation"
'''
if hasattr(misp_event, item[1]):
if is_safe_attribute(misp_event, item[1]):
return Paragraph(safe_string(getattr(getattr(misp_event, item[1]), item[3])), col2_style)
return Paragraph(item[2], col2_style)
@ -370,7 +378,7 @@ def get_attributes_number_value(misp_event, item, col2_style):
:param col2_style: style to be applied on the returned paragraph
:return: a Paragraph to add in the pdf, regarding the values of "attributes"
'''
if hasattr(misp_event, item[1]):
if is_safe_attribute(misp_event, item[1]):
return Paragraph(str(len(getattr(misp_event, item[1]))), col2_style)
return Paragraph(item[2], col2_style)
@ -385,7 +393,7 @@ def get_tag_value(misp_event, item, col2_style):
:param col2_style: style to be applied on the returned paragraph
:return: a Paragraph to add in the pdf, regarding the values of "tags"
'''
if hasattr(misp_event, item[1]):
if is_safe_attribute_table(misp_event, item[1]):
table_event_tags = create_flowable_table_from_tags(misp_event)
return table_event_tags
return Paragraph(item[2], col2_style)
@ -410,24 +418,23 @@ def get_published_value(misp_event, item, col2_style):
YES_ANSWER = "<font color=" + GREEN_COLOR + "><b> Yes </b></font> ("
NO_ANSWER = "<font color=" + RED_COLOR + "><b>No</b></font>"
answer = ""
# Formatting similar to MISP Event web view
if hasattr(misp_event, item[1]):
if is_safe_attribute(misp_event, item[1]):
if getattr(misp_event, item[1]): # == True
if hasattr(misp_event, item[3]):
if is_safe_attribute(misp_event, item[3]):
# Published and have published date
answer = Paragraph(YES_ANSWER + getattr(misp_event, item[3]).strftime(EXPORT_DATE_FORMAT) + ")",
col2_style)
else:
# Published without published date
answer = YES_ANSWER + "no date)"
answer = Paragraph(YES_ANSWER + "no date)", col2_style)
else:
# Not published
answer = NO_ANSWER
answer = Paragraph(NO_ANSWER, col2_style)
else:
# Does not have a published attribute
answer = item[2]
answer = Paragraph(item[2], col2_style)
return answer
@ -436,6 +443,9 @@ def is_safe_attribute(curr_object, attribute_name):
return hasattr(curr_object, attribute_name) and getattr(curr_object, attribute_name) is not None and getattr(
curr_object, attribute_name) != ""
def is_safe_attribute_table(curr_object, attribute_name):
return hasattr(curr_object, attribute_name) and getattr(curr_object, attribute_name) is not None and getattr(
curr_object, attribute_name) != []
def create_flowable_table_from_one_attribute(misp_attribute):
'''
@ -456,8 +466,8 @@ def create_flowable_table_from_one_attribute(misp_attribute):
# Handle the special case of links
STANDARD_TYPE = True
if hasattr(misp_attribute, 'type') and (
getattr(misp_attribute, 'type') == LINK_TYPE or getattr(misp_attribute, 'type') == URL_TYPE):
if is_safe_attribute(misp_attribute, 'type') and (getattr(misp_attribute, 'type') in [LINK_TYPE, URL_TYPE]):
# getattr(misp_attribute, 'type') == LINK_TYPE or getattr(misp_attribute, 'type') == URL_TYPE):
# Special case for links
STANDARD_TYPE = False
@ -471,30 +481,69 @@ def create_flowable_table_from_one_attribute(misp_attribute):
# The attribute does not exist, you may want to print a default text on the row. Then use as a else case :
# data.append([Paragraph(item[0], col1_style), Paragraph(item[2], col2_style)])
# Handle Special case for links (Value)
if not STANDARD_TYPE:
item = ["Value", 'value', "None"]
# Handle Special case for links (Value) - There were not written in the previous loop
item = ["Value", 'value', "None"]
if not STANDARD_TYPE and is_safe_attribute(misp_attribute, item[1]):
data.append([Paragraph(item[0], col1_style), get_good_or_bad_link(misp_attribute, item, col2_style)])
if is_safe_attribute(misp_attribute, item[1]):
if getattr(misp_attribute, 'type') == LINK_TYPE:
data.append([Paragraph(item[0], col1_style), get_unoverflowable_paragraph(
"<font color=" + GOOD_LINK_COLOR + "><a href=" + getattr(misp_attribute, item[1]) + ">" + getattr(
misp_attribute, item[1]) + "</a></font>", col2_style, False)])
elif getattr(misp_attribute, 'type') == URL_TYPE:
data.append([Paragraph(item[0], col1_style), get_unoverflowable_paragraph(
"<font color=" + BAD_LINK_COLOR + "><a href=" + WARNING_MESSAGE_URL + ">" + getattr(misp_attribute,
item[
1]) + "</a></font>",
col2_style, False)])
# Handle pictures
item = ["Data", 'data', "None"]
if is_safe_attribute(misp_attribute, item[1]) and getattr(misp_attribute, 'type') == IMAGE_TYPE:
data.append([Paragraph(item[0], col1_style), get_image_value(misp_attribute, item, col2_style)])
# Tags
item = ["Tags", 'Tag', "None"]
if hasattr(misp_attribute, item[1]):
if is_safe_attribute_table(misp_attribute, item[1]):
data.append([Paragraph(item[0], col1_style), get_tag_value(misp_attribute, item, col2_style)])
return create_flowable_table_from_data(data)
def create_flowable_table_from_one_object(misp_object):
'''
Returns a table (flowable) representing the object
:param misp_attribute: A misp object
:return: a table representing this misp's object's attributes, to add to the pdf as a flowable
'''
data = []
col1_style, col2_style = get_table_styles()
# To reduce code size, and automate it a bit, triplet (Displayed Name, object_attribute_name,
# to_display_if_not_present) are store in the following list
list_attr_automated = [["UUID", 'uuid', "None"],
["Description", 'description', "None"],
["Meta Category", 'meta-category', "None"],
["Object Name", 'name', "None"],
["Comment", 'comment', "None"],
["Type", 'type', "None"]]
# Automated adding of standard (python) attributes of the misp object
for item in list_attr_automated:
if is_safe_attribute(misp_object, item[1]):
# The attribute exists, we fetch it and create the row
data.append([Paragraph(item[0], col1_style),
get_unoverflowable_paragraph(getattr(misp_object, item[1]), col2_style)])
# The attribute does not exist, you may want to print a default text on the row. Then use as a else case :
# data.append([Paragraph(item[0], col1_style), Paragraph(item[2], col2_style)])
# Timestamp
item = ["Object date", 'timestamp', "None"]
data.append([Paragraph(item[0], col1_style), get_timestamp_value(misp_object, item, col2_style)])
# Transform list of value in a table
data = [create_flowable_table_from_data(data)]
# Handle all the attributes
if is_safe_attribute(misp_object, "Attribute"):
data += create_flowable_table_from_attributes(misp_object)
# Add a page break at the end of an object
data.append(PageBreak())
return data
def create_tags_table_from_data(data):
'''
Given a list of flowables tags (2D/list of list), creates a Table with styles adapted to tags.
@ -514,6 +563,85 @@ def create_tags_table_from_data(data):
return curr_table
def get_good_link(misp_attribute, item, col2_style):
'''
Returns a flowable paragraph to add to the pdf given the misp_attribute value, if this is a link
:param misp_attribute: A misp attribute with a link
:param item: a list of name, in order :
["Name to be print in the pdf", "json property access name",
" Name to be display if no values found in the misp_event"]
:param col2_style: style to be applied on the returned paragraph
:return: a Paragraph to add in the pdf, regarding the values of this "link" attribute
'''
return get_unoverflowable_paragraph(
"<font color=" + GOOD_LINK_COLOR + "><a href=" + getattr(misp_attribute, item[1]) + ">" + getattr(
misp_attribute, item[1]) + "</a></font>", col2_style, False)
def get_bad_link(misp_attribute, item, col2_style):
'''
Returns a flowable paragraph to add to the pdf given the misp_attribute value, if this is a link
:param misp_attribute: A misp event with an url
:param item: a list of name, in order :
["Name to be print in the pdf", "json property access name",
" Name to be display if no values found in the misp_event"]
:param col2_style: style to be applied on the returned paragraph
:return: a Paragraph to add in the pdf, regarding the values of this "url" attribute
'''
return get_unoverflowable_paragraph(
"<font color=" + BAD_LINK_COLOR + "><a href=" + WARNING_MESSAGE_URL + ">" + getattr(misp_attribute,
item[1]) + "</a></font>",
col2_style, False)
def get_good_or_bad_link(misp_attribute, item, col2_style):
'''
Returns a flowable paragraph to add to the pdf given the misp_attribute value, if this is a link or an url
:param misp_attribute: A misp attribute with a link or an url
:param item: a list of name, in order :
["Name to be print in the pdf", "json property access name",
" Name to be display if no values found in the misp_event"]
:param col2_style: style to be applied on the returned paragraph
:return: a Paragraph to add in the pdf, regarding the values of this "link" or "url" attribute
'''
# Handle "Good" links
if getattr(misp_attribute, 'type') == LINK_TYPE:
answer = get_good_link(misp_attribute, item, col2_style)
# Handle "bad "links
elif getattr(misp_attribute, 'type') == URL_TYPE:
answer = get_bad_link(misp_attribute, item, col2_style)
return answer
def get_image_value(misp_attribute, item, col2_style):
'''
Returns a flowable image to add to the pdf given the misp attribute type and data
:param misp_attribute: A misp attribute with type="attachement" and data
:param item: a list of name, in order :
["Name to be print in the pdf", "json property access name",
" Name to be display if no values found in the misp_event"]
:param col2_style: style to be applied on the returned paragraph
:return: a flowable image to add in the pdf, regarding the values of "data"
'''
try:
# Get the image
buf = getattr(misp_attribute, item[1])
# Create image within a bounded box (to allow pdf creation)
img = Image(buf, width=FRAME_PICTURE_MAX_WIDTH, height=FRAME_PICTURE_MAX_HEIGHT, kind='bound')
answer = img
except OSError:
logger.error(
"Trying to add an attachment during PDF export generation. Attachement joining failed. Attachement may not be an image.")
answer = get_unoverflowable_paragraph(
"<font color=" + BAD_LINK_COLOR + ">" + NOT_A_PICTURE_MESSAGE + "</font>", col2_style, False)
return answer
########################################################################
# General attribut formater
@ -689,16 +817,16 @@ def create_flowable_table_from_attributes(misp_event):
sample_style_sheet = getSampleStyleSheet()
i = 0
if hasattr(misp_event, "Attribute"):
if is_safe_attribute_table(misp_event, "Attribute"):
# There is some attributes for this object
for item in getattr(misp_event, "Attribute"):
# you can use a spacer instead of title to separate paragraph: flowable_table.append(Spacer(1, 5 * mm))
flowable_table.append(Paragraph("Attribute #" + str(i), sample_style_sheet['Heading3']))
flowable_table.append(Paragraph("Attribute #" + str(i), sample_style_sheet['Heading4']))
flowable_table.append(create_flowable_table_from_one_attribute(item))
i += 1
else:
# No attributes for this object
flowable_table.append(Paragraph("No attributes", sample_style_sheet['Heading2']))
flowable_table.append(Paragraph("No attributes", sample_style_sheet['Heading4']))
return flowable_table
@ -714,7 +842,7 @@ def create_flowable_table_from_tags(misp_event):
col1_style, col2_style = get_table_styles()
i = 0
if hasattr(misp_event, "Tag") and len(getattr(misp_event, "Tag")) > 1: # 'Tag' can exist and be empty
if is_safe_attribute_table(misp_event, "Tag") : # and len(getattr(misp_event, "Tag")) > 1: # 'Tag' can exist and be empty
# There is some tags for this object
for item in getattr(misp_event, "Tag"):
flowable_table.append(create_flowable_tag(item))
@ -727,6 +855,34 @@ def create_flowable_table_from_tags(misp_event):
return answer_tags
def create_flowable_table_from_objects(misp_event):
'''
Returns a list of flowables representing the list of objects of a misp event.
The list is composed of a serie of
[ header object, table of object information, [ header of attribute, table of attribute]*] to add to the pdf
:param misp_event: A misp event
:return: a table of flowables
'''
flowable_table = []
sample_style_sheet = getSampleStyleSheet()
i = 0
if is_safe_attribute_table(misp_event, "Object"):
# There is a list of objects
for item in getattr(misp_event, "Object"):
# you can use a spacer instead of title to separate paragraph: flowable_table.append(Spacer(1, 5 * mm))
flowable_table.append(Paragraph("Object #" + str(i), sample_style_sheet['Heading3']))
flowable_table += create_flowable_table_from_one_object(item)
i += 1
else:
# No object found
flowable_table.append(Paragraph("No object", sample_style_sheet['Heading3']))
return flowable_table
########################################################################
# Handling static parts drawn on the upper layer
@ -802,12 +958,20 @@ def collect_parts(misp_event, config=None):
sample_style_sheet = getSampleStyleSheet()
# Create stuff
title = get_value_link_to_event(misp_event, ["Info", 'info', "None"], sample_style_sheet['Heading1'], config, False)
subtitle = Paragraph("General information", sample_style_sheet['Heading2'])
attributes = Paragraph("Attributes", sample_style_sheet['Heading2'])
title_style = ParagraphStyle(name='Column_1', parent=sample_style_sheet['Heading1'], alignment=TA_CENTER)
title = get_value_link_to_event(misp_event, ["Info", 'info', "None"], title_style, config, False)
table_event_general = create_flowable_table_from_event(misp_event, config)
table_event_attribute = create_flowable_table_from_attributes(misp_event)
subtitle = Paragraph("General information", sample_style_sheet['Heading2'])
table_general_metainformation = create_flowable_table_from_event(misp_event, config)
event_attributes_title = Paragraph("Attributes", sample_style_sheet['Heading2'])
table_direct_attributes = create_flowable_table_from_attributes(misp_event)
event_objects_title = Paragraph("Objects", sample_style_sheet['Heading2'])
table_objects = create_flowable_table_from_objects(misp_event)
event_sighting_title = Paragraph("Sighting", sample_style_sheet['Heading2'])
# TODO : table_event_sightings = create_flowable_table_from_sightings(misp_event)
# If you want to output the full json (as debug), just add next line
# paragraph_2 = Paragraph(str(misp_event.to_json()), sample_style_sheet['Code'])
@ -815,12 +979,20 @@ def collect_parts(misp_event, config=None):
# Add all parts to final PDF
flowables.append(title)
flowables.append(subtitle)
flowables.append(table_event_general)
flowables.append(table_general_metainformation)
flowables.append(PageBreak())
flowables.append(attributes)
flowables += table_event_attribute
flowables.append(event_attributes_title)
flowables += table_direct_attributes
flowables.append(PageBreak())
flowables.append(event_objects_title)
flowables += table_objects
# TODO : flowables.append(PageBreak())
# TODO : flowables.append(event_sighting_title)
# TODO : flowables += table_event_sightings
return flowables

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -23,7 +23,9 @@ class TestMISPEvent(unittest.TestCase):
self.root = ""
self.test_folder = self.root + "reportlab_testfiles/"
self.test_batch_folder = self.root + "OSINT_output/"
self.test_image_folder = self.root + "image_json/"
self.storage_folder = self.root + "reportlab_testoutputs/"
self.storage_image_folder = self.root + "reportlab_test_image_outputs/"
def init_event(self):
self.mispevent.info = 'This is a test'
@ -52,36 +54,36 @@ class TestMISPEvent(unittest.TestCase):
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),
self.storage_folder + "basic_event.pdf")
self.storage_folder + "normal_event.pdf")
def test_HTML_json(self):
if self.check_python_2():
self.assertTrue(True)
else:
self.init_event()
self.mispevent.load_file(self.test_folder + '56e12e66-f01c-41be-afea-4d9a950d210f.json')
self.mispevent.load_file(self.test_folder + 'HTML_event.json')
reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent),
self.storage_folder + "HTML.pdf")
self.storage_folder + "HTML_event.pdf")
def test_long_json(self):
if self.check_python_2():
self.assertTrue(True)
else:
self.init_event()
self.mispevent.load_file(self.test_folder + '57153590-f73c-49fa-be4b-4737950d210f.json')
self.mispevent.load_file(self.test_folder + 'long_event.json')
reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent),
self.storage_folder + "long.pdf")
self.storage_folder + "long_event.pdf")
# Issue report : "We are not smart enough" : https://pairlist2.pair.net/pipermail/reportlab-users/2010-May/009529.html
# Not nice but working solution exposed ther e: https://pairlist2.pair.net/pipermail/reportlab-users/2016-March/011525.html
# Not nice but working solution exposed there: https://pairlist2.pair.net/pipermail/reportlab-users/2016-March/011525.html
def test_very_long_json(self):
if self.check_python_2():
self.assertTrue(True)
else:
self.init_event()
self.mispevent.load_file(self.test_folder + '5abf6421-c1b8-477b-a9d2-9c0902de0b81.json')
self.mispevent.load_file(self.test_folder + 'very_long_event.json')
reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent),
self.storage_folder + "very_long.pdf")
self.storage_folder + "very_long_event.pdf")
def test_full_config_json(self):
if self.check_python_2():
@ -94,9 +96,9 @@ class TestMISPEvent(unittest.TestCase):
config[moduleconfig[1]] = "My Wonderful CERT"
self.init_event()
self.mispevent.load_file(self.test_folder + '5abf6421-c1b8-477b-a9d2-9c0902de0b81.json')
self.mispevent.load_file(self.test_folder + 'very_long_event.json')
reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
self.storage_folder + "config_complete.pdf")
self.storage_folder + "config_complete_event.pdf")
def test_partial_0_config_json(self):
if self.check_python_2():
@ -108,9 +110,9 @@ class TestMISPEvent(unittest.TestCase):
config[moduleconfig[0]] = "http://localhost:8080"
self.init_event()
self.mispevent.load_file(self.test_folder + '5abf6421-c1b8-477b-a9d2-9c0902de0b81.json')
self.mispevent.load_file(self.test_folder + 'very_long_event.json')
reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
self.storage_folder + "config_partial_0.pdf")
self.storage_folder + "config_partial_0_event.pdf")
def test_partial_1_config_json(self):
if self.check_python_2():
@ -122,9 +124,83 @@ class TestMISPEvent(unittest.TestCase):
config[moduleconfig[1]] = "My Wonderful CERT"
self.init_event()
self.mispevent.load_file(self.test_folder + '5abf6421-c1b8-477b-a9d2-9c0902de0b81.json')
self.mispevent.load_file(self.test_folder + 'very_long_event.json')
reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
self.storage_folder + "config_partial_1.pdf")
self.storage_folder + "config_partial_1_event.pdf")
def test_image_json(self):
if self.check_python_2():
self.assertTrue(True)
else:
config = {}
moduleconfig = ["MISP_base_url_for_dynamic_link", "MISP_name_for_metadata"]
config[moduleconfig[0]] = "http://localhost:8080"
config[moduleconfig[1]] = "My Wonderful CERT"
self.init_event()
self.mispevent.load_file(self.test_folder + 'image_event.json')
reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
self.storage_folder + "image_event.pdf")
def test_objects_1_json(self):
if self.check_python_2():
self.assertTrue(True)
else:
config = {}
moduleconfig = ["MISP_base_url_for_dynamic_link", "MISP_name_for_metadata"]
config[moduleconfig[0]] = "http://localhost:8080"
config[moduleconfig[1]] = "My Wonderful CERT"
self.init_event()
self.mispevent.load_file(self.test_folder + 'mainly_objects_1.json')
reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
self.storage_folder + "mainly_objects_1.pdf")
def test_objects_2_json(self):
if self.check_python_2():
self.assertTrue(True)
else:
config = {}
moduleconfig = ["MISP_base_url_for_dynamic_link", "MISP_name_for_metadata"]
config[moduleconfig[0]] = "http://localhost:8080"
config[moduleconfig[1]] = "My Wonderful CERT"
self.init_event()
self.mispevent.load_file(self.test_folder + 'mainly_objects_2.json')
reportlab_generator.register_value_to_file(reportlab_generator.convert_event_in_pdf_buffer(self.mispevent, config),
self.storage_folder + "mainly_objects_2.pdf")
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)
elif not manual_testing :
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))
# Local run : 73.061s for 102 files
def test_batch_OSINT_events(self):
# Test case ONLY for manual testing. Needs to download a full list of OSINT events !
@ -152,3 +228,4 @@ class TestMISPEvent(unittest.TestCase):
reportlab_generator.convert_event_in_pdf_buffer(self.mispevent),
self.storage_folder + curr_file + ".pdf")
print("Elapsed time : " + str(time.time() - t))
# Local run : 1958.930s for 1064 files