コード例 #1
0
ファイル: tcp_server_cog.py プロジェクト: petr-tik/solent
def should_start_and_stop():
    engine = engine_fake()
    nearcast_schema = gs_nearcast_schema_new()
    snoop = nearcast_snoop_fake(nearcast_schema=nearcast_schema)
    snoop.disable()
    orb = nearcast_orb_new(engine=engine,
                           nearcast_schema=nearcast_schema,
                           nearcast_snoop=snoop)
    r = orb.init_cog(fn=receiver_cog_fake)
    tcp_server_cog = orb.init_cog(fn=tcp_server_cog_new)
    #
    addr = '127.0.0.1'
    port = 5000
    password = '******'
    #
    # confirm starting state
    orb.cycle()
    assert tcp_server_cog.server_sid == None
    assert tcp_server_cog.client_sid == None
    #
    # scenario: start the server
    r.nc_start_service(ip=addr, port=port, password=password)
    #
    # confirm effects
    assert tcp_server_cog.server_sid != None
    assert tcp_server_cog.client_sid == None
    #
    # scenario: stop the service
    stop_service(orb=orb)
    #
    # confirm effects
    assert tcp_server_cog.server_sid == None
    assert tcp_server_cog.client_sid == None
    #
    return True
コード例 #2
0
def should_allow_authorised_ip():
    engine = engine_fake()
    nearcast_schema = gs_nearcast_schema_new()
    nearcast_snoop = nearcast_snoop_fake(nearcast_schema=nearcast_schema)
    nearcast_snoop.disable()
    orb = nearcast_orb_new(engine=engine,
                           nearcast_schema=nearcast_schema,
                           nearcast_snoop=nearcast_snoop)
    r = orb.init_cog(fn=receiver_cog_fake)
    ipval_cog = orb.init_cog(fn=ipval_cog_new)
    #
    ip = '127.0.0.1'
    port = 5000
    #
    # scenario: we see permission for a differnt ip and then a connect
    r.nc_ipval_add_ip(ip='203.15.93.2')
    r.nc_announce_tcp_connect(ip=ip, port=port)
    #
    # check effects: we should still see a boot messaage
    assert 1 == r.count_please_tcp_boot()
    # but we do get a note to say it's ok
    assert 0 == r.count_nearnote()
    #
    # scenario: now we permit the relevant ip, and then see a connect
    r.nc_ipval_add_ip(ip=ip)
    r.nc_announce_tcp_connect(ip=ip, port=port)
    #
    # check effects: we should see no more boot messages
    assert 1 == r.count_please_tcp_boot()
    # but we do get a note to say it's ok
    assert 1 == r.count_nearnote()
    #
    return True
コード例 #3
0
ファイル: tcp_server_cog.py プロジェクト: petr-tik/solent
def should_send_gruel_send_data_to_a_connected_client():
    gruel_schema = gruel_schema_new()
    gruel_press = gruel_press_new(gruel_schema=gruel_schema, mtu=MTU)
    gruel_puff = gruel_puff_new(gruel_schema=gruel_schema, mtu=MTU)
    #
    engine = engine_fake()
    nearcast_schema = gs_nearcast_schema_new()
    snoop = nearcast_snoop_fake(nearcast_schema=nearcast_schema)
    snoop.disable()
    orb = nearcast_orb_new(engine=engine,
                           nearcast_schema=nearcast_schema,
                           nearcast_snoop=snoop)
    r = orb.init_cog(fn=receiver_cog_fake)
    tcp_server_cog = orb.init_cog(fn=tcp_server_cog_new)
    #
    addr = '127.0.0.1'
    port = 5000
    password = '******'
    #
    # confirm starting state
    assert 0 == r.count_announce_tcp_connect()
    assert tcp_server_cog.server_sid == None
    assert tcp_server_cog.client_sid == None
    #
    # scenario: start the server
    start_service(orb=orb, ip=addr, port=port, password=password)
    #
    # confirm effects
    assert 0 == r.count_announce_tcp_connect()
    assert tcp_server_cog.server_sid != None
    assert tcp_server_cog.client_sid == None
    #
    # scenario: client connects
    client_addr = '203.15.93.150'
    client_port = 6000
    simulate_client_connect(engine=engine,
                            orb=orb,
                            tcp_server_cog=tcp_server_cog,
                            ip=client_addr,
                            port=client_port)
    #
    # confirm baseline
    assert 1 == r.count_announce_tcp_connect()
    assert tcp_server_cog.server_sid == None
    assert tcp_server_cog.client_sid != None
    #
    # scenario: tcp_server_cog gets gruel_send but client is not connected
    r.nc_gruel_send(payload=gruel_press.create_client_login_payload(
        password='******', heartbeat_interval=4))
    orb.cycle()
    #
    # confirm effects: client should still be connected, and we should have
    # sent no packets to the engine.
    assert tcp_server_cog.server_sid == None
    assert tcp_server_cog.client_sid != None
    assert 1 == len(engine.sent_data)
    #
    return True
コード例 #4
0
ファイル: tcp_server_cog.py プロジェクト: petr-tik/solent
def should_handle_client_connect_and_then_boot_client():
    engine = engine_fake()
    nearcast_schema = gs_nearcast_schema_new()
    snoop = nearcast_snoop_fake(nearcast_schema=nearcast_schema)
    snoop.disable()
    orb = nearcast_orb_new(engine=engine,
                           nearcast_schema=nearcast_schema,
                           nearcast_snoop=snoop)
    r = orb.init_cog(fn=receiver_cog_fake)
    tcp_server_cog = orb.init_cog(fn=tcp_server_cog_new)
    #
    addr = '127.0.0.1'
    port = 5000
    password = '******'
    #
    # confirm starting state
    assert 0 == r.count_announce_tcp_connect()
    assert tcp_server_cog.server_sid == None
    assert tcp_server_cog.client_sid == None
    #
    # scenario: start the server
    start_service(orb=orb, ip=addr, port=port, password=password)
    #
    # confirm effects
    assert 0 == r.count_announce_tcp_connect()
    assert tcp_server_cog.server_sid != None
    assert tcp_server_cog.client_sid == None
    #
    # scenario: client connects
    client_addr = '203.15.93.150'
    client_port = 6000
    simulate_client_connect(engine=engine,
                            orb=orb,
                            tcp_server_cog=tcp_server_cog,
                            ip=client_addr,
                            port=client_port)
    #
    # confirm effects
    assert 1 == r.count_announce_tcp_connect()
    assert tcp_server_cog.server_sid == None
    assert tcp_server_cog.client_sid != None
    #
    # scenario: stop the service, booting the client in the process
    stop_service(orb=orb)
    #
    # confirm effects
    assert tcp_server_cog.server_sid == None
    assert tcp_server_cog.client_sid == None
    #
    return True
コード例 #5
0
ファイル: tcp_server_cog.py プロジェクト: petr-tik/solent
def should_boot_client_when_invalid_gruel_is_received():
    activity = activity_new()
    engine = engine_fake()
    nearcast_schema = gs_nearcast_schema_new()
    snoop = nearcast_snoop_fake(nearcast_schema=nearcast_schema)
    snoop.disable()
    orb = nearcast_orb_new(engine=engine,
                           nearcast_schema=nearcast_schema,
                           nearcast_snoop=snoop)
    #
    r = orb.init_cog(fn=receiver_cog_fake)
    tcp_server_cog = orb.init_cog(fn=tcp_server_cog_new)
    #
    addr = '127.0.0.1'
    port = 5000
    password = '******'
    #
    # get to a point where the client is logged in
    start_service(orb=orb, ip=addr, port=port, password=password)
    simulate_client_connect(engine=engine,
                            orb=orb,
                            tcp_server_cog=tcp_server_cog,
                            ip=addr,
                            port=port)
    #
    # confirm starting position
    assert 1 == r.count_announce_tcp_connect()
    assert 0 == r.count_please_tcp_boot()
    assert tcp_server_cog.server_sid == None
    assert tcp_server_cog.client_sid != None
    #
    # scenario: send invalid data as though it is gruel
    cs_tcp_recv = CsTcpRecv()
    cs_tcp_recv.engine = engine
    cs_tcp_recv.client_sid = create_sid()
    cs_tcp_recv.data = bytes('this string is invalid gruel', 'utf8')
    tcp_server_cog._engine_on_tcp_recv(cs_tcp_recv=cs_tcp_recv)
    orb.cycle()
    #
    # confirm effects: nearcast a boot message
    assert 1 == r.count_please_tcp_boot()
    assert tcp_server_cog.server_sid != None
    assert tcp_server_cog.client_sid == None
    #
    return True
コード例 #6
0
def should_reject_unauthorised_ip():
    engine = engine_fake()
    nearcast_schema = gs_nearcast_schema_new()
    nearcast_snoop = nearcast_snoop_fake(nearcast_schema=nearcast_schema)
    nearcast_snoop.disable()
    orb = nearcast_orb_new(engine=engine,
                           nearcast_schema=nearcast_schema,
                           nearcast_snoop=nearcast_snoop)
    r = orb.init_cog(fn=receiver_cog_fake)
    ipval_cog = orb.init_cog(fn=ipval_cog_new)
    #
    # scenario: unauth ip connects
    ip = '127.0.0.1'
    port = 5000
    r.nc_announce_tcp_connect(ip=ip, port=port)
    #
    # check effects: we should send a messaage to boot
    assert 1 == r.count_please_tcp_boot()
    #
    return True
コード例 #7
0
def should_allow_any_ip():
    engine = engine_fake()
    nearcast_schema = gs_nearcast_schema_new()
    nearcast_snoop = nearcast_snoop_fake(nearcast_schema=nearcast_schema)
    nearcast_snoop.disable()
    orb = nearcast_orb_new(engine=engine,
                           nearcast_schema=nearcast_schema,
                           nearcast_snoop=nearcast_snoop)
    r = orb.init_cog(fn=receiver_cog_fake)
    ipval_cog = orb.init_cog(fn=ipval_cog_new)
    #
    ip = '127.0.0.1'
    port = 5000
    r.nc_ipval_disable()
    r.nc_announce_tcp_connect(ip=ip, port=port)
    #
    assert 0 == r.count_please_tcp_boot()
    assert 1 == r.count_nearnote()
    #
    return True
コード例 #8
0
ファイル: tcp_server_cog.py プロジェクト: petr-tik/solent
def should_boot_client_when_told_to():
    engine = engine_fake()
    nearcast_schema = gs_nearcast_schema_new()
    snoop = nearcast_snoop_fake(nearcast_schema=nearcast_schema)
    snoop.disable()
    orb = nearcast_orb_new(engine=engine,
                           nearcast_schema=nearcast_schema,
                           nearcast_snoop=snoop)
    #
    r = orb.init_cog(fn=receiver_cog_fake)
    tcp_server_cog = orb.init_cog(fn=tcp_server_cog_new)
    #
    addr = '127.0.0.1'
    port = 5000
    password = '******'
    #
    # get to a point where the client is logged in
    start_service(orb=orb, ip=addr, port=port, password=password)
    simulate_client_connect(engine=engine,
                            orb=orb,
                            tcp_server_cog=tcp_server_cog,
                            ip=addr,
                            port=port)
    #
    # confirm starting position
    assert 1 == r.count_announce_tcp_connect()
    assert tcp_server_cog.server_sid == None
    assert tcp_server_cog.client_sid != None
    #
    # scenario: we receive a boot message
    r.nc_please_tcp_boot()
    #
    # check effects: we want to see that the connection has been dropped and
    # that the server is back up
    assert tcp_server_cog.server_sid != None
    assert tcp_server_cog.client_sid == None
    #
    return True
コード例 #9
0
ファイル: tcp_server_cog.py プロジェクト: petr-tik/solent
def should_broadcast_incoming_message_as_gruel_in():
    engine = engine_fake()
    nearcast_schema = gs_nearcast_schema_new()
    snoop = nearcast_snoop_fake(nearcast_schema=nearcast_schema)
    snoop.disable()
    orb = nearcast_orb_new(engine=engine,
                           nearcast_schema=nearcast_schema,
                           nearcast_snoop=snoop)
    #
    r = orb.init_cog(fn=receiver_cog_fake)
    tcp_server_cog = orb.init_cog(fn=tcp_server_cog_new)
    #
    addr = '127.0.0.1'
    port = 5000
    password = '******'
    #
    # get to a point where the client is logged in
    start_service(orb=orb, ip=addr, port=port, password=password)
    simulate_client_connect(engine=engine,
                            orb=orb,
                            tcp_server_cog=tcp_server_cog,
                            ip=addr,
                            port=port)
    #
    # confirm starting position
    assert 1 == r.count_announce_tcp_connect()
    assert tcp_server_cog.server_sid == None
    assert tcp_server_cog.client_sid != None
    #
    # scenario: client sends a message
    client_send_password = '******'
    client_send_hbint = 3
    simulate_client_send_login(engine=engine,
                               orb=orb,
                               tcp_server_cog=tcp_server_cog,
                               pw=client_send_password,
                               hbint=client_send_hbint)
    #
    # confirm effects
    assert 1 == r.count_gruel_recv()
    d_gruel = r.last_gruel_recv()
    assert d_gruel['message_h'] == 'client_login'
    assert d_gruel['heartbeat_interval'] == client_send_hbint
    assert d_gruel['password'] == client_send_password
    #
    # scenario: client disconnect
    simulate_client_condrop(engine=engine,
                            orb=orb,
                            tcp_server_cog=tcp_server_cog)
    #
    # confirm effects
    assert tcp_server_cog.server_sid != None
    assert tcp_server_cog.client_sid == None
    #
    # scenario: close server
    stop_service(orb=orb)
    #
    # confirm effects
    assert tcp_server_cog.server_sid == None
    assert tcp_server_cog.client_sid == None
    #
    return True