mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
Updates to match change in wizard names. Added improved exception checking.
This commit is contained in:
parent
98b53eb016
commit
b9715e7726
@ -9,6 +9,7 @@ import shutil
|
|||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
import xml
|
import xml
|
||||||
|
import re
|
||||||
from xml.dom.minidom import parse, parseString
|
from xml.dom.minidom import parse, parseString
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -253,7 +254,61 @@ class Database:
|
|||||||
for error in self.attribute_comparison:
|
for error in self.attribute_comparison:
|
||||||
list.append(error)
|
list.append(error)
|
||||||
return ";".join(list)
|
return ";".join(list)
|
||||||
|
|
||||||
|
def generate_autopsy_artifacts(self):
|
||||||
|
if not self.autopsy_artifacts:
|
||||||
|
autopsy_db_file = os.path.join("./", case.output_dir, case.image_name,
|
||||||
|
"AutopsyTestCase", "autopsy.db")
|
||||||
|
autopsy_con = sqlite3.connect(autopsy_db_file)
|
||||||
|
autopsy_cur = autopsy_con.cursor()
|
||||||
|
for type_id in range(1, 13):
|
||||||
|
autopsy_cur.execute("SELECT COUNT(*) FROM blackboard_artifacts WHERE artifact_type_id=%d" % type_id)
|
||||||
|
self.autopsy_artifacts.append(autopsy_cur.fetchone()[0])
|
||||||
|
|
||||||
|
def generate_autopsy_attributes(self):
|
||||||
|
if self.autopsy_attributes == 0:
|
||||||
|
autopsy_db_file = os.path.join("./", case.output_dir, case.image_name,
|
||||||
|
"AutopsyTestCase", "autopsy.db")
|
||||||
|
autopsy_con = sqlite3.connect(autopsy_db_file)
|
||||||
|
autopsy_cur = autopsy_con.cursor()
|
||||||
|
autopsy_cur.execute("SELECT COUNT(*) FROM blackboard_attributes")
|
||||||
|
autopsy_attributes = autopsy_cur.fetchone()[0]
|
||||||
|
self.autopsy_attributes = autopsy_attributes
|
||||||
|
|
||||||
|
def generate_autopsy_objects(self):
|
||||||
|
if self.autopsy_objects == 0:
|
||||||
|
autopsy_db_file = os.path.join("./", case.output_dir, case.image_name,
|
||||||
|
"AutopsyTestCase", "autopsy.db")
|
||||||
|
autopsy_con = sqlite3.connect(autopsy_db_file)
|
||||||
|
autopsy_cur = autopsy_con.cursor()
|
||||||
|
autopsy_cur.execute("SELECT COUNT(*) FROM tsk_objects")
|
||||||
|
autopsy_objects = autopsy_cur.fetchone()[0]
|
||||||
|
self.autopsy_objects = autopsy_objects
|
||||||
|
|
||||||
|
def generate_gold_artifacts(self):
|
||||||
|
if not self.gold_artifacts:
|
||||||
|
gold_db_file = os.path.join("./", case.gold, case.image_name, "standard.db")
|
||||||
|
gold_con = sqlite3.connect(gold_db_file)
|
||||||
|
gold_cur = gold_con.cursor()
|
||||||
|
for type_id in range(1, 13):
|
||||||
|
gold_cur.execute("SELECT COUNT(*) FROM blackboard_artifacts WHERE artifact_type_id=%d" % type_id)
|
||||||
|
self.gold_artifacts.append(gold_cur.fetchone()[0])
|
||||||
|
|
||||||
|
def generate_gold_attributes(self):
|
||||||
|
if self.gold_attributes == 0:
|
||||||
|
gold_db_file = os.path.join("./", case.gold, case.image_name, "standard.db")
|
||||||
|
gold_con = sqlite3.connect(gold_db_file)
|
||||||
|
gold_cur = gold_con.cursor()
|
||||||
|
gold_cur.execute("SELECT COUNT(*) FROM blackboard_attributes")
|
||||||
|
self.gold_attributes = gold_cur.fetchone()[0]
|
||||||
|
|
||||||
|
def generate_gold_objects(self):
|
||||||
|
if self.gold_objects == 0:
|
||||||
|
gold_db_file = os.path.join("./", case.gold, case.image_name, "standard.db")
|
||||||
|
gold_con = sqlite3.connect(gold_db_file)
|
||||||
|
gold_cur = gold_con.cursor()
|
||||||
|
gold_cur.execute("SELECT COUNT(*) FROM tsk_objects")
|
||||||
|
self.gold_objects = gold_cur.fetchone()[0]
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------#
|
#----------------------------------#
|
||||||
@ -262,7 +317,7 @@ class Database:
|
|||||||
|
|
||||||
# Iterates through an XML configuration file to find all given elements
|
# Iterates through an XML configuration file to find all given elements
|
||||||
def run_config_test(config_file):
|
def run_config_test(config_file):
|
||||||
#try:
|
try:
|
||||||
parsed = parse(config_file)
|
parsed = parse(config_file)
|
||||||
if parsed.getElementsByTagName("indir"):
|
if parsed.getElementsByTagName("indir"):
|
||||||
case.input_dir = parsed.getElementsByTagName("indir")[0].getAttribute("value").encode()
|
case.input_dir = parsed.getElementsByTagName("indir")[0].getAttribute("value").encode()
|
||||||
@ -285,9 +340,9 @@ def run_config_test(config_file):
|
|||||||
else:
|
else:
|
||||||
printerror("Warning: Image file listed in the configuration does not exist:")
|
printerror("Warning: Image file listed in the configuration does not exist:")
|
||||||
printerror(value + "\n")
|
printerror(value + "\n")
|
||||||
#except Exception as e:
|
except Exception as e:
|
||||||
#printerror("Error: There was an error running with the configuration file.")
|
printerror("Error: There was an error running with the configuration file.")
|
||||||
#printerror(str(e) + "\n")
|
printerror(str(e) + "\n")
|
||||||
|
|
||||||
# Runs the test on the single given file.
|
# Runs the test on the single given file.
|
||||||
# The path must be guarenteed to be a correct path.
|
# The path must be guarenteed to be a correct path.
|
||||||
@ -312,8 +367,6 @@ def run_test(image_file):
|
|||||||
generate_common_log()
|
generate_common_log()
|
||||||
try:
|
try:
|
||||||
fill_case_data()
|
fill_case_data()
|
||||||
except StringNotFoundException as e:
|
|
||||||
e.print_error()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
printerror("Error: Unknown fatal error when filling case data.")
|
printerror("Error: Unknown fatal error when filling case data.")
|
||||||
printerror(str(e) + "\n")
|
printerror(str(e) + "\n")
|
||||||
@ -324,8 +377,8 @@ def run_test(image_file):
|
|||||||
# If NOT keeping Solr index (-k)
|
# If NOT keeping Solr index (-k)
|
||||||
if not args.keep:
|
if not args.keep:
|
||||||
solr_index = make_local_path(case.output_dir, case.image_name, "AutopsyTestCase", "KeywordSearch")
|
solr_index = make_local_path(case.output_dir, case.image_name, "AutopsyTestCase", "KeywordSearch")
|
||||||
clear_dir(solr_index)
|
if clear_dir(solr_index):
|
||||||
print_report([], "DELETE SOLR INDEX", "Solr index deleted.")
|
print_report([], "DELETE SOLR INDEX", "Solr index deleted.")
|
||||||
elif args.keep:
|
elif args.keep:
|
||||||
print_report([], "KEEP SOLR INDEX", "Solr index has been kept.")
|
print_report([], "KEEP SOLR INDEX", "Solr index has been kept.")
|
||||||
# If running in verbose mode (-v)
|
# If running in verbose mode (-v)
|
||||||
@ -335,7 +388,7 @@ def run_test(image_file):
|
|||||||
print_report(errors, "VERBOSE", okay)
|
print_report(errors, "VERBOSE", okay)
|
||||||
# If running in exception mode (-e)
|
# If running in exception mode (-e)
|
||||||
if args.exception:
|
if args.exception:
|
||||||
exceptions = report_with(args.exception_string)
|
exceptions = search_logs(args.exception_string)
|
||||||
okay = "No warnings or exceptions found containing text '" + args.exception_string + "'."
|
okay = "No warnings or exceptions found containing text '" + args.exception_string + "'."
|
||||||
print_report(exceptions, "EXCEPTION", okay)
|
print_report(exceptions, "EXCEPTION", okay)
|
||||||
|
|
||||||
@ -455,6 +508,24 @@ def compare_to_gold_db():
|
|||||||
gold_db_file = os.path.join("./", case.gold, case.image_name, "standard.db")
|
gold_db_file = os.path.join("./", case.gold, case.image_name, "standard.db")
|
||||||
autopsy_db_file = os.path.join("./", case.output_dir, case.image_name,
|
autopsy_db_file = os.path.join("./", case.output_dir, case.image_name,
|
||||||
"AutopsyTestCase", "autopsy.db")
|
"AutopsyTestCase", "autopsy.db")
|
||||||
|
# Try to query the databases. Ignore any exceptions, the function will
|
||||||
|
# return an error later on if these do fail
|
||||||
|
database.clear()
|
||||||
|
try:
|
||||||
|
database.generate_gold_objects()
|
||||||
|
database.generate_gold_artifacts()
|
||||||
|
database.generate_gold_attributes()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
database.generate_autopsy_objects()
|
||||||
|
database.generate_autopsy_artifacts()
|
||||||
|
database.generate_autopsy_attributes()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
# This is where we return if a file doesn't exist, because we don't want to
|
||||||
|
# compare faulty databases, but we do however want to try to run all queries
|
||||||
|
# regardless of the other database
|
||||||
if not file_exists(autopsy_db_file):
|
if not file_exists(autopsy_db_file):
|
||||||
printerror("Error: Database file does not exist at:")
|
printerror("Error: Database file does not exist at:")
|
||||||
printerror(autopsy_db_file + "\n")
|
printerror(autopsy_db_file + "\n")
|
||||||
@ -471,13 +542,12 @@ def compare_to_gold_db():
|
|||||||
autopsy_cur = autopsy_con.cursor()
|
autopsy_cur = autopsy_con.cursor()
|
||||||
|
|
||||||
exceptions = []
|
exceptions = []
|
||||||
database.clear()
|
|
||||||
# Testing tsk_objects
|
# Testing tsk_objects
|
||||||
exceptions.append(compare_tsk_objects(gold_cur, autopsy_cur))
|
exceptions.append(compare_tsk_objects())
|
||||||
# Testing blackboard_artifacts
|
# Testing blackboard_artifacts
|
||||||
exceptions.append(compare_bb_artifacts(gold_cur, autopsy_cur))
|
exceptions.append(compare_bb_artifacts())
|
||||||
# Testing blackboard_attributes
|
# Testing blackboard_attributes
|
||||||
exceptions.append(compare_bb_attributes(gold_cur, autopsy_cur))
|
exceptions.append(compare_bb_attributes())
|
||||||
|
|
||||||
database.artifact_comparison = exceptions[1]
|
database.artifact_comparison = exceptions[1]
|
||||||
database.attribute_comparison = exceptions[2]
|
database.attribute_comparison = exceptions[2]
|
||||||
@ -516,61 +586,53 @@ def compare_to_gold_html():
|
|||||||
except DirNotFoundException as e:
|
except DirNotFoundException as e:
|
||||||
e.print_error()
|
e.print_error()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
printerror("Error: Unknown fatal error comparing databases.")
|
printerror("Error: Unknown fatal error comparing reports.")
|
||||||
printerror(str(e) + "\n")
|
printerror(str(e) + "\n")
|
||||||
|
|
||||||
# Compares the blackboard artifact counts of two databases
|
# Compares the blackboard artifact counts of two databases
|
||||||
# given the two database cursors
|
# given the two database cursors
|
||||||
def compare_bb_artifacts(gold_cur, autopsy_cur):
|
def compare_bb_artifacts():
|
||||||
exceptions = []
|
exceptions = []
|
||||||
for type_id in range(1, 13):
|
try:
|
||||||
gold_cur.execute("SELECT COUNT(*) FROM blackboard_artifacts WHERE artifact_type_id=%d" % type_id)
|
for type_id in range(1, 13):
|
||||||
gold_artifacts = gold_cur.fetchone()[0]
|
if database.gold_artifacts != database.autopsy_artifacts:
|
||||||
autopsy_cur.execute("SELECT COUNT(*) FROM blackboard_artifacts WHERE artifact_type_id=%d" % type_id)
|
error = str("Artifact counts do not match for type id %d. " % type_id)
|
||||||
autopsy_artifacts = autopsy_cur.fetchone()[0]
|
error += str("Gold: %d, Test: %d" %
|
||||||
# Append the results to the global database
|
(database.gold_artifacts[type_id],
|
||||||
database.gold_artifacts.append(gold_artifacts)
|
database.autopsy_artifacts[type_id]))
|
||||||
database.autopsy_artifacts.append(autopsy_artifacts)
|
exceptions.append(error)
|
||||||
# Report every discrepancy
|
return exceptions
|
||||||
if gold_artifacts != autopsy_artifacts:
|
except Exception as e:
|
||||||
error = str("Artifact counts do not match for type id %d. " % type_id)
|
exceptions.append("Error: Unable to compare blackboard_artifacts.\n")
|
||||||
error += str("Gold: %d, Test: %d" % (gold_artifacts, autopsy_artifacts))
|
return exceptions
|
||||||
exceptions.append(error)
|
|
||||||
return exceptions
|
|
||||||
|
|
||||||
# Compares the blackboard atribute counts of two databases
|
# Compares the blackboard atribute counts of two databases
|
||||||
# given the two database cursors
|
# given the two database cursors
|
||||||
def compare_bb_attributes(gold_cur, autopsy_cur):
|
def compare_bb_attributes():
|
||||||
exceptions = []
|
exceptions = []
|
||||||
gold_cur.execute("SELECT COUNT(*) FROM blackboard_attributes")
|
try:
|
||||||
gold_attributes = gold_cur.fetchone()[0]
|
if database.gold_attributes != database.autopsy_attributes:
|
||||||
autopsy_cur.execute("SELECT COUNT(*) FROM blackboard_attributes")
|
error = "Attribute counts do not match. "
|
||||||
autopsy_attributes = autopsy_cur.fetchone()[0]
|
error += str("Gold: %d, Test: %d" % (database.gold_attributes, database.autopsy_attributes))
|
||||||
# Give the database the attributes
|
exceptions.append(error)
|
||||||
database.gold_attributes = gold_attributes
|
return exceptions
|
||||||
database.autopsy_attributes = autopsy_attributes
|
except Exception as e:
|
||||||
if gold_attributes != autopsy_attributes:
|
exceptions.append("Error: Unable to compare blackboard_attributes.\n")
|
||||||
error = "Attribute counts do not match. "
|
return exceptions
|
||||||
error += str("Gold: %d, Test: %d" % (gold_attributes, autopsy_attributes))
|
|
||||||
exceptions.append(error)
|
|
||||||
return exceptions
|
|
||||||
|
|
||||||
# Compares the tsk object counts of two databases
|
# Compares the tsk object counts of two databases
|
||||||
# given the two database cursors
|
# given the two database cursors
|
||||||
def compare_tsk_objects(gold_cur, autopsy_cur):
|
def compare_tsk_objects():
|
||||||
exceptions = []
|
exceptions = []
|
||||||
gold_cur.execute("SELECT COUNT(*) FROM tsk_objects")
|
try:
|
||||||
gold_objects = gold_cur.fetchone()[0]
|
if database.gold_objects != database.autopsy_objects:
|
||||||
autopsy_cur.execute("SELECT COUNT(*) FROM tsk_objects")
|
error = "TSK Object counts do not match. "
|
||||||
autopsy_objects = autopsy_cur.fetchone()[0]
|
error += str("Gold: %d, Test: %d" % (database.gold_objects, database.autopsy_objects))
|
||||||
# Give the database the attributes
|
exceptions.append(error)
|
||||||
database.gold_objects = gold_objects
|
return exceptions
|
||||||
database.autopsy_objects = autopsy_objects
|
except Exception as e:
|
||||||
if gold_objects != autopsy_objects:
|
exceptions.append("Error: Unable to compare tsk_objects.\n")
|
||||||
error = "TSK Object counts do not match. "
|
return exceptions
|
||||||
error += str("Gold: %d, Test: %d" % (gold_objects, autopsy_objects))
|
|
||||||
exceptions.append(error)
|
|
||||||
return exceptions
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -581,22 +643,28 @@ def compare_tsk_objects(gold_cur, autopsy_cur):
|
|||||||
# Generate the "common log": a log of all exceptions and warnings
|
# Generate the "common log": a log of all exceptions and warnings
|
||||||
# from each log file generated by Autopsy
|
# from each log file generated by Autopsy
|
||||||
def generate_common_log():
|
def generate_common_log():
|
||||||
logs_path = make_local_path(case.output_dir, case.image_name, "logs")
|
try:
|
||||||
common_log = open(case.common_log, "a")
|
logs_path = make_local_path(case.output_dir, case.image_name, "logs")
|
||||||
common_log.write("--------------------------------------------------\n")
|
common_log = open(case.common_log, "a")
|
||||||
common_log.write(case.image_name + "\n")
|
common_log.write("--------------------------------------------------\n")
|
||||||
common_log.write("--------------------------------------------------\n")
|
common_log.write(case.image_name + "\n")
|
||||||
for file in os.listdir(logs_path):
|
common_log.write("--------------------------------------------------\n")
|
||||||
log = open(make_path(logs_path, file), "r")
|
for file in os.listdir(logs_path):
|
||||||
lines = log.readlines()
|
log = open(make_path(logs_path, file), "r")
|
||||||
for line in lines:
|
lines = log.readlines()
|
||||||
if ("exception" in line) or ("EXCEPTION" in line) or ("Exception" in line):
|
for line in lines:
|
||||||
common_log.write("From " + log.name[log.name.rfind("/")+1:] +":\n" + line + "\n")
|
if "exception" in line.lower():
|
||||||
if ("warning" in line) or ("WARNING" in line) or ("Warning" in line):
|
common_log.write("From " + log.name[log.name.rfind("/")+1:] +":\n" + line + "\n")
|
||||||
common_log.write("From " + log.name[log.name.rfind("/")+1:] +":\n" + line + "\n")
|
if "warning" in line.lower():
|
||||||
log.close()
|
common_log.write("From " + log.name[log.name.rfind("/")+1:] +":\n" + line + "\n")
|
||||||
common_log.write("\n\n")
|
if "error" in line.lower():
|
||||||
common_log.close()
|
common_log.write("From " + log.name[log.name.rfind("/")+1:] +":\n" + line + "\n")
|
||||||
|
log.close()
|
||||||
|
common_log.write("\n\n")
|
||||||
|
common_log.close()
|
||||||
|
except Exception as e:
|
||||||
|
printerror("Error: Unable to generate the common log.")
|
||||||
|
printerror(str(e))
|
||||||
|
|
||||||
# Fill in the global case's variables that require the log files
|
# Fill in the global case's variables that require the log files
|
||||||
def fill_case_data():
|
def fill_case_data():
|
||||||
@ -668,6 +736,8 @@ def generate_csv(csv_path):
|
|||||||
total_ingest_time = case.total_ingest_time
|
total_ingest_time = case.total_ingest_time
|
||||||
service_times = case.service_times
|
service_times = case.service_times
|
||||||
exceptions_count = str(len(get_exceptions()))
|
exceptions_count = str(len(get_exceptions()))
|
||||||
|
mem_exceptions_count = str(len(search_common_log("OutOfMemoryException")) +
|
||||||
|
len(search_common_log("OutOfMemoryError")))
|
||||||
tsk_objects_count = str(database.autopsy_objects)
|
tsk_objects_count = str(database.autopsy_objects)
|
||||||
artifacts_count = str(database.get_artifacts_count())
|
artifacts_count = str(database.get_artifacts_count())
|
||||||
attributes_count = str(database.autopsy_attributes)
|
attributes_count = str(database.autopsy_attributes)
|
||||||
@ -680,7 +750,7 @@ def generate_csv(csv_path):
|
|||||||
|
|
||||||
# Make a list with all the strings in it
|
# Make a list with all the strings in it
|
||||||
seq = (image_path, name, path, autopsy_version, heap_space, start_date, end_date, total_test_time,
|
seq = (image_path, name, path, autopsy_version, heap_space, start_date, end_date, total_test_time,
|
||||||
total_ingest_time, service_times, exceptions_count, tsk_objects_count, artifacts_count,
|
total_ingest_time, service_times, exceptions_count, mem_exceptions_count, tsk_objects_count, artifacts_count,
|
||||||
attributes_count, gold_db_name, artifact_comparison, attribute_comparison,
|
attributes_count, gold_db_name, artifact_comparison, attribute_comparison,
|
||||||
gold_report_name, report_comparison, ant)
|
gold_report_name, report_comparison, ant)
|
||||||
# Join it together with a ", "
|
# Join it together with a ", "
|
||||||
@ -689,10 +759,6 @@ def generate_csv(csv_path):
|
|||||||
# Write to the log!
|
# Write to the log!
|
||||||
csv.write(output)
|
csv.write(output)
|
||||||
csv.close()
|
csv.close()
|
||||||
except StringNotFoundException as e:
|
|
||||||
e.print_error()
|
|
||||||
printerror("Error: CSV file was not created at:")
|
|
||||||
printerror(csv_path + "\n")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
printerror("Error: Unknown fatal error when creating CSV file at:")
|
printerror("Error: Unknown fatal error when creating CSV file at:")
|
||||||
printerror(csv_path)
|
printerror(csv_path)
|
||||||
@ -703,7 +769,8 @@ def csv_header(csv_path):
|
|||||||
csv = open(csv_path, "w")
|
csv = open(csv_path, "w")
|
||||||
seq = ("Image Path", "Image Name", "Output Case Directory", "Autopsy Version",
|
seq = ("Image Path", "Image Name", "Output Case Directory", "Autopsy Version",
|
||||||
"Heap Space Setting", "Test Start Date", "Test End Date", "Total Test Time",
|
"Heap Space Setting", "Test Start Date", "Test End Date", "Total Test Time",
|
||||||
"Total Ingest Time", "Service Times", "Exceptions Count", "TSK Objects Count", "Artifacts Count",
|
"Total Ingest Time", "Service Times", "Exceptions Count", "OutOfMemoryExceptions",
|
||||||
|
"TSK Objects Count", "Artifacts Count",
|
||||||
"Attributes Count", "Gold Database Name", "Artifacts Comparison",
|
"Attributes Count", "Gold Database Name", "Artifacts Comparison",
|
||||||
"Attributes Comparison", "Gold Report Name", "Report Comparison", "Ant Command Line")
|
"Attributes Comparison", "Gold Report Name", "Report Comparison", "Ant Command Line")
|
||||||
output = "|".join(seq)
|
output = "|".join(seq)
|
||||||
@ -713,56 +780,50 @@ def csv_header(csv_path):
|
|||||||
|
|
||||||
# Returns a list of all the exceptions listed in the common log
|
# Returns a list of all the exceptions listed in the common log
|
||||||
def get_exceptions():
|
def get_exceptions():
|
||||||
try:
|
exceptions = []
|
||||||
exceptions = []
|
common_log = open(case.common_log, "r")
|
||||||
common_log = open(case.common_log, "r")
|
lines = common_log.readlines()
|
||||||
lines = common_log.readlines()
|
ex = re.compile("\SException")
|
||||||
for line in lines:
|
er = re.compile("\SError")
|
||||||
if ("exception" in line) or ("EXCEPTION" in line) or ("Exception" in line):
|
for line in lines:
|
||||||
exceptions.append(line)
|
if ex.search(line) or er.search(line):
|
||||||
common_log.close()
|
exceptions.append(line)
|
||||||
return exceptions
|
common_log.close()
|
||||||
except:
|
return exceptions
|
||||||
raise FileNotFoundExeption(case.common_log)
|
|
||||||
|
|
||||||
# Returns a list of all the warnings listed in the common log
|
# Returns a list of all the warnings listed in the common log
|
||||||
def get_warnings():
|
def get_warnings():
|
||||||
try:
|
warnings = []
|
||||||
warnings = []
|
common_log = open(case.common_log, "r")
|
||||||
common_log = open(case.common_log, "r")
|
lines = common_log.readlines()
|
||||||
lines = common_log.readlines()
|
for line in lines:
|
||||||
for line in lines:
|
if "warning" in line.lower():
|
||||||
if ("warning" in line) or ("WARNING" in line) or ("Warning" in line):
|
warnings.append(line)
|
||||||
warnings.append(line)
|
common_log.close()
|
||||||
common_log.close()
|
return warnings
|
||||||
return warnings
|
|
||||||
except:
|
|
||||||
raise FileNotFoundExeption(case.common_log)
|
|
||||||
|
|
||||||
# Returns all the errors found in the common log in a list
|
# Returns all the errors found in the common log in a list
|
||||||
def report_all_errors():
|
def report_all_errors():
|
||||||
try:
|
try:
|
||||||
return get_warnings() + get_exceptions()
|
return get_warnings() + get_exceptions()
|
||||||
except FileNotFoundException as e:
|
|
||||||
e.print_error()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
printerror("Error: Unknown fatal error when reporting all errors.")
|
printerror("Error: Unknown fatal error when reporting all errors.")
|
||||||
printerror(str(e) + "\n")
|
printerror(str(e) + "\n")
|
||||||
|
|
||||||
# Returns any lines from the common log with the given string in them (case sensitive)
|
# Searched all the known logs for the given regex
|
||||||
def report_with(exception):
|
# The function expects regex = re.compile(...)
|
||||||
try:
|
def regex_search_logs(regex):
|
||||||
exceptions = []
|
logs_path = make_local_path(case.output_dir, case.image_name, "logs")
|
||||||
common_log = open(case.common_log, "r")
|
results = []
|
||||||
lines = common_log.readlines()
|
for file in os.listdir(logs_path):
|
||||||
|
log = open(make_path(logs_path, file), "r")
|
||||||
|
lines = log.readlines()
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if exception in line:
|
if regex.search(line):
|
||||||
exceptions.append(line)
|
results.append(line)
|
||||||
common_log.close()
|
log.close()
|
||||||
return exceptions
|
if results:
|
||||||
except:
|
return results
|
||||||
printerror("Error: Cannot find the common log at:")
|
|
||||||
printerror(case.common_log + "\n")
|
|
||||||
|
|
||||||
# Search through all the known log files for a specific string.
|
# Search through all the known log files for a specific string.
|
||||||
# Returns a list of all lines with that string
|
# Returns a list of all lines with that string
|
||||||
@ -776,11 +837,18 @@ def search_logs(string):
|
|||||||
if string in line:
|
if string in line:
|
||||||
results.append(line)
|
results.append(line)
|
||||||
log.close()
|
log.close()
|
||||||
if results:
|
return results
|
||||||
return results
|
|
||||||
raise StringNotFoundException(string)
|
# Searches the common log for any instances of a specific string.
|
||||||
# Search through all the known log files for a specific string.
|
def search_common_log(string):
|
||||||
# Returns a list of all lines with that string
|
results = []
|
||||||
|
log = open(case.common_log, "r")
|
||||||
|
lines = log.readlines()
|
||||||
|
for line in lines:
|
||||||
|
if string in line:
|
||||||
|
results.append(line)
|
||||||
|
log.close()
|
||||||
|
return results
|
||||||
|
|
||||||
# Searches the given log for the given string
|
# Searches the given log for the given string
|
||||||
# Returns a list of all lines with that string
|
# Returns a list of all lines with that string
|
||||||
@ -796,7 +864,6 @@ def search_log(log, string):
|
|||||||
log.close()
|
log.close()
|
||||||
if results:
|
if results:
|
||||||
return results
|
return results
|
||||||
raise StringNotFoundException(string)
|
|
||||||
except:
|
except:
|
||||||
raise FileNotFoundException(logs_path)
|
raise FileNotFoundException(logs_path)
|
||||||
|
|
||||||
@ -829,82 +896,90 @@ def generate_html():
|
|||||||
# this test, so we need to make the start of the html log
|
# this test, so we need to make the start of the html log
|
||||||
if not file_exists(case.html_log):
|
if not file_exists(case.html_log):
|
||||||
write_html_head()
|
write_html_head()
|
||||||
html = open(case.html_log, "a")
|
try:
|
||||||
# The image title
|
html = open(case.html_log, "a")
|
||||||
title = "<h1><a name='" + case.image_name + "'>" + case.image_name + "</a></h1>\
|
# The image title
|
||||||
<h2 align='center'>\
|
title = "<h1><a name='" + case.image_name + "'>" + case.image_name + "</a></h1>\
|
||||||
<a href='#" + case.image_name + "-errors'>Errors and Warnings</a> |\
|
<h2 align='center'>\
|
||||||
<a href='#" + case.image_name + "-info'>Information</a> |\
|
<a href='#" + case.image_name + "-errors'>Errors and Warnings</a> |\
|
||||||
<a href='#" + case.image_name + "-general'>General Output</a>\
|
<a href='#" + case.image_name + "-info'>Information</a> |\
|
||||||
</h2>"
|
<a href='#" + case.image_name + "-general'>General Output</a>\
|
||||||
# The script errors found
|
</h2>"
|
||||||
errors = "<div id='errors'>\
|
# The script errors found
|
||||||
<h2><a name='" + case.image_name + "-errors'>Errors and Warnings</a></h2>\
|
errors = "<div id='errors'>\
|
||||||
<hr color='#FF0000'>"
|
<h2><a name='" + case.image_name + "-errors'>Errors and Warnings</a></h2>\
|
||||||
# For each error we have logged in the case
|
<hr color='#FF0000'>"
|
||||||
for error in case.printerror:
|
# For each error we have logged in the case
|
||||||
# Replace < and > to avoid any html display errors
|
for error in case.printerror:
|
||||||
errors += "<p>" + error.replace("<", "<").replace(">", ">") + "</p>"
|
# Replace < and > to avoid any html display errors
|
||||||
# If there is a \n, we probably want a <br /> in the html
|
errors += "<p>" + error.replace("<", "<").replace(">", ">") + "</p>"
|
||||||
if "\n" in error:
|
# If there is a \n, we probably want a <br /> in the html
|
||||||
errors += "<br />"
|
if "\n" in error:
|
||||||
errors += "</div>"
|
errors += "<br />"
|
||||||
# All the testing information
|
errors += "</div>"
|
||||||
info = "<div id='info'>\
|
# All the testing information
|
||||||
<h2><a name='" + case.image_name + "-info'>Information</a></h2>\
|
info = "<div id='info'>\
|
||||||
<hr color='#0005FF'>\
|
<h2><a name='" + case.image_name + "-info'>Information</a></h2>\
|
||||||
<table cellspacing='5px'>"
|
<hr color='#0005FF'>\
|
||||||
# The individual elements
|
<table cellspacing='5px'>"
|
||||||
info += "<tr><td>Image Path:</td>"
|
# The individual elements
|
||||||
info += "<td>" + case.image_file + "</td></tr>"
|
info += "<tr><td>Image Path:</td>"
|
||||||
info += "<tr><td>Image Name:</td>"
|
info += "<td>" + case.image_file + "</td></tr>"
|
||||||
info += "<td>" + case.image_name + "</td></tr>"
|
info += "<tr><td>Image Name:</td>"
|
||||||
info += "<tr><td>Case Output Directory:</td>"
|
info += "<td>" + case.image_name + "</td></tr>"
|
||||||
info += "<td>" + case.output_dir + "</td></tr>"
|
info += "<tr><td>Case Output Directory:</td>"
|
||||||
info += "<tr><td>Autopsy Version:</td>"
|
info += "<td>" + case.output_dir + "</td></tr>"
|
||||||
info += "<td>" + case.autopsy_version + "</td></tr>"
|
info += "<tr><td>Autopsy Version:</td>"
|
||||||
info += "<tr><td>Heap Space:</td>"
|
info += "<td>" + case.autopsy_version + "</td></tr>"
|
||||||
info += "<td>" + case.heap_space + "</td></tr>"
|
info += "<tr><td>Heap Space:</td>"
|
||||||
info += "<tr><td>Test Start Date:</td>"
|
info += "<td>" + case.heap_space + "</td></tr>"
|
||||||
info += "<td>" + case.start_date + "</td></tr>"
|
info += "<tr><td>Test Start Date:</td>"
|
||||||
info += "<tr><td>Test End Date:</td>"
|
info += "<td>" + case.start_date + "</td></tr>"
|
||||||
info += "<td>" + case.end_date + "</td></tr>"
|
info += "<tr><td>Test End Date:</td>"
|
||||||
info += "<tr><td>Total Test Time:</td>"
|
info += "<td>" + case.end_date + "</td></tr>"
|
||||||
info += "<td>" + case.total_test_time + "</td></tr>"
|
info += "<tr><td>Total Test Time:</td>"
|
||||||
info += "<tr><td>Total Ingest Time:</td>"
|
info += "<td>" + case.total_test_time + "</td></tr>"
|
||||||
info += "<td>" + case.total_ingest_time + "</td></tr>"
|
info += "<tr><td>Total Ingest Time:</td>"
|
||||||
info += "<tr><td>Exceptions Count:</td>"
|
info += "<td>" + case.total_ingest_time + "</td></tr>"
|
||||||
info += "<td>" + str(len(get_exceptions())) + "</td></tr>"
|
info += "<tr><td>Exceptions Count:</td>"
|
||||||
info += "<tr><td>TSK Objects Count:</td>"
|
info += "<td>" + str(len(get_exceptions())) + "</td></tr>"
|
||||||
info += "<td>" + str(database.autopsy_objects) + "</td></tr>"
|
info += "<tr><td>OutOfMemoryExceptions:</td>"
|
||||||
info += "<tr><td>Artifacts Count:</td>"
|
info += "<td>" + str(len(search_common_log("OutOfMemoryException"))) + "</td></tr>"
|
||||||
info += "<td>" + str(database.get_artifacts_count()) + "</td></tr>"
|
info += "<tr><td>OutOfMemoryErrors:</td>"
|
||||||
info += "<tr><td>Attributes Count:</td>"
|
info += "<td>" + str(len(search_common_log("OutOfMemoryError"))) + "</td></tr>"
|
||||||
info += "<td>" + str(database.autopsy_attributes) + "</td></tr>"
|
info += "<tr><td>TSK Objects Count:</td>"
|
||||||
info += "</table>\
|
info += "<td>" + str(database.autopsy_objects) + "</td></tr>"
|
||||||
</div>"
|
info += "<tr><td>Artifacts Count:</td>"
|
||||||
# For all the general print statements in the case
|
info += "<td>" + str(database.get_artifacts_count()) + "</td></tr>"
|
||||||
output = "<div id='general'>\
|
info += "<tr><td>Attributes Count:</td>"
|
||||||
<h2><a name='" + case.image_name + "-general'>General Output</a></h2>\
|
info += "<td>" + str(database.autopsy_attributes) + "</td></tr>"
|
||||||
<hr color='#282828'>"
|
info += "</table>\
|
||||||
# For each printout in the case's list
|
</div>"
|
||||||
for out in case.printout:
|
# For all the general print statements in the case
|
||||||
output += "<p>" + out + "</p>"
|
output = "<div id='general'>\
|
||||||
# If there was a \n it probably means we want a <br /> in the html
|
<h2><a name='" + case.image_name + "-general'>General Output</a></h2>\
|
||||||
if "\n" in out:
|
<hr color='#282828'>"
|
||||||
output += "<br />"
|
# For each printout in the case's list
|
||||||
output += "</div>"
|
for out in case.printout:
|
||||||
|
output += "<p>" + out + "</p>"
|
||||||
foot = "</body>\
|
# If there was a \n it probably means we want a <br /> in the html
|
||||||
</html>"
|
if "\n" in out:
|
||||||
|
output += "<br />"
|
||||||
html.write(title)
|
output += "</div>"
|
||||||
html.write(errors)
|
|
||||||
html.write(info)
|
foot = "</body>\
|
||||||
html.write(output)
|
</html>"
|
||||||
# Leaving the closing body and html tags out
|
|
||||||
# for simplicity. It shouldn't kill us.
|
html.write(title)
|
||||||
html.close()
|
html.write(errors)
|
||||||
|
html.write(info)
|
||||||
|
html.write(output)
|
||||||
|
html.close()
|
||||||
|
except Exception as e:
|
||||||
|
printerror("Error: Unknown fatal error when creating HTML log at:")
|
||||||
|
printerror(case.html_log)
|
||||||
|
printerror(str(e) + "\n")
|
||||||
|
|
||||||
|
|
||||||
# Writed the top of the HTML log file
|
# Writed the top of the HTML log file
|
||||||
def write_html_head():
|
def write_html_head():
|
||||||
@ -999,8 +1074,9 @@ def copy_logs():
|
|||||||
try:
|
try:
|
||||||
log_dir = os.path.join("..","build","test","qa-functional","work","userdir0","var","log")
|
log_dir = os.path.join("..","build","test","qa-functional","work","userdir0","var","log")
|
||||||
shutil.copytree(log_dir, make_local_path(case.output_dir, case.image_name, "logs"))
|
shutil.copytree(log_dir, make_local_path(case.output_dir, case.image_name, "logs"))
|
||||||
except:
|
except Exception as e:
|
||||||
printerror("Error: Failed tp copy the logs.\n")
|
printerror("Error: Failed tp copy the logs.")
|
||||||
|
printerror(str(e) + "\n")
|
||||||
|
|
||||||
# Clears all the files from a directory and remakes it
|
# Clears all the files from a directory and remakes it
|
||||||
def clear_dir(dir):
|
def clear_dir(dir):
|
||||||
@ -1008,9 +1084,11 @@ def clear_dir(dir):
|
|||||||
if dir_exists(dir):
|
if dir_exists(dir):
|
||||||
shutil.rmtree(dir)
|
shutil.rmtree(dir)
|
||||||
os.makedirs(dir)
|
os.makedirs(dir)
|
||||||
|
return True;
|
||||||
except:
|
except:
|
||||||
printerror("Error: Cannot clear the given directory:")
|
printerror("Error: Cannot clear the given directory:")
|
||||||
printerror(dir + "\n")
|
printerror(dir + "\n")
|
||||||
|
return False;
|
||||||
|
|
||||||
# Copies a given file from "ffrom" to "to"
|
# Copies a given file from "ffrom" to "to"
|
||||||
def copy_file(ffrom, to):
|
def copy_file(ffrom, to):
|
||||||
@ -1147,22 +1225,7 @@ class DirNotFoundException(Exception):
|
|||||||
error = "Error: Directory could not be found at:\n" + self.dir + "\n"
|
error = "Error: Directory could not be found at:\n" + self.dir + "\n"
|
||||||
return error
|
return error
|
||||||
|
|
||||||
# If a string cannot be found in a log file,
|
|
||||||
# it will throw this exception
|
|
||||||
class StringNotFoundException(Exception):
|
|
||||||
def __init__(self, string):
|
|
||||||
self.string = string
|
|
||||||
self.strerror = "StringNotFoundException: " + string
|
|
||||||
|
|
||||||
def print_error(self):
|
|
||||||
printerror("Error: String '" + self.string + "' could not be found.\n")
|
|
||||||
|
|
||||||
def error(self):
|
|
||||||
error = "Error: String '" + self.string + "' could not be found.\n"
|
|
||||||
return error
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#----------------------#
|
#----------------------#
|
||||||
# Main #
|
# Main #
|
||||||
|
@ -186,7 +186,7 @@ public class RegressionTest extends JellyTestCase{
|
|||||||
|
|
||||||
public void testConfigureSearch() {
|
public void testConfigureSearch() {
|
||||||
logger.info("Search Configure");
|
logger.info("Search Configure");
|
||||||
JDialog jd = JDialogOperator.waitJDialog("Keyword List Configuration", false, false);
|
JDialog jd = JDialogOperator.waitJDialog("Advanced Keyword Search Configuration", false, false);
|
||||||
JDialogOperator jdo = new JDialogOperator(jd);
|
JDialogOperator jdo = new JDialogOperator(jd);
|
||||||
String words = System.getProperty("keyword_path");
|
String words = System.getProperty("keyword_path");
|
||||||
JButtonOperator jbo0 = new JButtonOperator(jdo, "Import List", 0);
|
JButtonOperator jbo0 = new JButtonOperator(jdo, "Import List", 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user