def testExampleStringGeneration(self): """ This test uses generate_string() from generators.py to generate some HTML as a string. It is similar to the reference HTML in tdda/referencetest/examples/reference/string_result.html except that the Copyright and version lines are slightly different. As shipped, the test should pass, because the ignore_patterns tell it to ignore those lines. Make a change to the generation code in the generate_string function in generators.py to change the HTML output. The test should then fail and suggest a diff command to run to see the difference. Rerun with python test_using_referencetestcase.py --write-all and it should re-write the reference output to match your modified results. """ actual = generate_string() self.assertStringCorrect(actual, 'string_result.html', ignore_substrings=['Copyright', 'Version'])
def testExampleStringGeneration(self): """ This test uses generate_string() from generators.py to generate some HTML as a string. It is similar to the reference HTML in tdda/referencetest/examples/reference/string_result.html except that the Copyright and Version lines are slightly different. As shipped, the test should pass, because the ignore_substrings parameter tell it to ignore any lines in the expected result that contain either of those strings. Make a change to the generation code in the generate_string function in generators.py to change the HTML output. The test should then fail and suggest a diff command to run to see the difference. Rerun with python test_using_referencetestcase.py --write-all and it should re-write the reference output to match your modified results. """ actual = generate_string() self.assertStringCorrect(actual, 'string_result.html', ignore_substrings=['Copyright', 'Version'])
def put_second(hostname, flag_id, flag): hostport = get_hostport(hostname) password = generate_string(10) cookies = register(hostport, password) source = generate_simple_task() token = flag task_id = run_task(hostport, cookies, source, b"", token) uid, _ = get_data_from_cookies(cookies) print("{},{},{}".format(uid, password, task_id)) exit(OK)
def check_with_task(hostname, task_func): hostport = get_hostport(hostname) password = generate_string(5) token = generate_string(5) cookies = register(hostport, password) uid, _ = get_data_from_cookies(cookies) another_cookies = login(hostport, password, uid) if another_cookies != cookies: exit_with( MUMBLE, "different cookies with same uid and password: {} != {}".format( cookies, another_cookies)) # source, stdin, output = generate_long_output_task() # source, stdin, output = generate_mega_task() source, stdin, output = task_func() task_id = run_task(hostport, cookies, source, stdin, token) stdout = b"" status = 1 error = "" for try_index in range(CHECK_TRIES_COUNT): try: stdout, status, error = get_task_info(hostport, cookies, task_id, token) if status != 1: break except requests.exceptions.HTTPError as e: if e.response.status_code != 404: raise time.sleep(RETRY_SLEEP) if status == 1: exit_with(MUMBLE, "can not get task info, too long answer") elif status == 2: exit_with(MUMBLE, "error while task running: {}".format(error)) if output != stdout: exit_with( MUMBLE, "wrong output:\n\nexpected='{}'\n\nreal='{}'\n".format( output, stdout)) exit(OK)
def run(): cycle = 0 while True: try: print("Cycle:", cycle) if check() is None: continue flag = generate_string(32) for vuln in range(1, 3): flag_id = put(flag, vuln) if flag_id is None: continue get(flag_id, flag, vuln) cycle += 1 print() # sleep(1) except KeyboardInterrupt: print("\nstop") break
def testExampleStringGeneration(ref): actual = generate_string() ref.assertStringCorrect(actual, 'expected.html')
def testExampleStringGeneration(self): actual = generate_string() with open('expected.html') as f: expected = f.read() self.assertEqual(actual, expected)
def testExampleStringGeneration(): actual = generate_string() with open('expected.html') as f: expected = f.read() assert actual == expected