def create_testbook(self, formula): testbook = [] if not self.args.keep_mutants: testcase = "%s/%s.smt2" % (self.args.scratchfolder, self.args.name) else: testcase = "%s/%s-%s-%s.smt2" % (self.args.scratchfolder, escape(self.currentseeds), self.args.name, random_string()) with open(testcase, 'w') as testcase_writer: testcase_writer.write(formula.__str__()) for cli in self.args.SOLVER_CLIS: if self.args.optfuzz != None: if not self.args.keep_mutants: testcase = "%s/%s-%s" % (self.args.scratchfolder, plain(cli), self.args.name) else: testcase = "%s/%s-%s-%s-%s.smt2" % ( self.args.scratchfolder, plain(cli), escape(self.currentseeds), self.args.name, random_string()) with open(testcase, 'w') as testcase_writer: testcase_writer.write( self.args.optfuzz.generate(cli) + formula.__str__()) testbook.append((cli, testcase)) return testbook
def user_reset_password(self, where): # Get user's infomation for sending email where.pop('objectId', 0) params = {'where': json.dumps(where), 'keys': 'name,email,username'} user = self.get(collection='users', params=params) if 'error' in user: return user elif len(user['results']) != 1: return {'error': 404, 'message': 'Invalid email'} # Reset user's password payload = { 'objectId': user['results'][0]['objectId'], 'password': random_string(15) } res = self.put(collection='users', object_id=payload['objectId'], payload=payload, master_key=True) if 'error' not in res: # Sending notification email status, msg = send_reset_password_email( email=user['results'][0]['email'], username=user['results'][0]['username'], password=payload['password']) if status is not 200: return {'code': status, 'error': msg} res['email'] = {'status': status, 'message': msg} return res
def __init__(self, parent_page, chart_model): self.parent_page = parent_page self.data_json = "/" + chart_model.get_json_path() self.parent_page.foot_js.append(Js("highcharts.js")) self.parent_page.foot_js.append(Js("highchart_exporting.js")) self.template = "highchart.tpl" self.id = random_string(10) self.width = 400 self.height = 400 self.parent_page.foot_js_templates.append(Template("highchart_js.tpl", self)) self.description = chart_model.description self.title = chart_model.name
def __init__(self, name="webclient", session="", namespace=""): self.clients.append(self) self.session_id = utils.storage.get("session_id") if not self.session_id: self.session_id = utils.random_string(10) utils.storage.set("session_id", self.session_id) self.socket_url = location.protocol + '//' + location.hostname + ':' + location.port + namespace self.socket = io(self.socket_url, {'transports': ['websocket']}) self.socket.on("command", self.on_command) self.socket.on("server_call", self.on_server_call) self.socket.on("exception", self.on_error) self.socket.on("connect", self.on_connect) self.socket.on("disconnect", self.on_disconnect) self.commands = { 'connect': 1, 'reconnect': 2, 'disconnect': 3, 'status': 4, 'handshake': 5, 'rehandshake': 6 } self.command_callbacks = {} self.namespace = namespace self.session = session self.name = name self._reconnecting = False self._connection_status = True self._disconnected_once = False self._initial_socket_connection = False self._socket_connection = False self._response_cb = {} self._first_connect = True self._msg_queue = [] self._last_msg = None self._cmd_status = {} self._cmd_status_c = 0 self._retries = None self._poll_interval = 5 self._poll_timeout = 1000 * 60 * 120 self._last_retry = __new__(Date()).getTime() self._prev_retry_interval = 0 self.polling = False if not Client.polling: utils.poll_func(self.connection, self._poll_timeout, self._poll_interval * 1000) self.polling = True Client.polling = True
def init_tables(): StorageDb.connect() try: MenuItem.create_table(True) ChartInfo.create_table(False) User.create_table(True) MenuItem.create_table(True) SimplePageConfig.create_table(True) ReportInfo.create_table(True) Connection.create_table(True) SQLquery.create_table(True) ServerConfig.create_table(True) User.create(login='******', password='******', name='Test User') create_menu_item("/admin/" ,'Home', -1, 'SimplePage', 1) SimplePageConfig.create(title="Admin Home", text="This is admin home") create_menu_item("/app/" ,'Home', -1, 'SimplePage', 2) SimplePageConfig.create(title="Home", text="This is the home page") create_menu_item("/admin/" ,'UpdateDB', 0, 'UpdateDB', 3) SimplePageConfig.create(title="Menu", text="This is the Menu page") create_menu_item("/admin/" ,'Report Creator', 0, 'ReportCreator', 4) SimplePageConfig.create(title="Config", text="This is the Config page") create_menu_item("/app/" ,'Reports', -1, 'Reports', 5) create_menu_item("/app/" ,'Charts', 4, 'Charts', 8) create_menu_item("/admin/" ,'Chart Creator', 4, 'ChartCreator', 9) Connection.create(name="local", description="", connection_engine="mysql", \ connection_login="******", connection_password="******", \ connection_host ="127.0.0.1", \ connection_defaultdb="mysql", connection_port = 3306) SQLquery.create(name='test', description='', sql="""SELECT * FROM mysql.user """, connection_id=1) ReportInfo.create(name="Users", description="Report description", source_type='SQLquery', \ source_id=1, cache_duration=86000, row_callback=""""fnRowCallback": function( nRow, aData, iDisplayIndex ) { $('td:eq(2)', nRow).html('<a href="/testpage?' + aData[2] + '"> link </a>'); return nRow; },""") ServerConfig.create(key="CookieKey", value=random_string(50)) ServerConfig.create(key="AppName", value="EazyReport") ServerConfig.create(key="CacheFolder", value="cache") except Exception, e: print "Database already exists", e
def __init__(self, parent_page, name, headers, row_callback=""): self.parent_page = parent_page self.parent_page.css.append(Css("DT_bootstrap.css")) self.parent_page.foot_js.append(Js("jquery.dataTables.min.js")) self.parent_page.foot_js.append(Js("DT_bootstrap.js")) self.parent_page.foot_js_templates = [Template("datatables_js_ready", self)] self.template = "datatables.tpl" self.row_callback = row_callback self.id_table = random_string(10) self.header = headers self.drop_down_nb = True self.drop_down_values = [[20, 50, 100, -1], [20, 50, 100, "All"]] self.drop_down_text = "records per page" self.global_search = True self.global_search_text = "Search all columns:" self.pagination = True self.show_nb_records = True self.records_per_page = 20 self.column_search = True self.ajax_url = "/cache/" + str(name) + ".json" self.csv_url = "/cache/" + str(name) + ".csv"
parser.add_argument( "-d", "--diagnose", action='store_true', help= "forwards solver outputs to stdout e.g. for solver command line diagnosis") parser.add_argument( "-optfuzz", "--optfuzz", default="", help="read solvers' option setting and enable option fuzzing") parser.add_argument( "-name", "--name", default=random_string(), help="set name of this fuzzing instance (default: random string)") parser.add_argument("-bugs", "--bugsfolder", default=rootpath + "/bugs", help="set bug folder (default: " + rootpath + "/bugs)") parser.add_argument( "-scratch", "--scratchfolder", default=rootpath + "/scratch", help="specifies where the mutant formulas are temporarily stored.\ Note, if you run yinyang with several processes in parallel, each\ instance should have its own scratch folder. (default:" + rootpath + "/scratch)") parser.add_argument("-opconfig", "--opconfig",
def validate(self, formula): ret = True log_str = "" if (self.args.oracle == "unknown"): oracle = SolverResult(SolverResultType.UNKNOWN) elif (self.args.oracle == "sat"): oracle = SolverResult(SolverResultType.SAT) elif (self.args.oracle == "unsat"): oracle = SolverResult(SolverResultType.UNSAT) else: assert(False) testbook = [] for cli in self.args.SOLVER_CLIS: if not self.args.keep_mutants: testcase = "%s/%s.smt2" % (self.args.scratchfolder, self.args.name) else: testcase = "%s/%s-%s-%s-%s.smt2" % (self.args.scratchfolder,\ plain(cli),\ escape(self.currentseeds),\ self.args.name,\ random_string()) with open(testcase, 'w') as testcase_writer: if self.args.optfuzz != None: testcase_writer.write(self.args.optfuzz.generate(cli) + formula.__str__()) else: testcase_writer.write(formula.__str__()) testbook.append((cli,testcase)) reference = ("", "", "") for testitem in testbook: solver = Solver(testitem[0]) result, output = solver.solve(testitem[1], self.args.timeout) # print("result", result) # print("output", output) if result.equals(SolverResultType.IGNORED): #ignored self.statistic.ignored += 1 elif result.equals(SolverResultType.UNKNOWN): #unknown pass elif result.equals(SolverResultType.TIMEOUT): #timeout self.statistic.timeout += 1 elif result.equals(SolverResultType.CRASH): #crash self.statistic.error += 1 _,log_str = self.report(testitem[1], "crash", testitem[0], output, random_string()) ret = False elif result.equals(SolverResultType.FAIL): print("\nPlease check your solver command-line interfaces.") exit(1) else: if oracle.equals(SolverResultType.UNKNOWN): oracle = result reference = (testitem[0], testitem[1], output) elif oracle.equals(result): #correct pass else: #incorrect self.statistic.soundness += 1 report_id, log_str = self.report(testitem[1], "incorrect", testitem[0], output, random_string(),oracle,result) if reference != ("", "", ""): _ ,log_str = self.report(reference[1], "incorrect", reference[0], reference[2], report_id, oracle, result) ret = False if not self.args.keep_mutants: pass # print("testcase", testcase) # os.remove(testcase) return ret, log_str
def test(self, formula): """ Tests the solvers with the formula returning "False" if the testing on formula should be stopped and "True" otherwise. """ oracle = self.init_oracle() testbook = self.create_testbook(formula) reference = None for testitem in testbook: solver_cli, scratchfile = testitem[0], testitem[1] solver = Solver(solver_cli) stdout, stderr, exitcode = solver.solve(scratchfile, self.args.timeout, debug=self.args.diagnose) # (1) Detect crashes from a solver run including invalid models. if self.in_crash_list(stdout, stderr): # (2) Match against the duplicate list to avoid reporting duplicate bugs. if not self.in_duplicate_list(stdout, stderr): self.statistic.crashes += 1 self.report(scratchfile, "crash", solver_cli, stdout, stderr, random_string()) else: self.statistic.duplicates += 1 return False # stop testing else: # (3a) Check whether the solver run produces errors, by checking # the ignore list. if self.in_ignore_list(stdout, stderr): self.statistic.ignored += 1 continue # continue with next solver (4) # (3b) Check whether the exit code is nonzero. if exitcode != 0: if exitcode == -signal.SIGSEGV or exitcode == 245: #segfault self.statistic.crashes += 1 self.report(scratchfile, "segfault", solver_cli, stdout, stderr, random_string()) return False # stop testing elif exitcode == 137: #timeout self.statistic.timeout += 1 continue # continue with next solver (4) elif exitcode == 127: #command not found print( "\nPlease check your solver command-line interfaces." ) continue # continue with next solver (4) self.statistic.ignored += 1 # (3c) if there is no '^sat$' or '^unsat$' in the output elif not re.search("^unsat$", stdout, flags=re.MULTILINE) and \ not re.search("^sat$", stdout, flags=re.MULTILINE) and \ not re.search("^unknown$", stdout, flags=re.MULTILINE): self.statistic.ignored += 1 else: # (5) grep for '^sat$', '^unsat$', and '^unknown$' to produce # the output (including '^unknown$' to also deal with incremental # benchmarks) for comparing with the oracle (semantic fusion) or # with other non-erroneous solver runs (opfuzz) for soundness bugs result = self.grep_result(stdout) if oracle.equals(SolverQueryResult.UNKNOWN): oracle = result reference = (solver_cli, scratchfile, stdout, stderr) # Comparing with the oracle (semantic fusion) or with other # non-erroneous solver runs (opfuzz) for soundness bugs. if not oracle.equals(result): self.statistic.soundness += 1 self.report(scratchfile, "incorrect", solver_cli, stdout, stderr, random_string()) if reference: # Produce a diff bug report for soundness bugs in # the opfuzz case ref_cli = reference[0] ref_stdout = reference[1] ref_stderr = reference[2] self.report_diff(scratchfile, "incorrect", ref_cli, ref_stdout, ref_stderr, solver_cli, stdout, stderr, random_string()) return False # stop testing return True
def validate(self, fn): ret = True if (self.args.oracle == "unknown"): oracle = SolverResult(SolverResultType.UNKNOWN) elif (self.args.oracle == "sat"): oracle = SolverResult(SolverResultType.SAT) elif (self.args.oracle == "unsat"): oracle = SolverResult(SolverResultType.UNSAT) else: assert (False) testbook = [] for cli in self.args.SOLVER_CLIS: testcase = fn if self.args.optfuzz != None: with open(fn, 'r') as generated_test: pure_formula = generated_test.read() testcase = "%s/%s-%s" % (self.args.scratchfolder, plain(cli), fn.split('/')[-1]) with open(testcase, 'w') as testcase_writer: testcase_writer.write( self.args.optfuzz.generate(cli) + pure_formula) testbook.append((cli, testcase)) reference = ("", "", "") for testitem in testbook: solver = Solver(testitem[0]) result, output = solver.solve(testitem[1], self.args.timeout) if result.equals(SolverResultType.IGNORED): #ignored self.statistic.ignored += 1 elif result.equals(SolverResultType.UNKNOWN): #unknown pass elif result.equals(SolverResultType.TIMEOUT): #timeout self.statistic.timeout += 1 elif result.equals(SolverResultType.CRASH): #crash self.statistic.error += 1 self.report(testitem[1], "crash", testitem[0], output, random_string()) ret = False elif result.equals(SolverResultType.FAIL): print("\nPlease check your solver command-line interfaces.") else: if oracle.equals(SolverResultType.UNKNOWN): oracle = result reference = (testitem[0], testitem[1], output) elif oracle.equals(result): #correct pass else: #incorrect self.statistic.soundness += 1 report_id = self.report(testitem[1], "incorrect", testitem[0], output, random_string()) if reference != ("", "", ""): self.report(reference[1], "incorrect", reference[0], reference[2], report_id) ret = False return ret