Пример #1
0
    def test_broken_message_worker_exception(self, mocker):
        connection = Connection(uuid.uuid4(), 'server', 445, True)

        mock_transport = mocker.MagicMock()
        connection.transport = mock_transport
        connection.transport.recv.side_effect = Exception('test')
        connection._process_message_thread()

        with pytest.raises(Exception, match='test'):
            connection.send(SMB2Echo())

        with pytest.raises(Exception, match='test'):
            connection.receive(None)
Пример #2
0
    def test_broken_message_worker_closed_socket(self, smb_real):
        connection = Connection(uuid.uuid4(), smb_real[2], smb_real[3], True)
        connection.connect()
        try:
            test_msg = SMB2NegotiateRequest()
            test_req = Request(test_msg, type(test_msg), connection)
            connection.outstanding_requests[666] = test_req

            # Close the connection manually
            connection.transport.close()

            with pytest.raises(SMBConnectionClosed):
                connection.receive(test_req)

            with pytest.raises(SMBConnectionClosed):
                connection.send(SMB2NegotiateRequest())
        finally:
            connection.disconnect()