mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 10:17:41 +00:00
Merge pull request #235 from jawallace/master
Regression Test Refactoring
This commit is contained in:
commit
2cb1aeb5cd
@ -5,120 +5,45 @@ from email.mime.text import MIMEText
|
||||
from email.mime.base import MIMEBase
|
||||
from email import encoders
|
||||
import xml
|
||||
from time import localtime, strftime
|
||||
from xml.dom.minidom import parse, parseString
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
|
||||
def send_email(parsed, errorem, attachl, passFail):
|
||||
element = parsed.getElementsByTagName("email")
|
||||
if(len(element)<=0):
|
||||
return
|
||||
element = element[0]
|
||||
toval = element.getAttribute("value").encode().decode("utf_8")
|
||||
if(toval==None):
|
||||
return
|
||||
element = parsed.getElementsByTagName("mail_server")[0]
|
||||
serverval = element.getAttribute("value").encode().decode("utf_8")
|
||||
# Create the container (outer) email message.
|
||||
msg = MIMEMultipart()
|
||||
element = parsed.getElementsByTagName("subject")[0]
|
||||
subval = element.getAttribute("value").encode().decode("utf_8")
|
||||
if(passFail):
|
||||
msg['Subject'] = '[Test]Autopsy ' + subval + ' test passed.'
|
||||
else:
|
||||
msg['Subject'] = '[Test]Autopsy ' + subval + ' test failed.'
|
||||
# me == the sender's email address
|
||||
# family = the list of all recipients' email addresses
|
||||
msg['From'] = 'AutopsyTest'
|
||||
msg['To'] = toval
|
||||
msg.preamble = 'This is a test'
|
||||
container = MIMEText(errorem, 'plain')
|
||||
msg.attach(container)
|
||||
Build_email(msg, attachl)
|
||||
s = smtplib.SMTP(serverval)
|
||||
try:
|
||||
print('Sending Email')
|
||||
s.sendmail(msg['From'], msg['To'], msg.as_string())
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
s.quit()
|
||||
def send_email(to, server, subj, body, attachments):
|
||||
"""Send an email with the given information.
|
||||
|
||||
def Build_email(msg, attachl):
|
||||
for file in attachl:
|
||||
part = MIMEBase('application', "octet-stream")
|
||||
atach = open(file, "rb")
|
||||
attch = atach.read()
|
||||
noml = file.split("\\")
|
||||
nom = noml[len(noml)-1]
|
||||
part.set_payload(attch)
|
||||
encoders.encode_base64(part)
|
||||
part.add_header('Content-Disposition', 'attachment; filename="' + nom + '"')
|
||||
msg.attach(part)
|
||||
Args:
|
||||
to: a String, the email address to send the email to
|
||||
server: a String, the mail server to send from
|
||||
subj: a String, the subject line of the message
|
||||
body: a String, the body of the message
|
||||
attachments: a listof_pathto_File, the attachements to include
|
||||
"""
|
||||
msg = MIMEMultipart()
|
||||
msg['Subject'] = subj
|
||||
# me == the sender's email address
|
||||
# family = the list of all recipients' email addresses
|
||||
msg['From'] = 'AutopsyTest'
|
||||
msg['To'] = to
|
||||
msg.preamble = 'This is a test'
|
||||
container = MIMEText(body, 'plain')
|
||||
msg.attach(container)
|
||||
Build_email(msg, attachments)
|
||||
s = smtplib.SMTP(server)
|
||||
try:
|
||||
print('Sending Email')
|
||||
s.sendmail(msg['From'], msg['To'], msg.as_string())
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
s.quit()
|
||||
|
||||
# Returns a Windows style path starting with the cwd and
|
||||
# ending with the list of directories given
|
||||
def make_local_path(*dirs):
|
||||
path = wgetcwd().decode("utf-8")
|
||||
for dir in dirs:
|
||||
path += ("\\" + str(dir))
|
||||
return path_fix(path)
|
||||
def Build_email(msg, attachments):
|
||||
for file in attachments:
|
||||
part = MIMEBase('application', "octet-stream")
|
||||
atach = open(file, "rb")
|
||||
attch = atach.read()
|
||||
noml = file.split("\\")
|
||||
nom = noml[len(noml)-1]
|
||||
part.set_payload(attch)
|
||||
encoders.encode_base64(part)
|
||||
part.add_header('Content-Disposition', 'attachment; filename="' + nom + '"')
|
||||
msg.attach(part)
|
||||
|
||||
# Returns a Windows style path based only off the given directories
|
||||
def make_path(*dirs):
|
||||
path = dirs[0]
|
||||
for dir in dirs[1:]:
|
||||
path += ("\\" + str(dir))
|
||||
return path_fix(path)
|
||||
|
||||
# Fix a standard os.path by making it Windows format
|
||||
def path_fix(path):
|
||||
return path.replace("/", "\\")
|
||||
|
||||
# Gets the true current working directory instead of Cygwin's
|
||||
def wgetcwd():
|
||||
proc = subprocess.Popen(("cygpath", "-m", os.getcwd()), stdout=subprocess.PIPE)
|
||||
out,err = proc.communicate()
|
||||
tst = out.rstrip()
|
||||
if os.getcwd == tst:
|
||||
return os.getcwd
|
||||
else:
|
||||
proc = subprocess.Popen(("cygpath", "-m", os.getcwd()), stdout=subprocess.PIPE)
|
||||
out,err = proc.communicate()
|
||||
return out.rstrip()
|
||||
# Verifies a file's existance
|
||||
def file_exists(file):
|
||||
try:
|
||||
if os.path.exists(file):
|
||||
return os.path.isfile(file)
|
||||
except:
|
||||
return False
|
||||
|
||||
# Verifies a directory's existance
|
||||
def dir_exists(dir):
|
||||
try:
|
||||
return os.path.exists(dir)
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
# Returns the nth word in the given string or "" if n is out of bounds
|
||||
# n starts at 0 for the first word
|
||||
def get_word_at(string, n):
|
||||
words = string.split(" ")
|
||||
if len(words) >= n:
|
||||
return words[n]
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Returns true if the given file is one of the required input files
|
||||
# for ingest testing
|
||||
def required_input_file(name):
|
||||
if ((name == "notablehashes.txt-md5.idx") or
|
||||
(name == "notablekeywords.xml") or
|
||||
(name == "nsrl.txt-md5.idx")):
|
||||
return True
|
||||
else:
|
||||
return False
|
File diff suppressed because it is too large
Load Diff
154
test/script/regression_utils.py
Normal file
154
test/script/regression_utils.py
Normal file
@ -0,0 +1,154 @@
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
from time import localtime, strftime
|
||||
import traceback
|
||||
|
||||
# Returns a Windows style path starting with the cwd and
|
||||
# ending with the list of directories given
|
||||
def make_local_path(*dirs):
|
||||
path = wgetcwd().decode("utf-8")
|
||||
for dir in dirs:
|
||||
path += ("\\" + str(dir))
|
||||
return path_fix(path)
|
||||
|
||||
# Returns a Windows style path based only off the given directories
|
||||
def make_path(*dirs):
|
||||
path = dirs[0]
|
||||
for dir in dirs[1:]:
|
||||
path += ("\\" + str(dir))
|
||||
return path_fix(path)
|
||||
|
||||
# Fix a standard os.path by making it Windows format
|
||||
def path_fix(path):
|
||||
return path.replace("/", "\\")
|
||||
|
||||
# Gets the true current working directory instead of Cygwin's
|
||||
def wgetcwd():
|
||||
proc = subprocess.Popen(("cygpath", "-m", os.getcwd()), stdout=subprocess.PIPE)
|
||||
out,err = proc.communicate()
|
||||
tst = out.rstrip()
|
||||
if os.getcwd == tst:
|
||||
return os.getcwd
|
||||
else:
|
||||
proc = subprocess.Popen(("cygpath", "-m", os.getcwd()), stdout=subprocess.PIPE)
|
||||
out,err = proc.communicate()
|
||||
return out.rstrip()
|
||||
# Verifies a file's existance
|
||||
def file_exists(file):
|
||||
try:
|
||||
if os.path.exists(file):
|
||||
return os.path.isfile(file)
|
||||
except:
|
||||
return False
|
||||
|
||||
# Verifies a directory's existance
|
||||
def dir_exists(dir):
|
||||
try:
|
||||
return os.path.exists(dir)
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
# Returns the nth word in the given string or "" if n is out of bounds
|
||||
# n starts at 0 for the first word
|
||||
def get_word_at(string, n):
|
||||
words = string.split(" ")
|
||||
if len(words) >= n:
|
||||
return words[n]
|
||||
else:
|
||||
return ""
|
||||
|
||||
# Returns true if the given file is one of the required input files
|
||||
# for ingest testing
|
||||
def required_input_file(name):
|
||||
if ((name == "notablehashes.txt-md5.idx") or
|
||||
(name == "notablekeywords.xml") or
|
||||
(name == "nsrl.txt-md5.idx")):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def image_type(image_file):
|
||||
ext_start = image_file.rfind(".")
|
||||
if (ext_start == -1):
|
||||
return IMGTYPE.UNKNOWN
|
||||
ext = image_file[ext_start:].lower()
|
||||
if (ext == ".img" or ext == ".dd"):
|
||||
return IMGTYPE.RAW
|
||||
elif (ext == ".e01"):
|
||||
return IMGTYPE.ENCASE
|
||||
elif (ext == ".aa" or ext == ".001"):
|
||||
return IMGTYPE.SPLIT
|
||||
else:
|
||||
return IMGTYPE.UNKNOWN
|
||||
|
||||
# Returns the type of image file, based off extension
|
||||
class IMGTYPE:
|
||||
RAW, ENCASE, SPLIT, UNKNOWN = range(4)
|
||||
|
||||
def get_image_name(image_file):
|
||||
path_end = image_file.rfind("/")
|
||||
path_end2 = image_file.rfind("\\")
|
||||
ext_start = image_file.rfind(".")
|
||||
if(ext_start == -1):
|
||||
name = image_file
|
||||
if(path_end2 != -1):
|
||||
name = image_file[path_end2+1:ext_start]
|
||||
elif(ext_start == -1):
|
||||
name = image_file[path_end+1:]
|
||||
elif(path_end == -1):
|
||||
name = image_file[:ext_start]
|
||||
elif(path_end!=-1 and ext_start!=-1):
|
||||
name = image_file[path_end+1:ext_start]
|
||||
else:
|
||||
name = image_file[path_end2+1:ext_start]
|
||||
return name
|
||||
|
||||
def usage():
|
||||
"""Return the usage description of the test script."""
|
||||
return """
|
||||
Usage: ./regression.py [-f FILE] [OPTIONS]
|
||||
|
||||
Run RegressionTest.java, and compare the result with a gold standard.
|
||||
By default, the script tests every image in ../input
|
||||
When the -f flag is set, this script only tests a single given image.
|
||||
When the -l flag is set, the script looks for a configuration file,
|
||||
which may outsource to a new input directory and to individual images.
|
||||
|
||||
Expected files:
|
||||
An NSRL database at: ../input/nsrl.txt-md5.idx
|
||||
A notable hash database at: ../input/notablehashes.txt-md5.idx
|
||||
A notable keyword file at: ../input/notablekeywords.xml
|
||||
|
||||
Options:
|
||||
-r Rebuild the gold standards for the image(s) tested.
|
||||
-i Ignores the ../input directory and all files within it.
|
||||
-u Tells Autopsy not to ingest unallocated space.
|
||||
-k Keeps each image's Solr index instead of deleting it.
|
||||
-v Verbose mode; prints all errors to the screen.
|
||||
-e ex Prints out all errors containing ex.
|
||||
-l cfg Runs from configuration file cfg.
|
||||
-c Runs in a loop over the configuration file until canceled. Must be used in conjunction with -l
|
||||
-fr Will not try download gold standard images
|
||||
"""
|
||||
|
||||
#####
|
||||
# Enumeration definition (python 3.2 doesn't have enumerations, this is a common solution
|
||||
# that allows you to access a named enum in a Java-like style, i.e. Numbers.ONE)
|
||||
#####
|
||||
def enum(*seq, **named):
|
||||
enums = dict(zip(seq, range(len(seq))), **named)
|
||||
return type('Enum', (), enums)
|
||||
|
||||
|
||||
def get_files_by_ext(dir_path, ext):
|
||||
"""Get a list of all the files with a given extenstion in the directory.
|
||||
|
||||
Args:
|
||||
dir: a pathto_Dir, the directory to search.
|
||||
ext: a String, the extension to search for. i.e. ".html"
|
||||
"""
|
||||
return [ os.path.join(dir_path, file) for file in os.listdir(dir_path) if
|
||||
file.endswith(ext) ]
|
Loading…
x
Reference in New Issue
Block a user