mirror of
https://github.com/elisspace/autopsy.git
synced 2026-09-06 02:24:30 +00:00
Merge pull request #3465 from esaunders/develop
Updated regression test script to handle indexed reports.
This commit is contained in:
@@ -319,7 +319,8 @@ class TskDbDiff(object):
|
||||
id_fs_info_table = build_id_fs_info_table(conn.cursor(), isMultiUser)
|
||||
id_objects_table = build_id_objects_table(conn.cursor(), isMultiUser)
|
||||
id_artifact_types_table = build_id_artifact_types_table(conn.cursor(), isMultiUser)
|
||||
id_obj_path_table = build_id_obj_path_table(id_files_table, id_objects_table, id_artifact_types_table)
|
||||
id_reports_table = build_id_reports_table(conn.cursor(), isMultiUser)
|
||||
id_obj_path_table = build_id_obj_path_table(id_files_table, id_objects_table, id_artifact_types_table, id_reports_table)
|
||||
|
||||
#line = normalize_db_entry(line, id_obj_path_table, id_vs_parts_table, id_vs_info_table, id_fs_info_table, id_objects_table)
|
||||
if isMultiUser: # Use PostgreSQL
|
||||
@@ -340,7 +341,7 @@ class TskDbDiff(object):
|
||||
continue
|
||||
else:
|
||||
dump_line += line
|
||||
dump_line = normalize_db_entry(dump_line, id_obj_path_table, id_vs_parts_table, id_vs_info_table, id_fs_info_table, id_objects_table)
|
||||
dump_line = normalize_db_entry(dump_line, id_obj_path_table, id_vs_parts_table, id_vs_info_table, id_fs_info_table, id_objects_table, id_reports_table)
|
||||
db_log.write('%s\n' % dump_line)
|
||||
dump_line = ''
|
||||
postgreSQL_db.close()
|
||||
@@ -352,7 +353,7 @@ class TskDbDiff(object):
|
||||
# Write to the database dump
|
||||
with codecs.open(dump_file, "wb", "utf_8") as db_log:
|
||||
for line in conn.iterdump():
|
||||
line = normalize_db_entry(line, id_obj_path_table, id_vs_parts_table, id_vs_info_table, id_fs_info_table, id_objects_table)
|
||||
line = normalize_db_entry(line, id_obj_path_table, id_vs_parts_table, id_vs_info_table, id_fs_info_table, id_objects_table, id_reports_table)
|
||||
db_log.write('%s\n' % line)
|
||||
# Now sort the file
|
||||
srtcmdlst = ["sort", dump_file, "-o", dump_file]
|
||||
@@ -404,7 +405,7 @@ class PGSettings(object):
|
||||
return self.password
|
||||
|
||||
|
||||
def normalize_db_entry(line, files_table, vs_parts_table, vs_info_table, fs_info_table, objects_table):
|
||||
def normalize_db_entry(line, files_table, vs_parts_table, vs_info_table, fs_info_table, objects_table, reports_table):
|
||||
""" Make testing more consistent and reasonable by doctoring certain db entries.
|
||||
|
||||
Args:
|
||||
@@ -464,8 +465,10 @@ def normalize_db_entry(line, files_table, vs_parts_table, vs_info_table, fs_info
|
||||
#if obj_id or parent_id is invalid literal, we simple return the values as it is
|
||||
try:
|
||||
obj_id = int(obj_id)
|
||||
parent_id = int(parent_id)
|
||||
if parent_id != 'NULL':
|
||||
parent_id = int(parent_id)
|
||||
except Exception as e:
|
||||
print(obj_id, parent_id)
|
||||
return line
|
||||
|
||||
if obj_id in files_table.keys():
|
||||
@@ -476,7 +479,18 @@ def normalize_db_entry(line, files_table, vs_parts_table, vs_info_table, fs_info
|
||||
path = vs_info_table[obj_id]
|
||||
elif obj_id in fs_info_table.keys():
|
||||
path = fs_info_table[obj_id]
|
||||
elif obj_id in reports_table.keys():
|
||||
path = reports_table[obj_id]
|
||||
|
||||
# remove host name from path for reports (only applicable for multi-user)
|
||||
if path is not None:
|
||||
moduleOutput_idx = path.find('ModuleOutput')
|
||||
if moduleOutput_idx > -1:
|
||||
path = "'" + path[path.find('ModuleOutput'):]
|
||||
reports_idx = path.find('\\Reports\\AutopsyTestCase')
|
||||
if reports_idx > -1:
|
||||
path = "'" + path[path.find('Reports\\AutopsyTestCase'):]
|
||||
|
||||
if parent_id in files_table.keys():
|
||||
parent_path = files_table[parent_id]
|
||||
elif parent_id in vs_parts_table.keys():
|
||||
@@ -485,6 +499,8 @@ def normalize_db_entry(line, files_table, vs_parts_table, vs_info_table, fs_info
|
||||
parent_path = vs_info_table[parent_id]
|
||||
elif parent_id in fs_info_table.keys():
|
||||
parent_path = fs_info_table[parent_id]
|
||||
elif parent_id == 'NULL':
|
||||
parent_path = "NULL"
|
||||
|
||||
|
||||
if path and parent_path:
|
||||
@@ -590,20 +606,35 @@ def build_id_artifact_types_table(db_cursor, isPostgreSQL):
|
||||
mapping = dict([(row[0], row[1]) for row in sql_select_execute(db_cursor, isPostgreSQL, "SELECT blackboard_artifacts.artifact_obj_id, blackboard_artifact_types.type_name FROM blackboard_artifacts INNER JOIN blackboard_artifact_types ON blackboard_artifact_types.artifact_type_id = blackboard_artifacts.artifact_type_id ")])
|
||||
return mapping
|
||||
|
||||
def build_id_reports_table(db_cursor, isPostgreSQL):
|
||||
"""Build the map of report object ids to report path.
|
||||
|
||||
def build_id_obj_path_table(files_table, objects_table, artifacts_table):
|
||||
Args:
|
||||
db_cursor: the database cursor
|
||||
"""
|
||||
# for each row in the reports table in the db, create an obj_id -> path map
|
||||
mapping = dict([(row[0], row[1]) for row in sql_select_execute(db_cursor, isPostgreSQL, "SELECT obj_id, path FROM reports")])
|
||||
return mapping
|
||||
|
||||
|
||||
def build_id_obj_path_table(files_table, objects_table, artifacts_table, reports_table):
|
||||
"""Build the map of object ids to artifact ids.
|
||||
|
||||
Args:
|
||||
files_table: obj_id, path
|
||||
objects_table: obj_id, par_obj_id, type
|
||||
artifacts_table: obj_id, artifact_type_name
|
||||
reports_table: obj_id, path
|
||||
"""
|
||||
# make a copy of files_table and updated it with new data from artifats_table
|
||||
# make a copy of files_table and update it with new data from artifacts_table and reports_table
|
||||
mapping = files_table.copy()
|
||||
for k, v in objects_table.items():
|
||||
if k not in mapping.keys(): # If the mapping table doesn't have data for obj_id(k), we use it's par_obj_id's path+name plus it's artifact_type name as path
|
||||
if k in artifacts_table.keys():
|
||||
if k not in mapping.keys(): # If the mapping table doesn't have data for obj_id(k) i.e. the object is not a file...
|
||||
if k in reports_table.keys(): # For a report we use the report path
|
||||
par_obj_id = v[0]
|
||||
if par_obj_id is not None:
|
||||
mapping[k] = reports_table[k]
|
||||
elif k in artifacts_table.keys(): # For an artifact we use it's par_obj_id's path+name plus it's artifact_type name
|
||||
par_obj_id = v[0]
|
||||
path = mapping[par_obj_id]
|
||||
mapping[k] = path + "/" + artifacts_table[k]
|
||||
@@ -641,7 +672,7 @@ def main():
|
||||
output_db = sys.argv.pop(0)
|
||||
gold_db = sys.argv.pop(0)
|
||||
except:
|
||||
print("usage: tskdbdiff [OUPUT DB PATH] [GOLD DB PATH]")
|
||||
print("usage: tskdbdiff [OUTPUT DB PATH] [GOLD DB PATH]")
|
||||
sys.exit(1)
|
||||
|
||||
db_diff = TskDbDiff(output_db, gold_db, output_dir=".")
|
||||
|
||||
Reference in New Issue
Block a user