Example #1
0
    def test_keepalive_1(self):
        """ Test if a client will receive a ping client after 10 seconds, and will
        be disconnected after another 10 seconds.
        """

        s = setup_story(1)

        s.expect_local_wait(10.0)
        s.expect_local_send(LHOST, PEER1, packets.ping())
        s.expect_local_wait(10.0)
        s.expect_local_send(LHOST, PEER1, packets.byebye())
        s.expect_local_close(LHOST, PEER1)
        s.expect_local_idle()

        with SysMock(s):
            main(['--nxtcp', ':9999'])
Example #2
0
    def test_shutdown_sigint(self):
        """ Test if the server will send byebye packet and close connection on SIGINT.
        """

        s = setup_story(1)

        s.do_remote_signal(signal.SIGINT)

        s.expect_local_close(LHOST)

        s.expect_local_send(LHOST, PEER1, packets.byebye())

        s.expect_local_wait(5.0)

        s.expect_local_close(LHOST, PEER1)

        with SysMock(s):
            main(['--nxtcp', ':9999'])
Example #3
0
def test_byebye_1(self):
    """ Test that the client closes the connection when the server sends a byebye packet BEFORE the welcome packet.
    """

    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)

        conn = NxtcpConnection(loop, SERVER.address)

        mock.run_events(loop.run_once)

        mock.do_tcp_input(SERVER, CLIENT, packets.byebye())

        mock.expect_tcp_fin(CLIENT, SERVER)

        mock.run_events(loop.run_once)
 def test_byebye(self):
     self.assertEncodePacket(ByeByePacket(), packets.byebye())