Esempio n. 1
0
    def test_data_message_exception(self):
        """Test that if receive_message raises an exception, the session is terminated"""

        client = mock.Mock()
        client._fqdn = "test_server"

        client.sessions = SessionTable(client)
        session = mock.Mock()
        session.id = 'foo_id'
        client.sessions._sessions['test_plugin'] = session

        session.receive_message = mock.Mock(side_effect=RuntimeError())

        reader = HttpReader(client)
        reader._handle_messages([{
            'type': 'DATA',
            'plugin': 'test_plugin',
            'session_id': 'foo_id',
            'session_seq': None,
            'fqdn': 'test_server',
            'body': {
                'body': 'foo'
            }
        }])

        # Should have called our teardown method
        session.teardown.assertCalledOnce()
        # Should have removed the session
        self.assertNotIn('test_plugin', client.sessions._sessions)
Esempio n. 2
0
    def test_data_message_exception(self):
        """Test that if receive_message raises an exception, the session is terminated"""

        client = mock.Mock()
        client._fqdn = "test_server"

        client.sessions = SessionTable(client)
        session = mock.Mock()
        session.id = "foo_id"
        client.sessions._sessions["test_plugin"] = session

        session.receive_message = mock.Mock(side_effect=RuntimeError())

        reader = HttpReader(client)
        reader._handle_messages([{
            "type": "DATA",
            "plugin": "test_plugin",
            "session_id": "foo_id",
            "session_seq": None,
            "fqdn": "test_server",
            "body": {
                "body": "foo"
            },
        }])

        # Should have called our teardown method
        session.teardown.assertCalledOnce()
        # Should have removed the session
        self.assertNotIn("test_plugin", client.sessions._sessions)
Esempio n. 3
0
    def test_data_message(self):
        client = mock.Mock()
        client._fqdn = "test_server"

        client.sessions = SessionTable(client)
        session = mock.Mock()
        session.id = 'foo_id'
        client.sessions._sessions['test_plugin'] = session

        reader = HttpReader(client)
        reader._handle_messages([{
            'type': 'DATA',
            'plugin': 'test_plugin',
            'session_id': 'foo_id',
            'session_seq': None,
            'fqdn': 'test_server',
            'body': {
                'body': 'foo'
            }
        }])

        session.receive_message.assertCalledOnceWith({'body': 'foo'})
Esempio n. 4
0
    def test_data_message(self):
        client = mock.Mock()
        client._fqdn = "test_server"

        client.sessions = SessionTable(client)
        session = mock.Mock()
        session.id = "foo_id"
        client.sessions._sessions["test_plugin"] = session

        reader = HttpReader(client)
        reader._handle_messages([{
            "type": "DATA",
            "plugin": "test_plugin",
            "session_id": "foo_id",
            "session_seq": None,
            "fqdn": "test_server",
            "body": {
                "body": "foo"
            },
        }])

        session.receive_message.assertCalledOnceWith({"body": "foo"})