Exemple #1
0
    def __init__(self, core, name, force, persist, standby):
        self.core = core
        self.name = name
        self.force = force
        self.persist = persist
        self.standby = standby

        # set handlers for events from core
        self.core.set_call_handler(self.name, self.__on_call)
        self.core.set_interest_handler(self.name, self.__on_interest)
        self.core.add_connection_lost_handler(self.__on_connection_lost)

        self.call_handlers = HandlerList()
        self.interest_handlers = HandlerList()

        # dict used to keep track of what interests present
        self.current_interest = dict()

        # send login verb
        self.verb = verbs.LoginVerb(
            name=encode_name(self.name),
            enforce=self.force,
            standby=self.standby,
            persist=self.persist,
        )

        self.core.put_upstream(self.verb, auto_resend=True)
Exemple #2
0
    def test_login_logout_2(self):
        """ Test if both the login and logout verb are pushed when the connection becomes ready
        after the session is created.
        """

        conn = MockedConnection()
        chan = Channel(conn)

        conn.mock_connection_ready(False)

        session = chan.session('name')

        conn.mock_connection_ready(True)

        conn.assert_upstream_verb(verbs.LoginVerb(
            name=b'name',
            enforce=False,
            standby=False,
            persist=False,
        ))

        session.cancel()

        conn.assert_upstream_verb(verbs.LogoutVerb(
            name=b'name',
        ))

        conn.assert_upstream_verb(None)
Exemple #3
0
def test_login_4(self):
    """ Test that a login packet is send.
    """

    mock = Sysmock()
    mock.system.add_unused_local_address(CLIENT)

    with patch(mock):
        loop = Mainloop()

        mock.expect_tcp_syn(CLIENT, SERVER)
        mock.do_tcp_syn_ack(SERVER, CLIENT)
        mock.do_tcp_input(SERVER, CLIENT, packets.welcome())

        conn = NxtcpConnection(loop, SERVER.address)

        mock.run_events(loop.run_once)

        # the expected packet
        mock.expect_tcp_output(
            CLIENT, SERVER,
            packets.login(
                name=b'name',
                persist=False,
                standby=False,
                enforce=True,
            ))

        # put the verb upstream
        conn.send_verb(
            verbs.LoginVerb(
                name=b'name',
                persist=False,
                standby=False,
                enforce=True,
            ))

        mock.run_events(loop.run_once)