async def handler_put_1(hostname, id, flag): state = State(hostname) public_before = random.randrange(2) == 0 username, password = await state.login() await state.put_posts(username, random.randrange(3), True) if public_before: public_id, _, _, _, _ = await state.put_post(public=True, signed=True, username=username) else: private_id, _, _, _, _ = await state.put_post(body=flag, public=False, signed=True, username=username) await state.put_posts(username, random.randrange(3), True) if not public_before: public_id, _, _, _, _ = await state.put_post(public=True, signed=True, username=username) else: private_id, _, _, _, _ = await state.put_post(body=flag, public=False, signed=True, username=username) await state.put_posts(username, random.randrange(3), True) checker.ok(message=json.dumps({ 'username': username, 'private': private_id, 'public': public_id }))
async def handler_get_2(hostname, id, flag): p = await get_point_with_flag(hostname, id['username'], id['password'], id['id']) if p['x'] + p['y'] != flag: checker.corrupt(message="Bad flag: expected {}, found {}".format( flag, p['message'])) checker.ok()
async def handler_put(hostname, id, flag): t = random.randint(1, 2) if t == 1: id = await handler_put_1(hostname, id, flag) else: id = await handler_put_2(hostname, id, flag) id['type'] = t checker.ok(message=json.dumps(id))
async def handler_get(hostname, id, flag): first = State(hostname, PORT, 'first') text = await first.get(id) if flag not in text: print('NO FLAG') checker.corrupt() checker.ok()
async def handler_get_1(hostname, id, flag): id = json.loads(id) user = id['username'] state = State(hostname) await state.get_post(id['public'], True, user) file = await state.get_post(id['private'], True, user) if file['body'] != flag: return checker.corrupt( message="Bad flag: expected {}, found {}".format( flag, file['body'])) checker.ok()
async def handler_get_2(hostname, id, flag): id = json.loads(id) state = State(hostname) skill = id["skill"] await state.login(skills=json.dumps([skill])) url = id["url"] file = await state.get_post(url, True, id['username']) if file['body'] != flag: return checker.corrupt( message="Bad flag: expected {}, found {}".format( flag, file['body'])) checker.ok()
async def handler_put_2(hostname, id, flag): state = State(hostname) username, _ = await state.login() url, _, _, _, skill = await state.put_post(body=flag, public=True, signed=True, username=username, need_skill=True) checker.ok(message=json.dumps({ 'username': username, 'url': url, 'skill': skill }))
async def handler_check(hostname): messages = [] m.start() client = EchoClient(WS_BROADCASTER_ADDR.format(hostname)) client.add_writer(messages) client.connect() first = State(hostname, PORT, 'first') key = get_rnd_string(random.randint(5, 20)) msg = { "text": get_rnd_string(random.randint(5, 20)), "frequency": 1500, "dpm": 500, "need_base32": False, "password": "******", "is_private": False, 'datetime': None, } status, text = await first.post(key, msg, False) if status != 200: print('Не удалось положить в бд') checker.log() # Не удалось положить в бд if msg not in json.loads(text): print('В ответе нет нашего сообщения') checker.log() # В ответе нет нашего сообщения text = await first.get(key) if msg not in json.loads(text): print('В ответе нет нашего сообщения') checker.log() # В ответе нет нашего сообщения m.close_all() m.stop() m.join() if key not in messages: print('Не пришли новости о новой станции') checker.log() # Не пришли новости о новой станции checker.ok()
async def handler_check(hostname): first = State(hostname, PORT, 'first') fregister_and_put = register_and_put(first) second = State(hostname, PORT, 'second') sregister = second.register() fregister_and_put_result, _ = await asyncio.gather( asyncio.ensure_future(fregister_and_put), asyncio.ensure_future(sregister)) fusername, fdata = fregister_and_put_result while True: time.sleep(1) fcheckTask = check_in_self_list(first, fdata) scheckTask = check_in_anothers_list(second, fusername, fdata) suser_check_task = check_in_user_list(second, fusername) (fcheck, scheck, suser_check) = await asyncio.gather( asyncio.ensure_future(fcheckTask), asyncio.ensure_future(scheckTask), asyncio.ensure_future(suser_check_task)) if not scheck: checker.log("no suitable data in another user's list") continue if not fcheck: checker.log("posted data not present in list of owner") continue if not suser_check: checker.log("no user in list") continue break checker.ok()
async def handler_put(hostname, id, flag): first = State(hostname, PORT, 'first') key = get_rnd_string(random.randint(10, 20)) msg = { "text": flag, "frequency": random.randint(1, 4000), "dpm": random.randint(1, 4000), "need_base32": False, "password": get_rnd_string(random.randint(15, 30)), "is_private": True, 'datetime': None, } status, _ = await first.post(key, msg, False) if status != 200: print('CANT PUT') checker.mumble() print(key) checker.ok()
async def handler_check(hostname): first = State(hostname, PORT, 'first') fusername, fpassword = await first.register() point_listener = first.get_points_listener() second = State(hostname, PORT, 'second') suser, spass = await second.register() public_listener = second.get_public_listener() tasks = [] tasks.append( asyncio.ensure_future( check_one(fusername, first, public_listener, True))) tasks.append( asyncio.ensure_future( check_one(fusername, first, point_listener, False))) tasks.append( asyncio.ensure_future(check_path(fusername, first, second, suser))) await asyncio.gather(*tasks) checker.ok()
async def handler_check(hostname): unregistered = State(hostname) listener = unregistered.get_listener() state = State(hostname) username, password = await state.login() wanted, contents = await state.put_posts(username, 5) await unregistered.get_contents(contents) listener.want_many(wanted) skills = [get_pair_of_strings() for i in range(random.randint(3, 5))] skill = random.choice(skills) viewer = State(hostname) user, _ = await viewer.login(skills=json.dumps(skills)) writer = State(hostname) username, _ = await writer.login() url, public, title, body, _ = await writer.put_post(public=True, need_skill=True, skill=skill) listener.want(url, username) await viewer.get_content(url, title, body) await listener.finish() checker.ok()
async def handler_put(hostname, id, flag): putter = State(hostname, PORT, 'put') username, password = await putter.register() await putter.put_data(flag) checker.ok(message=json.dumps({'user': username, 'pass': password}))
async def handler_get(hostname, id, flag): id = json.loads(id) getter = State(hostname, PORT, 'get', id['user'], id['pass']) if not await check_in_self_list(getter, flag): checker.corrupt() checker.ok()