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
@ -1,124 +1,49 @@
|
|||||||
import smtplib
|
import smtplib
|
||||||
from email.mime.image import MIMEImage
|
from email.mime.image import MIMEImage
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.mime.base import MIMEBase
|
from email.mime.base import MIMEBase
|
||||||
from email import encoders
|
from email import encoders
|
||||||
import xml
|
import xml
|
||||||
from time import localtime, strftime
|
from xml.dom.minidom import parse, parseString
|
||||||
from xml.dom.minidom import parse, parseString
|
|
||||||
import subprocess
|
def send_email(to, server, subj, body, attachments):
|
||||||
import sys
|
"""Send an email with the given information.
|
||||||
import os
|
|
||||||
|
Args:
|
||||||
def send_email(parsed, errorem, attachl, passFail):
|
to: a String, the email address to send the email to
|
||||||
element = parsed.getElementsByTagName("email")
|
server: a String, the mail server to send from
|
||||||
if(len(element)<=0):
|
subj: a String, the subject line of the message
|
||||||
return
|
body: a String, the body of the message
|
||||||
element = element[0]
|
attachments: a listof_pathto_File, the attachements to include
|
||||||
toval = element.getAttribute("value").encode().decode("utf_8")
|
"""
|
||||||
if(toval==None):
|
msg = MIMEMultipart()
|
||||||
return
|
msg['Subject'] = subj
|
||||||
element = parsed.getElementsByTagName("mail_server")[0]
|
# me == the sender's email address
|
||||||
serverval = element.getAttribute("value").encode().decode("utf_8")
|
# family = the list of all recipients' email addresses
|
||||||
# Create the container (outer) email message.
|
msg['From'] = 'AutopsyTest'
|
||||||
msg = MIMEMultipart()
|
msg['To'] = to
|
||||||
element = parsed.getElementsByTagName("subject")[0]
|
msg.preamble = 'This is a test'
|
||||||
subval = element.getAttribute("value").encode().decode("utf_8")
|
container = MIMEText(body, 'plain')
|
||||||
if(passFail):
|
msg.attach(container)
|
||||||
msg['Subject'] = '[Test]Autopsy ' + subval + ' test passed.'
|
Build_email(msg, attachments)
|
||||||
else:
|
s = smtplib.SMTP(server)
|
||||||
msg['Subject'] = '[Test]Autopsy ' + subval + ' test failed.'
|
try:
|
||||||
# me == the sender's email address
|
print('Sending Email')
|
||||||
# family = the list of all recipients' email addresses
|
s.sendmail(msg['From'], msg['To'], msg.as_string())
|
||||||
msg['From'] = 'AutopsyTest'
|
except Exception as e:
|
||||||
msg['To'] = toval
|
print(str(e))
|
||||||
msg.preamble = 'This is a test'
|
s.quit()
|
||||||
container = MIMEText(errorem, 'plain')
|
|
||||||
msg.attach(container)
|
def Build_email(msg, attachments):
|
||||||
Build_email(msg, attachl)
|
for file in attachments:
|
||||||
s = smtplib.SMTP(serverval)
|
part = MIMEBase('application', "octet-stream")
|
||||||
try:
|
atach = open(file, "rb")
|
||||||
print('Sending Email')
|
attch = atach.read()
|
||||||
s.sendmail(msg['From'], msg['To'], msg.as_string())
|
noml = file.split("\\")
|
||||||
except Exception as e:
|
nom = noml[len(noml)-1]
|
||||||
print(str(e))
|
part.set_payload(attch)
|
||||||
s.quit()
|
encoders.encode_base64(part)
|
||||||
|
part.add_header('Content-Disposition', 'attachment; filename="' + nom + '"')
|
||||||
def Build_email(msg, attachl):
|
msg.attach(part)
|
||||||
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)
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
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