"""
Test connecting to a server which closes the socket mid-login handshake.

https://bugs.freedesktop.org/show_bug.cgi?id=48084
"""

from idletest import exec_test, BaseIRCServer

class DropConnectionServer(BaseIRCServer):
    def handleNICK(self, args, prefix):
        self.transport.loseConnection()

def test(q, bus, conn, stream):
    conn.Connect()
    # Idle should start to connect...
    q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])

    # ...and then give up with an error when the server drops the connection
    # mid-handshake.
    q.expect('dbus-signal', signal='StatusChanged', args=[2, 2])

if __name__ == '__main__':
    exec_test(test, protocol=DropConnectionServer)

Esempio n. 2
0
    def looks_like_a_room_list(event):
        channels, = event.args
        if len(channels) != 1:
            return False
        path, props = channels[0]

        return props[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_ROOM_LIST and \
            props[cs.TARGET_HANDLE_TYPE] == cs.HT_NONE and \
            props[cs.TARGET_ID] == ''

    e = q.expect('dbus-signal',
                 signal='NewChannels',
                 predicate=looks_like_a_room_list)

    chan = bus.get_object(conn.bus_name, path)
    list_chan = dbus.Interface(chan, cs.CHANNEL_TYPE_ROOM_LIST)
    list_chan.ListRooms()
    q.expect('dbus-signal',
             signal='GotRooms',
             predicate=lambda x: check_rooms(x.args[0]))

    call_async(q, conn, 'Disconnect')
    q.expect_many(
        EventPattern('dbus-return', method='Disconnect'),
        EventPattern('dbus-signal', signal='StatusChanged', args=[2, 1]))
    return True


if __name__ == '__main__':
    exec_test(test, protocol=RoomListServer)
Esempio n. 3
0
    chan.RemoveMembers([self_handle],
                       "bye bye cruel\r\nworld",
                       dbus_interface=cs.CHANNEL_IFACE_GROUP)

    part_event = q.expect('stream-PART')

    # This is a regression test for
    # <https://bugs.freedesktop.org/show_bug.cgi?id=34812>, where part messages
    # were not correctly colon-quoted.
    #
    # It is also a regression test for
    # <https://bugs.freedesktop.org/show_bug.cgi?id=34840>, where newlines
    # weren't stripped from part messages. We check that both \r and \n are
    # replaced by harmless spaces.
    assertEquals("bye bye cruel  world", part_event.data[1])

    stream.sendPart('#idletest', stream.nick)

    q.expect('dbus-signal', signal='Closed')

    chans = conn.Get(cs.CONN_IFACE_REQUESTS,
                     'Channels',
                     dbus_interface=cs.PROPERTIES_IFACE)
    assert len(chans) == 0


if __name__ == '__main__':
    exec_test(test, protocol=DelayJoinServer)
    exec_test(functools.partial(test, use_room=True), protocol=DelayJoinServer)
Esempio n. 4
0
class IgnoreQuitServer(BaseIRCServer):
    def handleUSER(self, args, prefix):
        #do nothing: don't send a welcome message
        self.event_func(make_irc_event('irc-user', None))

    def handleQUIT(self, args, prefix):
        # wait a little while and then send a welcome message
        reactor.callLater(5, self.sendWelcome)

def test(q, bus, conn, stream):
    conn.Connect()
    q.expect_many(
            EventPattern('dbus-signal', signal='StatusChanged', args=[1, 1]),
            EventPattern('irc-connected'))
    q.expect('irc-user');
    # this should send a QUIT message to the server, but the test server should not
    # respond properly, and will instead wait a while and then send a WELCOME msg
    call_async(q, conn, 'Disconnect')
    # the proper behavior of the CM is to disconnect, but the existing error is
    # that it will parse the welcome message and attempt to go to CONNECTED
    # state, which will cause an assertion to fail and the CM to crash
    q.expect_many(
            EventPattern('dbus-signal', signal='StatusChanged', args=[2, 1]),
            EventPattern('irc-disconnected'),
            EventPattern('dbus-return', method='Disconnect'))
    return True

if __name__ == '__main__':
    exec_test(test, timeout=10, protocol=IgnoreQuitServer)

Esempio n. 5
0
"""
Test Network error Handling with SSL servers
"""

import dbus
from idletest import exec_test, SSLIRCServer


def test(q, bus, conn, stream):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged',
             args=[1, 1])  # connecting, requested
    q.expect('dbus-signal', signal='StatusChanged',
             args=[2, 2])  # disconnected, network-error


if __name__ == '__main__':
    # there is no ssl server listening at port 5600, so this should fail
    exec_test(test, {'port': dbus.UInt32(5600), 'use-ssl': dbus.Boolean(True)})
            EventPattern('dbus-signal', signal='StatusChanged', args=[1, 1]),
            EventPattern('irc-connected'))
    q.expect('dbus-signal', signal='SelfHandleChanged',
        args=[1L])
    q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])

    CHANNEL_NAME = "#idletest"

    self_handle = conn.Get(CONN, 'SelfHandle', dbus_interface=PROPERTIES_IFACE)

    # The bouncer initiates a JOIN.
    path = test_join_bouncer(q, conn, stream, CHANNEL_NAME)

    # We PART.
    chan = make_channel_proxy(conn, path, 'Channel')
    chan.RemoveMembers([self_handle], "bye bye cruel world",
        dbus_interface=CHANNEL_IFACE_GROUP)
    q.expect('dbus-signal', signal='MembersChanged')

    # The bouncer initiates a JOIN to force the issue.
    test_join_bouncer(q, conn, stream, CHANNEL_NAME)

    call_async(q, conn, 'Disconnect')
    q.expect_many(
            EventPattern('dbus-return', method='Disconnect'),
            EventPattern('dbus-signal', signal='StatusChanged', args=[2, 1]))
    return True

if __name__ == '__main__':
    exec_test(test)
from servicetest import EventPattern, call_async
from twisted.internet import reactor, ssl


class QuitNoCloseServer(BaseIRCServer):
    def handleQUIT(self, args, prefix):
        quit_msg = ' '.join(args)
        self.sendMessage(
            'ERROR', ':Closing Link: idle.test.server (Quit: %s)' % quit_msg)
        # don't call self.transport.loseConnection()


def test(q, bus, conn, stream):
    conn.Connect()
    q.expect_many(
        EventPattern('dbus-signal', signal='StatusChanged', args=[1, 1]),
        EventPattern('irc-connected'))
    q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
    call_async(q, conn, 'Disconnect')
    # the test server won't drop the connection upon receiving a QUIT message --
    # test that we still exit and respond properly after a certain amount of time
    q.expect_many(
        EventPattern('dbus-signal', signal='StatusChanged', args=[2, 1]),
        EventPattern('irc-disconnected'),
        EventPattern('dbus-return', method='Disconnect'))
    return True


if __name__ == '__main__':
    exec_test(test, timeout=10, protocol=QuitNoCloseServer)
"""
Test connecting to a SSL server.
"""

import dbus
import constants as cs
from idletest import exec_test, SSLIRCServer
from servicetest import EventPattern, wrap_channel

def test(q, bus, conn, stream):
    conn.Connect()
    q.expect_many(
            EventPattern('dbus-signal', signal='StatusChanged', args=[1, 1]),
            EventPattern('irc-connected'))
    e = q.expect('dbus-signal', signal='NewChannels')
    channels = e.args[0]
    path, props = channels[0]

    channel = wrap_channel(bus.get_object(conn.bus_name, path),
        cs.CHANNEL_TYPE_SERVER_TLS_CONNECTION)
    channel.Close()

    q.expect('dbus-signal', signal='StatusChanged', args=[2, 2])

if __name__ == '__main__':
    exec_test(test, {'use-ssl':dbus.Boolean(True)}, protocol=SSLIRCServer)

"""

from idletest import exec_test, BaseIRCServer, make_irc_event
from servicetest import EventPattern, call_async
from twisted.internet import reactor, ssl

class QuitNoCloseServer(BaseIRCServer):
    def handleQUIT(self, args, prefix):
        quit_msg = ' '.join(args)
        self.sendMessage('ERROR', ':Closing Link: idle.test.server (Quit: %s)' % quit_msg)
        # don't call self.transport.loseConnection()

def test(q, bus, conn, stream):
    conn.Connect()
    q.expect_many(
            EventPattern('dbus-signal', signal='StatusChanged', args=[1, 1]),
            EventPattern('irc-connected'))
    q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
    call_async(q, conn, 'Disconnect')
    # the test server won't drop the connection upon receiving a QUIT message --
    # test that we still exit and respond properly after a certain amount of time
    q.expect_many(
            EventPattern('dbus-signal', signal='StatusChanged', args=[2, 1]),
            EventPattern('irc-disconnected'),
            EventPattern('dbus-return', method='Disconnect'))
    return True

if __name__ == '__main__':
    exec_test(test, timeout=10, protocol=QuitNoCloseServer)

    sync_stream(q, stream)
    q.unforbid_events(patterns)

    chan.RemoveMembers([self_handle], "bye bye cruel\r\nworld",
        dbus_interface=cs.CHANNEL_IFACE_GROUP)

    part_event = q.expect('stream-PART')

    # This is a regression test for
    # <https://bugs.freedesktop.org/show_bug.cgi?id=34812>, where part messages
    # were not correctly colon-quoted.
    #
    # It is also a regression test for
    # <https://bugs.freedesktop.org/show_bug.cgi?id=34840>, where newlines
    # weren't stripped from part messages. We check that both \r and \n are
    # replaced by harmless spaces.
    assertEquals("bye bye cruel  world", part_event.data[1])

    stream.sendPart('#idletest', stream.nick)

    q.expect('dbus-signal', signal='Closed')

    chans = conn.Get(cs.CONN_IFACE_REQUESTS, 'Channels',
        dbus_interface=cs.PROPERTIES_IFACE)
    assert len(chans) == 0

if __name__ == '__main__':
    exec_test(test, protocol=DelayJoinServer)
    exec_test(functools.partial(test, use_room=True), protocol=DelayJoinServer)

Esempio n. 11
0
    timestamp = e.data[0]
    stream.sendMessage('PONG',
                       'idle.test.server',
                       ':%s' % timestamp,
                       prefix='idle.test.server')

    # Apparently bip replies like this:
    e = q.expect('stream-PING')
    assertLength(1, e.data)
    timestamp = e.data[0]
    stream.sendMessage('PONG', timestamp, prefix='idle.test.server')

    q.expect('stream-PING')
    # If we don't answer Idle's ping, after some period of time Idle should
    # give up and close the connection.
    q.expect_many(
        EventPattern('irc-disconnected'),
        EventPattern('dbus-signal',
                     signal='StatusChanged',
                     args=[cs.CONN_STATUS_DISCONNECTED, cs.CSR_NETWORK_ERROR]),
    )


if __name__ == '__main__':
    # We expect Idle to blow up the connection after three intervals without a
    # reply. So the default 5-second test timeout *should* just be enough, but
    # let's not risk it.
    exec_test(test, timeout=10, params={
        'keepalive-interval': 1,
    })
Esempio n. 12
0
"""
Test connecting to a server which closes the socket mid-login handshake.

https://bugs.freedesktop.org/show_bug.cgi?id=48084
"""

from idletest import exec_test, BaseIRCServer


class DropConnectionServer(BaseIRCServer):
    def handleNICK(self, args, prefix):
        self.transport.loseConnection()


def test(q, bus, conn, stream):
    conn.Connect()
    # Idle should start to connect...
    q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])

    # ...and then give up with an error when the server drops the connection
    # mid-handshake.
    q.expect('dbus-signal', signal='StatusChanged', args=[2, 2])


if __name__ == '__main__':
    exec_test(test, protocol=DropConnectionServer)
"""
Test Network error Handling
"""

import dbus
from idletest import exec_test

def test(q, bus, conn, stream):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged', args=[1,1])
    q.expect('dbus-signal', signal='StatusChanged', args=[2,2])

if __name__ == '__main__':
    exec_test(test, {'port': dbus.UInt32(5600)})

Esempio n. 14
0
            TARGET_ID: CHANNEL
        })

    # wait for the join to finish
    ret = q.expect('dbus-return', method='CreateChannel')
    muc_path = ret.value
    chan = bus.get_object(conn.bus_name, ret.value[0])
    group_text_chan = dbus.Interface(chan, CHANNEL_TYPE_TEXT)
    group_text_chan.connect_to_signal('Received', group_received_cb)
    q.expect('dbus-signal', signal='MembersChanged')

    stream.sendMessage('PRIVMSG', NICK, ':PRIVATE', prefix=REMOTEUSER)

    event = q.expect('dbus-signal', signal='Received')
    # this seems a bit fragile, but I'm not entirely sure how else to ensure
    # that the message is not delivered to the MUC channel
    assert event.path not in muc_path

    # verify that we didn't receive a 'Received' D-Bus signal on the group text
    # channel
    global group_received_flag
    sync_dbus(bus, q, conn)
    assert group_received_flag == False

    call_async(q, conn, 'Disconnect')
    return True


if __name__ == '__main__':
    exec_test(test, {'account': NICK})
"""
Test Network error Handling with SSL servers
"""

import dbus
from idletest import exec_test, SSLIRCServer

def test(q, bus, conn, stream):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged', args=[1,1]) # connecting, requested
    q.expect('dbus-signal', signal='StatusChanged', args=[2,2]) # disconnected, network-error

if __name__ == '__main__':
    # there is no ssl server listening at port 5600, so this should fail
    exec_test(test, {'port': dbus.UInt32(5600), 'use-ssl': dbus.Boolean(True)})
Esempio n. 16
0
                     ('Private', True),
                     ('Password', True),
                     ('Limit', 99)]:
        call_async(q, chan.RoomConfig1, 'UpdateConfiguration',
                   {key: val})

        q.expect('dbus-error', method='UpdateConfiguration',
                 name=cs.PERMISSION_DENIED)

    # op the user
    change_channel_mode(stream, '+o test')
    q.expect('dbus-signal', signal='PropertiesChanged',
             args=[cs.CHANNEL_IFACE_ROOM_CONFIG,
                   {'CanUpdateConfiguration': True},
                   []])

    # remove ops again
    change_channel_mode(stream, '-o test')
    q.expect('dbus-signal', signal='PropertiesChanged',
             args=[cs.CHANNEL_IFACE_ROOM_CONFIG,
                   {'CanUpdateConfiguration': False},
                   []])

if __name__ == '__main__':
    exec_test(test_props_present)
    exec_test(test_simple_bools)
    exec_test(test_limit)
    exec_test(test_password)
    exec_test(test_modechanges)
    exec_test(test_mode_no_op)
Esempio n. 17
0
"""
Test Network error Handling
"""

import dbus
from idletest import exec_test


def test(q, bus, conn, stream):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])
    q.expect('dbus-signal', signal='StatusChanged', args=[2, 2])


if __name__ == '__main__':
    exec_test(test, {'port': dbus.UInt32(5600)})
Esempio n. 18
0
"""
Test connecting to a SSL server.
"""

import dbus
import constants as cs
from idletest import exec_test, SSLIRCServer
from servicetest import EventPattern, wrap_channel


def test(q, bus, conn, stream):
    conn.Connect()
    q.expect_many(
        EventPattern('dbus-signal', signal='StatusChanged', args=[1, 1]),
        EventPattern('irc-connected'))
    e = q.expect('dbus-signal', signal='NewChannels')
    channels = e.args[0]
    path, props = channels[0]

    channel = wrap_channel(bus.get_object(conn.bus_name, path),
                           cs.CHANNEL_TYPE_SERVER_TLS_CONNECTION)
    channel.Close()

    q.expect('dbus-signal', signal='StatusChanged', args=[2, 2])


if __name__ == '__main__':
    exec_test(test, {'use-ssl': dbus.Boolean(True)}, protocol=SSLIRCServer)
Esempio n. 19
0
from servicetest import EventPattern, call_async
import dbus


def test(q, bus, conn, stream):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])

    stream.sendMessage('PRIVMSG',
                       stream.nick,
                       ':testing testing',
                       prefix='-bip')
    q.expect('dbus-signal', signal='Received')
    # FIXME: we should be lenient and accept unicode nicks that we recieve
    # from remote servers, but twisted can't seem to send unicode text so I
    # don't seem to be able to test this :(
    #stream.sendMessage('PRIVMSG', stream.nick, ':testing testing', prefix=u'김정은')
    #q.expect('dbus-signal', signal='Received')
    stream.sendMessage('PRIVMSG',
                       stream.nick,
                       ':testing testing',
                       prefix='12foo')
    q.expect('dbus-signal', signal='Received')

    call_async(q, conn, 'Disconnect')
    return True


if __name__ == '__main__':
    exec_test(test)
Esempio n. 20
0
              TARGET_ID: CHANNEL_NAME })

    ret = q.expect('dbus-return', method='CreateChannel')
    q.expect('dbus-signal', signal='MembersChanged')
    chan = bus.get_object(conn.bus_name, ret.value[0])

    text_chan = dbus.Interface(chan, CHANNEL_TYPE_TEXT)
    # send a whole bunch of messages in a row
    call_async(q, text_chan, 'Send', 0, LONG_MESSAGE)

    # apparently we only emit one 'Sent' signal even if we split a message up
    # and send it in multiple messages
    q.expect('dbus-signal', signal='Sent')

    part1 = q.expect('dbus-signal', signal='Received')
    n = len(part1.args[5])
    assert n <= 512, "Message exceeds IRC maximum: %d" % n
    part2 = q.expect('dbus-signal', signal='Received')
    n = len(part2.args[5])
    assert n <= 512, "Message exceeds IRC maximum: %d" % n
    received_msg = part1.args[5] + part2.args[5]

    assert received_msg == LONG_MESSAGE, received_msg

    call_async(q, conn, 'Disconnect')
    return True

if __name__ == '__main__':
    exec_test(test, protocol=LongMessageMangler)