예제 #1
0
def t07():
    pretty = '%s t7' % __file__
    print(pretty)

    conn, ctrl, pipe = make_peers()
    step_connect(conn, ctrl)
    step_authenticate(conn, ctrl, 'password')

    # send the message in multiple pieces to cause partial reads by the server.
    # perform control steps in between partial reads to check that the server
    # does not hang.
    payload = RemoteControl.make_rpc_blob('sync_ping', None)
    header = Connection.make_header(payload)

    conn.write(header[:2])  # send half the header
    ctrl.step_main()  # should be a noop
    conn.write(header[2:])  # send the rest of the header
    ctrl.step_main()  # should be a noop
    conn.write(payload[:5])  # send the first couple of bytes from the payload
    ctrl.step_main()  # should be a noop
    conn.write(payload[5:])  # send the rest of the payload
    ctrl.step_main()  # validate and evaluate rpc
    ctrl.step_main()  # send response to client

    msg = conn.get(timeout=2)
    expected = {'result': 'pong'}
    if json.loads(msg) != expected:
        print('FAIL %s: wrong response: %s' % (pretty, msg))
        return False

    return True
예제 #2
0
def t08():
    pretty = '%s t8' % __file__
    print(pretty)

    conn, ctrl, pipe = make_peers()
    step_connect(conn, ctrl)
    step_authenticate(conn, ctrl, 'password')

    # set the recv/send buffer sizes for all control connections to 1 byte.
    # this will normally result in buffer sizes of about 2 kilobytes.
    payload = RemoteControl.make_rpc_blob('set_connection_buf_sizes', None,
                                          1024 * 64, 1)
    response = step_call(conn, ctrl, payload)
    recv_size, send_size = tuple(response['result'])

    # craft a message that is just too big to send in one chunk
    payload = RemoteControl.make_rpc_blob('sync_ping', None,
                                          '.' * send_size * 30)
    conn.put(payload)
    ctrl.step_main()  # read message from client

    # read the response back to the client. the server will need to perform a
    # number of steps in its main loop to get all the bytes out on the socket.
    response = ''
    while True:
        ctrl.step_main()  # send response to client
        try:
            # reading non-blocking should never fail under these conditions,
            # except that data may not be available (raises ConnectionAgain).
            response += Connection.read(conn, send_size)
        except ConnectionAgain:
            continue
        except Exception, e:
            print('FAIL %s: wrong error: %s' % (pretty, e))
            return False
        try:
            size, payload = Connection.validate_message(response)
            result = json.loads(payload)
            break
        except Exception, e:
            pass  # simply not done yet. do another step in the loop
예제 #3
0
def t09():
    pretty = '%s t9' % __file__
    print(pretty)

    conn, ctrl, pipe = make_peers()
    step_connect(conn, ctrl)
    step_authenticate(conn, ctrl, 'password')

    payload = RemoteControl.make_rpc_blob('make_garbage', None)
    header = Connection.make_header(payload)

    conn.write(header + payload)  # send the message

    try:
        ctrl.step_main()  # let server receive the message
        ctrl.step_main()  # let server send response to client
    except Exception, e:
        print('FAIL %s: could not step through garbage: %s' % (pretty, e))
        return False
예제 #4
0
def t05():
    pretty = '%s t5' % __file__
    print(pretty)

    conn, ctrl, pipe = make_peers()
    step_connect(conn, ctrl)
    step_authenticate(conn, ctrl, 'password')

    # call remote procedure
    rpc = RemoteControl.make_rpc_blob('raise_exit', None)
    conn.put(rpc)
    ctrl.step_main()  # read the rpc message
    # ctrl.step_main() # no separate step to send exit message

    try:
        msg = conn.get(timeout=2)
    except Exception, e:
        print('FAIL %s: message not received: %s' % (pretty, str(e)))
        return False
예제 #5
0
def t38(control, remote, queue):
    pretty = '%s t38' % __file__
    print(pretty)

    # ping once to make sure connection is established, then write a corrupt
    # message on the connection and check the response
    remote.sync_ping()

    header  = struct.pack('>L', 0x7fffffff+1)
    payload = RemoteControl.make_rpc_blob('sync_ping', None, [], {})
    remote._connection.write(header + payload)

    try:
        response  = json.loads(remote._connection.get(timeout=3))
        exception = exception_factory(response['exception'])
        if type(exception) != OverflowError:
            print('FAIL %s: wrong exception: %s' % (pretty, exception))
            return False
    except Exception, e:
        print('FAIL %s: wrong response: %s' % (pretty, e))
        return False
예제 #6
0
파일: hickup.py 프로젝트: yiu31802/ave
def t06(pretty, factory):
    def killer(pid):
        for i in range(150):
            os.kill(pid, signal.SIGUSR1)
            time.sleep(0.05)

    ctrl = factory.make_control(home=factory.HOME.path, authkey='')
    proc = Process(target=killer, args=(ctrl.get_pid(),))
    proc.start()

    # connect and authenticate
    conn = BlockingConnection(('',ctrl.port))
    conn.connect()
    conn.put(make_digest(conn.get(), ''))
    finish_challenge(conn.get())

    # feed messages slowly to the controller, check that it doesn't crash
    ok = True
    for i in range(15):
        blob = RemoteControl.make_rpc_blob('upper', None, 'a'*5000)
        conn.write(Connection.make_header(blob))
        #print '<',i
        for char in blob:
            conn.write(char)
            time.sleep(0.00002)
        #print '>',i
        try:
            msg = conn.get(timeout=1)
        except Exception, e:
            print('FAIL %s: control crashed in step %d: %s' % (pretty, i, e))
            ok = False
            break
        try:
            msg = json.loads(msg)
        except Exception, e:
            print('FAIL %s: could not decode response %d: %s' & (pretty, i, e))
            ok = False
            break
예제 #7
0
    conn, ctrl, pipe = make_peers()

    # these steps should just work (see t02)
    try:
        step_connect(conn, ctrl)
        step_authenticate(conn, ctrl, 'wrong credentials')
    except AuthError:
        pass  # good
    except Exception, e:
        print('FAIL %s: wrong error: %s' % (pretty, e))
        return False

    # let the client make a remote function call on the control
    try:
        rpc = RemoteControl.make_rpc_blob('sync_ping', None)
        conn.put(rpc)
    except Exception, e:
        print('FAIL %s: could not put rpc blob: %s' % (pretty, e))
        return False

    try:
        ctrl.step_main()  # read the rpc message
        ctrl.step_main()  # write the rpc response
        msg = json.loads(conn.get())
        if msg != {'result': 'pong'}:
            print('FAIL %s: wrong rpc response: %s' % (pretty, msg))
            return False
    except Exception, e:
        print('FAIL %s: could not process rpc: %s' % (pretty, e))
        return False