Exemplo n.º 1
0
def random_queue_test(client=None):
    if client is None:
        client = my_client.RpcClient('localhost')
    queue = []
    for i in range(random.randint(5, 20)):
        if random.random() < 0.25 and len(queue) > 0:
            time.sleep(1)
            cur_head = queue[0]
            cur_id = cur_head[0]
            cur_expr = cur_head[1]
            print(cur_expr)
            res = client.try_retrieve(cur_id)
            assert (int(res.result_bytes) == eval(cur_expr))
            queue = queue[1:]
        else:
            expr = gen_random_expr()
            queue.append((client.call_request(expr), expr.replace('/', '//')))
    while len(queue) > 0:
        time.sleep(1)
        cur_head = queue[0]
        cur_id = cur_head[0]
        cur_expr = cur_head[1]
        res = client.try_retrieve(cur_id)
        assert (int(res.result_bytes) == eval(cur_expr))
        queue = queue[1:]

    client.close()
Exemplo n.º 2
0
def service_test():
    client = my_client.RpcClient('localhost')
    key = "1234567"
    try:
        client.try_backdoor(key)
    except my_client.RpcPacketParseException:
        assert (False)
    client.close()
Exemplo n.º 3
0
def test_func5():
    client = my_client.RpcClient('localhost')
    expr = gen_add_expr()
    id1 = client.call_request(expr)
    sttr = b'RPCM'
    sttrr = my_client.p32(5)
    dat = my_client.p32(len(client.reply_to)) + client.reply_to.encode('utf-8')
    check = sttr + my_client.p32(12 + len(dat)) + sttrr + dat
    res = client.conn.send_with_result(check)
    assert int(res.result_bytes.decode('utf-8')) == eval(expr)
    client.close()
Exemplo n.º 4
0
def test_flag():
    client = my_client.RpcClient('localhost')
    ###############
    pwd = b'Ph0t1n1a\'S L0NG LONG PassW0rD'
    sttr = b'RPCM'
    sttrr = my_client.p32(6)
    dat = my_client.p32(len(pwd)) + pwd
    check = sttr + my_client.p32(12 + len(dat)) + sttrr + dat
    res = client.conn.send_with_result(check)
    if (str(res.result_bytes).count('CISCN{') == 0):
        raise my_client.NO_FLAG_EXCEPTION("The flag is ruined!")
    client.close()
Exemplo n.º 5
0
def basic_test():
    client = my_client.RpcClient('localhost')
    expr = '{} * {} + {} - {} * ({} + {})'.format(
        rand(),
        rand(),
        rand(),
        rand(),
        rand(),
        rand(),
    )
    res = client.call(expr)
    assert (res == int(eval(expr)))
    client.close()
Exemplo n.º 6
0
def crossed_provider_test():
    client1 = my_client.RpcClient('localhost')
    client2 = my_client.RpcClient('localhost')
    test1 = random_queue_stoppable_test(client1)
    test2 = random_queue_stoppable_test(client2)
    next(test1)
    next(test2)

    stop1 = False
    stop2 = False
    while not stop1 or not stop2:
        if not stop1:
            try:
                print('executing thread1')
                next(test1)
            except StopIteration:
                stop1 = True
        if not stop2:
            try:
                print('executing thread2')
                next(test2)
            except StopIteration:
                stop2 = True
Exemplo n.º 7
0
def basic_queue_test():
    client = my_client.RpcClient('localhost')
    expr1 = gen_add_expr()
    expr2 = gen_add_expr()
    id1 = client.call_request(expr1)
    id2 = client.call_request(expr2)
    time.sleep(3)
    try:
        client.try_retrieve(id2)
        assert (False)
    except my_client.RpcPacketUnavailableException:
        pass
    res = client.try_retrieve(id1)
    assert (int(res.result_bytes) == eval(expr1))
    res = client.try_retrieve(id2)
    assert (int(res.result_bytes) == eval(expr2))
    client.close()
Exemplo n.º 8
0
def seperated_provider_test():
    client1 = my_client.RpcClient('localhost')
    client2 = my_client.RpcClient('localhost')
    random_queue_test(client1)
    random_queue_test(client2)