From b3d9f1a907ebd0e5ceab5681f851bf8d7e01b704 Mon Sep 17 00:00:00 2001 From: Bernardo Damele Date: Fri, 18 Jan 2013 13:02:23 +0000 Subject: [PATCH] more impovements, issue #311 --- extra/shutils/regressiontest.py | 42 ++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/extra/shutils/regressiontest.py b/extra/shutils/regressiontest.py index 65e218b4d..b39333513 100644 --- a/extra/shutils/regressiontest.py +++ b/extra/shutils/regressiontest.py @@ -19,24 +19,26 @@ SMTP_SERVER = "127.0.0.1" SMTP_PORT = 25 SMTP_TIMEOUT = 30 FROM = "regressiontest@sqlmap.org" -TO = "dev@sqlmap.org" -SUBJECT = "Regression test results on on %s" % TIME +#TO = "dev@sqlmap.org" +TO = "bernardo.damele@gmail.com" +SUBJECT = "Regression test results on %s" % TIME CONTENT = "" TEST_COUNTS = [] +ATTACHMENTS = {} command_line = "cd ../../ ; rm -f $REGRESSION_FILE ; python sqlmap.py --live-test --run-case 'Invalid logic'" proc = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) proc.wait() stdout, stderr = proc.communicate() -failed_tests = re.findall("running live test case: (.+?) \((\d+)\/\d+\)[\r]*\n(.+?)test failed (.*?)at parsing item: (.+) \- scan folder is (\/.+)[\r]*\n", stdout, re.I | re.M) +failed_tests = re.findall("running live test case: (.+?) \((\d+)\/\d+\)[\r]*\n.+test failed (at parsing item \"(.+)\" )?\- scan folder: (\/.+) \- traceback: (.*?)( - SQL injection not detected)?[\r]*\n", stdout, re.M) for failed_test in failed_tests: title = failed_test[0] - test_count = failed_test[1] - error = True if "the test did not identify the SQL injection" in failed_test[2] else False - traceback = failed_test[2] or None - parse = failed_test[3] + test_count = int(failed_test[1]) + parse = failed_test[3] if failed_test[3] else None output_folder = failed_test[4] + traceback = failed_test[5] + detection = True if failed_test[6] else False TEST_COUNTS.append(test_count) @@ -44,27 +46,28 @@ for failed_test in failed_tests: console_output = console_output_fd.read() console_output_fd.close() - if error is False: - log_fd = codecs.open(os.path.join(output_folder, "debiandev", "log"), "rb", "utf8") - log = log_fd.read() - log_fd.close() + ATTACHMENTS[test_count] = str(console_output) + + log_fd = codecs.open(os.path.join(output_folder, "debiandev", "log"), "rb", "utf8") + log = log_fd.read() + log_fd.close() if traceback: traceback_fd = codecs.open(os.path.join(output_folder, "traceback"), "rb", "utf8") traceback = traceback_fd.read() traceback_fd.close() - CONTENT += "Failed test case '%s' at parsing: %s:\n\n" % (title, parse) + CONTENT += "Failed test case '%s'" % title - if error is False: + if parse: + CONTENT += " at parsing: %s:\n\n" % parse CONTENT += "### LOG FILE:\n\n" CONTENT += "%s\n" % log - else: - CONTENT += "### CONSOLE OUTPUT\n\n" - CONTENT += "%s\n" % str(console_output) + elif not detection: + CONTENT += " - SQL injection not detected\n\n" if traceback: - CONTENT += "### TRACEBACK:\n" + CONTENT += "### TRACEBACK:\n\n" CONTENT += "%s\n" % str(traceback) CONTENT += "\n#######################################\n\n" @@ -76,6 +79,11 @@ if CONTENT: msg["From"] = FROM msg["To"] = TO + for test_count, attachment in ATTACHMENTS: + attachment = MIMEText(attachment) + attachment.add_header('Content-Disposition', 'attachment', filename="%d.console_output.txt" % test_count) + msg.attach(attachment) + s = smtplib.SMTP(host=SMTP_SERVER, port=SMTP_PORT, timeout=SMTP_TIMEOUT) #s.set_debuglevel(1) s.sendmail(FROM, TO, msg.as_string())