示例#1
0
def exec_test_(func):
    # Can't use functools.partial, because the authenticator is stateful.
    authenticator = SaslEventAuthenticator(JID.split('@')[0], MECHANISMS)
    exec_test(func, do_connect=False, authenticator=authenticator,
        params={'password': None,
                'account' : JID,
               })
def exec_relay_test(incoming, too_slow=None):
    exec_test(partial(run_call_test,
                      GtalkProtocol04(),
                      incoming=incoming,
                      klass=CallGoogleRelayTest,
                      params={'too-slow': too_slow}),
              protocol=GoogleXmlStream)
def exec_test_(func):
    # Can't use functools.partial, because the authenticator is stateful.
    authenticator = SaslEventAuthenticator(JID.split('@')[0], MECHANISMS)
    exec_test(func,
              do_connect=False,
              authenticator=authenticator,
              params={
                  'password': None,
                  'account': JID,
              })
示例#4
0
def exec_file_transfer_test(send_cls, recv_cls, file = None):
        addr_type = cs.SOCKET_ADDRESS_TYPE_IPV4
        access_control = cs.SOCKET_ACCESS_CONTROL_LOCALHOST
        access_control_param = ""

        if file is None:
            file = File()

        def test(q, bus, conns, streams):
            q.timeout = 15
            conn1, conn2 = conns
            stream1, stream2 = streams
            send = send_cls(file, addr_type, access_control,
                            access_control_param)
            recv = recv_cls(file, addr_type, access_control,
                            access_control_param)
            send.test(q, bus, conn1, stream1)
            recv.test(q, bus, conn2, stream2)

            send_action = 0
            recv_action = 0
            target_set = False
            done = False
            while send_action < len(send._actions) or \
                    recv_action < len(recv._actions):
                for i in range(send_action, len(send._actions)):
                    action = send._actions[i]
                    if action is None:
                        break
                    done = action()
                    if done is True:
                        break
                send_action = i + 1

                if done is True:
                    break

                for i in range(recv_action, len(recv._actions)):
                    action = recv._actions[i]
                    if action is None:
                        break
                    done =  action()
                    if done is True:
                        break
                recv_action = i + 1

                if done is True:
                    break

                if target_set == False:
                    send.set_target(recv.self_handle_name)
                    recv.set_target(send.self_handle_name)
                    target_set = True

        exec_test(test, num_instances=2, do_connect=False)
def exec_file_transfer_test(send_cls, recv_cls, file = None):
        addr_type = cs.SOCKET_ADDRESS_TYPE_IPV4
        access_control = cs.SOCKET_ACCESS_CONTROL_LOCALHOST
        access_control_param = ""

        if file is None:
            file = File()

        def test(q, bus, conns, streams):
            q.timeout = 15
            conn1, conn2 = conns
            stream1, stream2 = streams
            send = send_cls(file, addr_type, access_control,
                            access_control_param)
            recv = recv_cls(file, addr_type, access_control,
                            access_control_param)
            send.test(q, bus, conn1, stream1)
            recv.test(q, bus, conn2, stream2)

            send_action = 0
            recv_action = 0
            target_set = False
            done = False
            while send_action < len(send._actions) or \
                    recv_action < len(recv._actions):
                for i in range(send_action, len(send._actions)):
                    action = send._actions[i]
                    if action is None:
                        break
                    done = action()
                    if done is True:
                        break
                send_action = i + 1

                if done is True:
                    break

                for i in range(recv_action, len(recv._actions)):
                    action = recv._actions[i]
                    if action is None:
                        break
                    done =  action()
                    if done is True:
                        break
                recv_action = i + 1

                if done is True:
                    break

                if target_set == False:
                    send.set_target(recv.self_handle_name)
                    recv.set_target(send.self_handle_name)
                    target_set = True

        exec_test(test, num_instances=2, do_connect=False)
def exec_tube_test(test, *args):
    for bytestream_cls in [
            bytestream.BytestreamIBBMsg,
            bytestream.BytestreamIBBIQ,
            bytestream.BytestreamS5B,
            bytestream.BytestreamSIFallbackS5CannotConnect,
            bytestream.BytestreamSIFallbackS5WrongHash,
            bytestream.BytestreamS5BRelay,
            bytestream.BytestreamS5BRelayBugged]:
        exec_test(lambda q, bus, conn, stream:
            test(q, bus, conn, stream, bytestream_cls, *args))
def exec_tube_test(test, *args):
    for bytestream_cls in [
            bytestream.BytestreamIBBMsg,
            bytestream.BytestreamIBBIQ,
            bytestream.BytestreamS5B,
            bytestream.BytestreamSIFallbackS5CannotConnect,
            bytestream.BytestreamSIFallbackS5WrongHash,
            bytestream.BytestreamS5BRelay,
            bytestream.BytestreamS5BRelayBugged]:
        exec_test(lambda q, bus, conn, stream:
            test(q, bus, conn, stream, bytestream_cls, *args))
def exec_file_transfer_test(test_cls):
    for bytestream_cls  in [
            bytestream.BytestreamIBBMsg,
            bytestream.BytestreamS5B,
            bytestream.BytestreamS5BPidgin,
            bytestream.BytestreamSIFallbackS5CannotConnect,
            bytestream.BytestreamSIFallbackS5WrongHash,
            bytestream.BytestreamS5BRelay,
            bytestream.BytestreamS5BRelayBugged]:
        for addr_type, access_control, access_control_param in platform_impls():
            file = File()
            test = test_cls(bytestream_cls, file, addr_type, access_control, access_control_param)
            exec_test(test.test)

            # test resume
            file.offset = 5
            test = test_cls(bytestream_cls, file, addr_type, access_control, access_control_param)
            exec_test(test.test)
示例#9
0
def exec_file_transfer_test(test_cls, one_run=False):
    for bytestream_cls  in [
            bytestream.BytestreamIBBMsg,
            bytestream.BytestreamS5B,
            bytestream.BytestreamS5BPidgin,
            bytestream.BytestreamSIFallbackS5CannotConnect,
            bytestream.BytestreamSIFallbackS5WrongHash,
            bytestream.BytestreamS5BRelay,
            bytestream.BytestreamS5BRelayBugged]:
        for addr_type, access_control, access_control_param in platform_impls():
            file = File()
            test = test_cls(bytestream_cls, file, addr_type, access_control, access_control_param)
            exec_test(test.test)

            # test resume
            file.offset = 5
            test = test_cls(bytestream_cls, file, addr_type, access_control, access_control_param)
            exec_test(test.test)

            if one_run:
                return
    stream.handle_get_all_privacy_lists(
        q, bus, conn, lists=["foo-list", "test-busy-list", "bar-list"])

    get_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set')
    list_node = xpath.queryForNodes('//active', get_list.query)[0]

    # ... and then activates the one linked with the requested status
    # Note: testbusy status is linked to test-busy-list by test plugin
    assertEquals('test-busy-list', list_node['name'])
    acknowledge_iq(stream, get_list.stanza)

    q.expect('dbus-signal',
             signal='PresencesChanged',
             args=[{
                 1: (cs.PRESENCE_BUSY, u'testbusy', '')
             }])
    q.expect('dbus-signal',
             signal='StatusChanged',
             args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])

    # ... testaway is not supposed to be settable on us
    call_async(q, conn.SimplePresence, 'SetPresence', 'testaway', '')
    q.expect('dbus-error', method='SetPresence', name=cs.INVALID_ARGUMENT)


if __name__ == '__main__':
    exec_test(test, protocol=ManualPrivacyListStream, do_connect=False)
    exec_test(test_with_xep0186,
              protocol=Xep0186AndManualPrivacyListStream,
              do_connect=False)
        q.expect_many(
                EventPattern('stream-iq', iq_type='result', iq_id='push'),
                EventPattern('dbus-signal', signal='ContactsChangedWithID',
                    args=[{}, {}, { holly: '*****@*****.**' }]),
                )
    else:
        q.expect_many(
                EventPattern('dbus-return', method=returning_method),
                EventPattern('stream-presence', presence_type='unsubscribed',
                    to='*****@*****.**'),
                )

        send_roster_push(stream, '*****@*****.**', 'to')
        q.expect_many(
                EventPattern('stream-iq', iq_type='result', iq_id='push'),
                EventPattern('dbus-signal', signal='ContactsChangedWithID',
                    args=[{holly:
                        (cs.SUBSCRIPTION_STATE_YES, cs.SUBSCRIPTION_STATE_NO, ''),
                        }, { holly: '*****@*****.**' }, {}]),
                )

def test_modern(q, bus, conn, stream):
    test(q, bus, conn, stream)

def test_modern_remove(q, bus, conn, stream):
    test(q, bus, conn, stream, remove=True)

if __name__ == '__main__':
    exec_test(test_modern)
    exec_test(test_modern_remove)
        call_async(q, media_iface, "RequestStreams", handle, [cs.MEDIA_STREAM_TYPE_AUDIO])

    def send_presence():
        jt.send_remote_presence()
        return q.expect("stream-iq", query_ns=ns.DISCO_INFO, to=jt.remote_jid)

    if request_before_presence:
        # Request streams before either <presence> or caps have arrived. Gabble
        # should wait for both to arrive before returning from RequestStreams.
        call_request_streams()

        # Ensure Gabble's received the method call.
        sync_dbus(bus, q, conn)

        # Now send the presence.
        info_event = send_presence()
    else:
        info_event = send_presence()

        # Now call RequestStreams; it should wait for the disco reply.
        call_request_streams()

    jt.send_remote_disco_reply(info_event.stanza)

    # RequestStreams should now happily complete
    q.expect("dbus-return", method="RequestStreams")


if __name__ == "__main__":
    exec_test(test, timeout=10)
示例#13
0
    """As of 2013-09, a new version of Facebook's XMPP server (used
    consistently for beta.chat.facebook.com, and gradually being rolled out
    for chat.facebook.com users) omits the 'from' attribute in its disco
    reply. The disco reply is otherwise correct.
    """
    def _cb_disco_iq(self, iq):
        nodes = xpath.queryForNodes(
            "/iq/query[@xmlns='" + ns.DISCO_INFO + "']", iq)
        query = nodes[0]

        for feature in self.disco_features:
            query.addChild(elem('feature', var=feature))

        iq['type'] = 'result'

        # The Facebook server's IQ responses have neither 'from' nor 'to'
        try:
            del iq['from']
        except KeyError:
            pass
        try:
            del iq['to']
        except KeyError:
            pass

        self.send(iq)


if __name__ == '__main__':
    exec_test(test, protocol=XmppXmlStreamFacebook201309, do_connect=False)
    }

    send_presence(q, conn, stream, contact1, caps)
    stanza = expect_disco(q, contact1, caps['node'], caps)

    send_presence(q, conn, stream, contact2, caps)
    q.forbid_events([
        EventPattern('stream-iq', to=contact2, query_ns=ns.DISCO_INFO),
    ])
    sync_stream(q, stream)

    send_disco_reply(stream, stanza, BANANAPHONE, features, {})
    q.expect_many(
        EventPattern('dbus-signal',
                     signal='ClientTypesUpdated',
                     args=[h1, ['phone']]),
        # Gabble previously did not emit ClientTypesUpdated for anyone beside
        # the contact we sent the disco request to; so this second event would
        # never arrive.
        EventPattern('dbus-signal',
                     signal='ClientTypesUpdated',
                     args=[h2, ['phone']]),
    )


if __name__ == '__main__':
    exec_test(test)
    exec_test(test2)
    exec_test(partial(two_contacts_with_the_same_hash, bare_jids=False))
    exec_test(partial(two_contacts_with_the_same_hash, bare_jids=True))
def test_dialects(f, dialects, params=None, protocol=None):
    for dialect in dialects:
        exec_test(partial(f, dialect()), params=params, protocol=protocol)
示例#16
0
                assertEquals('I most certainly dont feel like dancing',
                             c.children[0])
            else:
                raise

    for child in iq.children:
        if child.name == 'message':
            check_message(child)
        elif child.name == 'error':
            check_error(child)
        else:
            raise

    # check we can't call anything any more
    call_async(q, chan, 'Fail', ycs.ERROR_TYPE_CANCEL, 'lol', 'whut', 'pear')
    q.expect('dbus-error', method='Fail')

    call_async(q, chan, 'Reply', {'lol': 'whut'}, '')
    q.expect('dbus-error', method='Reply')

    call_async(q, chan, 'Request')
    q.expect('dbus-error', method='Request')


if __name__ == '__main__':
    exec_test(outgoing_reply)
    exec_test(outgoing_fail)
    exec_test(bad_requests)
    exec_test(incoming_reply)
    exec_test(incoming_fail)
示例#17
0
            'PLAIN', 'foo')
    q.expect('dbus-error', method='StartMechanismWithData',
            name=cs.NOT_AVAILABLE)

    authenticator.success(None)
    q.expect('dbus-signal', signal='SASLStatusChanged',
             interface=cs.CHANNEL_IFACE_SASL_AUTH,
             args=[cs.SASL_STATUS_SERVER_SUCCEEDED, '', {}])

    call_async(q, chan.SASLAuthentication, 'Respond',
            'Responding after success')
    q.expect('dbus-error', method='Respond', name=cs.NOT_AVAILABLE)

if __name__ == '__main__':
    exec_test(
        test_plain_success, {'password': None, 'account' : JID},
        authenticator=SaslEventAuthenticator('test', ['PLAIN']),
        do_connect=False)

    exec_test(
        test_plain_no_account,
        {'password': None, 'account' : 'example.com'},
        authenticator=SaslEventAuthenticator('test', ['PLAIN']),
        do_connect=False)

    exec_test(
        test_plain_fail, {'password': None, 'account' : JID},
        authenticator=SaslEventAuthenticator('test', ['PLAIN']),
        do_connect=False)

    exec_test(
        test_plain_bad_encoding, {'password': None, 'account' : JID},
示例#18
0
def test_no_password(q, bus, conn, stream):
    chan, props = connect_and_get_sasl_channel(q, bus, conn)

    chan.Close()

    q.expect_many(
        EventPattern('dbus-signal', path=chan.object_path, signal='Closed'),
        EventPattern('dbus-signal',
                     path=conn.object_path,
                     signal='ChannelClosed',
                     args=[chan.object_path]),
        EventPattern(
            'dbus-signal',
            path=conn.object_path,
            signal='ConnectionError',
            predicate=lambda e: e.args[0] == cs.AUTHENTICATION_FAILED),
        EventPattern(
            'dbus-signal',
            path=conn.object_path,
            signal='StatusChanged',
            args=[cs.CONN_STATUS_DISCONNECTED, cs.CSR_AUTHENTICATION_FAILED]),
    )


if __name__ == '__main__':
    exec_test(test_no_password, {
        'password': None,
        'account': JID
    },
              do_connect=False)
示例#19
0
    test_complex_success(q, bus, conn, stream, False)


def test_complex_success_data_accept(q, bus, conn, stream):
    test_complex_success(q, bus, conn, stream, True, True)


def test_complex_success_no_data_accept(q, bus, conn, stream):
    test_complex_success(q, bus, conn, stream, False, True)


if __name__ == '__main__':
    exec_test(test_complex_success_data, {
        'password': None,
        'account': JID
    },
              authenticator=SaslEventAuthenticator(
                  JID.split('@')[0], MECHANISMS),
              do_connect=False)
    exec_test(test_complex_success_no_data, {
        'password': None,
        'account': JID
    },
              authenticator=SaslEventAuthenticator(
                  JID.split('@')[0], MECHANISMS),
              do_connect=False)
    exec_test(test_complex_success_data_accept, {
        'password': None,
        'account': JID
    },
              authenticator=SaslEventAuthenticator(
    text_event, tube_event = q.expect_many(
        EventPattern('dbus-signal', signal='NewChannels', predicate=new_text),
        EventPattern('dbus-signal', signal='NewChannels', predicate=new_tube))

    channels = e.args[0]
    tube_path, props = tube_event.args[0][0]
    assertEquals(cs.CHANNEL_TYPE_DBUS_TUBE, props[cs.CHANNEL_TYPE])
    assertEquals('[email protected]/test', props[cs.INITIATOR_ID])
    assertEquals(False, props[cs.REQUESTED])
    assertEquals(cs.HT_ROOM, props[cs.TARGET_HANDLE_TYPE])
    assertEquals('com.example.TestCase', props[cs.DBUS_TUBE_SERVICE_NAME])

    _, props = text_event.args[0][0]
    assertEquals(cs.CHANNEL_TYPE_TEXT, props[cs.CHANNEL_TYPE])
    assertEquals(True, props[cs.REQUESTED])

    # tube is local-pending
    tube_chan = bus.get_object(conn.bus_name, tube_path)
    state = tube_chan.Get(cs.CHANNEL_IFACE_TUBE,
                          'State',
                          dbus_interface=dbus.PROPERTIES_IFACE)
    assertEquals(cs.TUBE_STATE_LOCAL_PENDING, state)


if __name__ == '__main__':
    # We can't use t.exec_dbus_tube_test() as we can use only the muc bytestream
    exec_test(lambda q, bus, conn, stream: test(
        q, bus, conn, stream, cs.SOCKET_ACCESS_CONTROL_CREDENTIALS))
    exec_test(lambda q, bus, conn, stream: test(
        q, bus, conn, stream, cs.SOCKET_ACCESS_CONTROL_LOCALHOST))
    assertLength(1, message)
    header = message[0]

    assertEquals(handle, header['message-sender'])
    assertEquals(cs.MT_DELIVERY_REPORT, header['message-type'])
    assertEquals(cs.DELIVERY_STATUS_ACCEPTED, header['delivery-status'])

    assertContains('delivery-echo', header)
    echo = header['delivery-echo']
    echo_header, echo_body = echo

    assertEquals(conn.Properties.Get(cs.CONN, "SelfHandle"),
                 echo_header['message-sender'])
    assertEquals('text/plain', echo_body['content-type'])
    assertEquals(text, echo_body['content'])

    channel.Text.AcknowledgePendingMessages([header['pending-message-id']])
    channel.Close()

    # Now test receiving an own-message stanza for a message sent to a contact
    # we don't have a channel open for. It should be ignored (but acked). This
    # is consistent with delivery failure reports.
    q.forbid_events([EventPattern('dbus-signal', signal='MessageReceived')])
    send_own_message(to='*****@*****.**',
                     text=u'please ignore this message')
    sync_dbus(bus, q, conn)


if __name__ == '__main__':
    exec_test(test, params={'account': '*****@*****.**'})
    request = \
        elem_iq(stream, 'get', from_='[email protected]/resource')(
          elem(ns.DISCO_INFO, 'query', node=node)
        )
    stream.send(request)

    disco_response = q.expect('stream-iq',
                              query_ns=ns.DISCO_INFO,
                              iq_id=request['id'])
    nodes = xpath.queryForNodes('/iq/query/feature', disco_response.stanza)
    vars = [n["var"] for n in nodes]
    assertEquals(set(features), set(vars))


def run_test(q, bus, conn, stream):
    event_stream = q.expect('stream-presence')

    c_nodes = xpath.queryForNodes('/presence/c', event_stream.stanza)
    assert c_nodes is not None
    assert len(c_nodes) == 1
    node = c_nodes[0].attributes['node']

    disco_bundle(q, bus, conn, stream, node + '#voice-v1',
                 set([ns.GOOGLE_FEAT_VOICE]))
    disco_bundle(q, bus, conn, stream, node + '#video-v1',
                 set([ns.GOOGLE_FEAT_VIDEO]))


if __name__ == '__main__':
    exec_test(run_test)
def test_google(q, bus, conn, stream):
    test(q, bus, conn, stream, is_google=True)

def test(q, bus, conn, stream, is_google=False):
    props = conn.GetAll(cs.CONN_IFACE_CONTACT_INFO,
            dbus_interface=cs.PROPERTIES_IFACE)
    check_normal_props(props)

    conn.Connect()

    q.expect('dbus-signal', signal='StatusChanged',
            args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])

    props = conn.GetAll(cs.CONN_IFACE_CONTACT_INFO,
            dbus_interface=cs.PROPERTIES_IFACE)

    if is_google:
        check_google_props(props)

        # on a Google server, we can't use most vCard fields
        call_async(q, conn.ContactInfo, 'SetContactInfo',
                [('x-jabber', [], ['*****@*****.**'])])
        q.expect('dbus-error', method='SetContactInfo',
                name=cs.INVALID_ARGUMENT)
    else:
        check_normal_props(props)

if __name__ == '__main__':
    exec_test(test, do_connect=False)
    exec_test(test_google, protocol=GoogleXmlStream, do_connect=False)
    assertEquals([], props[cs.CONFERENCE_INITIAL_INVITEE_HANDLES])


def test_create_pmuc_with_invitee(q, conn, stream):

    # Open an initial 1-to-1 connection
    props = {
        cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT,
        cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
        cs.TARGET_ID: 'bob@localhost',
    }

    call_async(q, conn.Requests, 'EnsureChannel', props)
    r = q.expect('dbus-return', method='EnsureChannel')

    assert len(r.value) == 3
    yours, path, props = r.value

    pmuc_name, path, props = create_pmuc(
        q, conn, stream, {
            cs.CONFERENCE_INITIAL_CHANNELS: dbus.Array([path], signature='o'),
        })

    # FIXME: check for stream-message containing invite for Bob

    assertEquals(['bob@localhost'], props[cs.CONFERENCE_INITIAL_INVITEE_IDS])


if __name__ == '__main__':
    exec_test(test, params={'fallback-conference-server': 'conf.localhost'})
示例#25
0
            })

    q.expect('dbus-error', name=cs.INVALID_ARGUMENT, method='EnsureChannel')

    # Now a channel which already exists (any of the above) with
    # a non-conflicting Server set.
    jid = '*****@*****.**'
    call_async(q, conn.Requests, 'EnsureChannel', {
            cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT,
            cs.TARGET_HANDLE_TYPE: cs.HT_ROOM,
            cs.TARGET_ID: jid,
            cs.ROOM_SERVER: 'conf.localhost',
            })

    q.expect('dbus-return', method='EnsureChannel')

    # Now a channel which already exists (any of the above) with
    # a conflicting Server set.
    jid = '*****@*****.**'
    call_async(q, conn.Requests, 'EnsureChannel', {
            cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT,
            cs.TARGET_HANDLE_TYPE: cs.HT_ROOM,
            cs.TARGET_ID: jid,
            cs.ROOM_SERVER: 'lol.conf.localhost',
            })

    q.expect('dbus-error', name=cs.INVALID_ARGUMENT, method='EnsureChannel')

if __name__ == '__main__':
    exec_test(test, params={ 'fallback-conference-server': 'fallback.conf.localhost' } )
def main():
    for i in xrange(0, 2000):
        print i
        exec_test(test)
    print("we partied like it's %i" % i)
示例#27
0
def main():
    for i in xrange(0, 2000):
        print i
        exec_test(test)
    print "we partied like it's %i" % i
    # tube and text is created
    text_event, tube_event = q.expect_many(EventPattern('dbus-signal', signal='NewChannels',
                                                        predicate=new_text),
                                           EventPattern('dbus-signal', signal='NewChannels',
                                                        predicate=new_tube))

    channels = e.args[0]
    tube_path, props = tube_event.args[0][0]
    assertEquals(cs.CHANNEL_TYPE_DBUS_TUBE, props[cs.CHANNEL_TYPE])
    assertEquals('[email protected]/test', props[cs.INITIATOR_ID])
    assertEquals(False, props[cs.REQUESTED])
    assertEquals(cs.HT_ROOM, props[cs.TARGET_HANDLE_TYPE])
    assertEquals('com.example.TestCase', props[cs.DBUS_TUBE_SERVICE_NAME])

    _, props = text_event.args[0][0]
    assertEquals(cs.CHANNEL_TYPE_TEXT, props[cs.CHANNEL_TYPE])
    assertEquals(True, props[cs.REQUESTED])

    # tube is local-pending
    tube_chan = bus.get_object(conn.bus_name, tube_path)
    state = tube_chan.Get(cs.CHANNEL_IFACE_TUBE, 'State',
            dbus_interface=dbus.PROPERTIES_IFACE)
    assertEquals(cs.TUBE_STATE_LOCAL_PENDING, state)

if __name__ == '__main__':
    # We can't use t.exec_dbus_tube_test() as we can use only the muc bytestream
    exec_test(lambda q, bus, conn, stream:
        test(q, bus, conn, stream, cs.SOCKET_ACCESS_CONTROL_CREDENTIALS))
    exec_test(lambda q, bus, conn, stream:
        test(q, bus, conn, stream, cs.SOCKET_ACCESS_CONTROL_LOCALHOST))
    acknowledge_iq(stream, event.stanza)
    q.expect('dbus-return', method='SetLocation')


# PEP is not supported.
def test_no_pep(q, bus, conn, stream):
    call_async(q, conn.Location, 'SetLocation', {'lat': 0.0, 'lon': 0.0})

    q.expect('dbus-error', name=cs.NOT_IMPLEMENTED)


#PEP is advertised using the right protocol
def test_pep(q, bus, conn, stream):
    call_async(q, conn.Location, 'SetLocation', {'lat': 0.0, 'lon': 0.0})

    geoloc_iq_set_event = EventPattern(
        'stream-iq',
        predicate=lambda x: xpath.queryForNodes(
            "/iq/pubsub/publish/item/geoloc", x.stanza))

    event = q.expect_many(geoloc_iq_set_event)[0]

    acknowledge_iq(stream, event.stanza)
    q.expect('dbus-return', method='SetLocation')


if __name__ == '__main__':
    exec_test(test_legacy, protocol=PepInServerDiscoXmlStream)
    exec_test(test_no_pep, protocol=GoogleXmlStream)
    exec_test(test_pep)
示例#30
0
        q.expect_many(EventPattern('dbus-signal',
                                   signal='ContactCapabilitiesChanged',
                                   path=conn2.object.object_path,
                                   args=[{conn2_handle:generic_ft_caps}]),
                      EventPattern('stream-presence', stream=stream2),
                      EventPattern('dbus-signal',
                                   signal='ContactCapabilitiesChanged',
                                   path=conn1.object.object_path,
                                   args=[{handle2:generic_ft_caps}]))

    presence_c = xpath.queryForNodes('/presence/c', presence.stanza)[0]
    assert "share-v1" in presence_c.attributes['ext']

    # We will have the same capabilities on both sides, so we can't check for
    # a cap disco since the hash will be the same, so we need to make sure the
    # hash is indeed the same
    assert presence_c.attributes['ver'] == conn1_ver

    found_share = False
    for feature in xpath.queryForNodes('/iq/query/feature', disco.stanza):
        if feature.attributes['var'] == ns.GOOGLE_FEAT_SHARE:
            found_share = True
    assert found_share

    check_contact_caps(conn1, handle2, True)


if __name__ == '__main__':
    exec_test(test)
    exec_test(test2, num_instances=2)
                   ('PCMU', 0, 8000, {'choppy': 'false'}),
                 ]
    # As per the XEP, it only sends the ones which have changed.
    c = new_codecs[2]
    node = jp.SetIq(jt2.peer, jt2.jid, [
        jp.Jingle(jt2.sid, jt2.peer, 'description-info', [
            jp.Content(audio_content, 'initiator', 'both',
                jp.Description('audio', [
                    jp.PayloadType(c[0], str(c[2]), str(c[1]), c[3])
                ])) ]) ])
    stream.send(jp.xml(node))

    # Gabble should patch its idea of the remote codecs with the update it just
    # got, and emit SetRemoteCodecs for them all.
    e = q.expect('dbus-signal', signal='SetRemoteCodecs')
    new_codecs_dbus = unwrap(jt2.dbusify_codecs_with_params(new_codecs))
    announced = unwrap(e.args[0])
    assert new_codecs_dbus == announced, (new_codecs_dbus, announced)

    # We close the session by removing the stream
    chan.StreamedMedia.RemoveStreams([id1])

    e = q.expect('stream-iq', iq_type='set', predicate=lambda x:
        xpath.queryForNodes("/iq/jingle[@action='session-terminate']",
            x.stanza))

if __name__ == '__main__':
    exec_test(test)
    exec_test(early_description_info)

示例#32
0
    assertEquals(
        False,
        conn.Get(cs.CONN_IFACE_POWER_SAVING,
                 "PowerSavingActive",
                 dbus_interface=cs.PROPERTIES_IFACE))


def test_disconnect(q, bus, conn, stream):
    assertContains(
        cs.CONN_IFACE_POWER_SAVING,
        conn.Get(cs.CONN, "Interfaces", dbus_interface=cs.PROPERTIES_IFACE))

    assertEquals(
        False,
        conn.Get(cs.CONN_IFACE_POWER_SAVING,
                 "PowerSavingActive",
                 dbus_interface=cs.PROPERTIES_IFACE))

    call_async(q, conn.PowerSaving, 'SetPowerSaving', True)

    stanza = expect_command(q, 'enable')

    disconnect_conn(q, conn, stream)


if __name__ == '__main__':
    exec_test(test, protocol=GoogleXmlStream)
    exec_test(test_local_queueing)
    exec_test(test_error, protocol=GoogleXmlStream)
    exec_test(test_disconnect, protocol=GoogleXmlStream)
示例#33
0
    q.expect('dbus-return', method='StartMechanismWithData')

    q.expect('dbus-signal', signal='SASLStatusChanged',
             interface=cs.CHANNEL_IFACE_SASL_AUTH,
             args=[cs.SASL_STATUS_SERVER_SUCCEEDED, '', {}])

    # fd.o#32278:
    # When this was breaking, gabble received AcceptSASL and told the
    # success_async GAsyncResult to complete in an idle. But, before
    # the result got its callback called, Close was also received and
    # the auth manager cleared its channel. When the idle function was
    # finally reached it saw it no longer had a channel (it had been
    # cleared in the closed callback) and thought it should be
    # chaining up to the wocky auth registry but of course it should
    # be calling the channel finish function.
    call_async(q, chan.SASLAuthentication, 'AcceptSASL')
    call_async(q, chan, 'Close')

    q.expect('dbus-signal', signal='SASLStatusChanged',
             interface=cs.CHANNEL_IFACE_SASL_AUTH,
             args=[cs.SASL_STATUS_SUCCEEDED, '', {}])

    e = q.expect('dbus-signal', signal='StatusChanged',
                 args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])

if __name__ == '__main__':
    exec_test(test_close_straight_after_accept,
              {'password': None, 'account' : "*****@*****.**"},
              do_connect=False)
示例#34
0
    q.unforbid_all()

def test(q, bus, conn, stream):
    path = conn.Requests.CreateChannel(
            { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT,
              cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
              cs.TARGET_ID: GUYBRUSH,
              })[0]
    chan = wrap_channel(bus.get_object(conn.bus_name, path), 'Text')

    # Let's start out with an empty roster, eh?
    e = q.expect('stream-iq', iq_type='get', query_ns=ns.ROSTER)
    e.stanza['type'] = 'result'
    stream.send(e.stanza)

    report_received_on_open_channel(q, bus, conn, stream, chan)
    report_ignored_without_channel(q, bus, conn, stream)
    not_sending_request_to_contact(q, bus, conn, stream, chan)

    # FIXME: This test is disabled because of stupidity in the presence cache.
    # See the comment in receipts_conceivably_supported().
    #sending_request_to_presenceless_contact(q, bus, conn, stream, chan)

    sending_request_to_cappy_contact(q, bus, conn, stream, chan)

    replying_to_requests(q, bus, conn, stream)


if __name__ == '__main__':
    exec_test(test, protocol=Xep0186Stream)
示例#35
0
        conn.MailNotification.RequestInboxURL()
    except dbus.DBusException as e:
        assert e.get_dbus_name() == cs.NOT_IMPLEMENTED

    try:
        conn.MailNotification.RequestMailURL("1", "http://test.com/mail")
    except dbus.DBusException as e:
        assert e.get_dbus_name() == cs.NOT_IMPLEMENTED

    # Make sure all properties return with empty or 0 data including
    # MailNotificationFlags
    check_properties_empty(conn)

    q.unforbid_events(forbidden)


def test(q, bus, conn, stream):
    interfaces = conn.Properties.Get(cs.CONN, 'Interfaces')

    if stream.__class__ is GoogleXmlStream:
        assert cs.CONN_IFACE_MAIL_NOTIFICATION in interfaces
        test_google_featured(q, bus, conn, stream)
    else:
        assert cs.CONN_IFACE_MAIL_NOTIFICATION not in interfaces
        test_no_google_featured(q, bus, conn, stream)


if __name__ == '__main__':
    exec_test(test, protocol=GoogleXmlStream)
    exec_test(test)
示例#36
0
    authenticator.success(None)
    q.expect('dbus-signal',
             signal='SASLStatusChanged',
             interface=cs.CHANNEL_IFACE_SASL_AUTH,
             args=[cs.SASL_STATUS_SERVER_SUCCEEDED, '', {}])

    call_async(q, chan.SASLAuthentication, 'Respond',
               'Responding after success')
    q.expect('dbus-error', method='Respond', name=cs.NOT_AVAILABLE)


if __name__ == '__main__':
    exec_test(test_plain_success, {
        'password': None,
        'account': JID
    },
              authenticator=SaslEventAuthenticator('test', ['PLAIN']),
              do_connect=False)

    exec_test(test_plain_no_account, {
        'password': None,
        'account': 'example.com'
    },
              authenticator=SaslEventAuthenticator('test', ['PLAIN']),
              do_connect=False)

    exec_test(test_plain_fail, {
        'password': None,
        'account': JID
    },
              authenticator=SaslEventAuthenticator('test', ['PLAIN']),
示例#37
0
        args=[cs.CONN_STATUS_DISCONNECTED, cs.CSR_AUTHENTICATION_FAILED])

def test_redirection(q, bus, conn, stream):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged',
        args=[cs.CONN_STATUS_CONNECTING, cs.CSR_REQUESTED])

    event = q.expect('stream-iq', query_ns=ns.REGISTER)
    result = make_result_iq(stream, event.stanza)
    query = result.firstChildElement()
    query.addElement((None, 'instructions')).addChild("Sigh.")
    # Tell the user to go to some website
    url = query.addElement((ns.X_OOB, 'x')).addElement((None, 'url'))
    url.addChild("http://foogle.talk.example/newaccount")

    stream.send(result)

    # This is really WOCKY_CONNECTOR_ERROR_REGISTRATION_UNSUPPORTED
    e = q.expect('dbus-signal', signal='ConnectionError')
    assertEquals(cs.NOT_AVAILABLE, e.args[0])
    q.expect('dbus-signal', signal='StatusChanged',
        args=[cs.CONN_STATUS_DISCONNECTED, cs.CSR_AUTHENTICATION_FAILED])

if __name__ == '__main__':
    exec_test(test_success, {'register': True}, do_connect=False)
    exec_test(test_conflict, {'register': True}, do_connect=False)
    exec_test(test_with_email, {'register': True}, do_connect=False)
    exec_test(test_data_forms, {'register': True}, do_connect=False)
    exec_test(test_redirection, {'register': True}, do_connect=False)

    parts = e.args[0]

    header = parts[0]
    assertEquals(bob_handle, header['message-sender'])
    assertEquals(bob_jid, header['message-sender-id'])

    body = parts[1]
    assertEquals('hello again', body['content'])

    assert_on_bus(q, tube_chan)
    assert_on_bus(q, text_chan)


if __name__ == '__main__':
    # request tube, assert no text appears
    exec_test(tube_no_text)

    # request tube, request text (no presence), assert both appear
    exec_test(tube_then_text)

    # request tube & text, close text, assert tube doesn't close
    exec_test(tube_remains_text_closes)

    # request text, close text, assert unavailable presence
    exec_test(normally_close_text)

    # request tube, close tube, assert unavailable presence
    exec_test(text_can_automatically_close)

    # request tube & text, close tube, assert text doesn't close
    exec_test(text_remains_after_tube)
示例#39
0
    if request_before_presence:
        # Request streams before either <presence> or caps have arrived. Gabble
        # should wait for both to arrive before returning from RequestStreams.
        call_request_streams()

        # Ensure Gabble's received the method call.
        sync_dbus(bus, q, conn)

        # Now send the presence.
        info_event = send_presence()
    else:
        info_event = send_presence()

        # Now call RequestStreams; it should wait for the disco reply.
        call_request_streams()

    jt.send_remote_disco_reply(info_event.stanza)

    # RequestStreams should now happily complete
    if channel_type == cs.CHANNEL_TYPE_STREAMED_MEDIA:
        q.expect('dbus-return', method='RequestStreams')
    else:
        q.expect('dbus-return', method='CreateChannel')

if __name__ == '__main__':
    exec_test(lambda q, bus, conn, stream:
        test(q, bus, conn, stream, cs.CHANNEL_TYPE_STREAMED_MEDIA), timeout=10)
    exec_test(lambda q, bus, conn, stream:
        test(q, bus, conn, stream, cs.CHANNEL_TYPE_CALL), timeout=10)

示例#40
0
    # pending local send:
    streams = sm.ListStreams()
    assert len(streams) == 2, streams
    video_streams = [s for s in streams if s[2] == cs.MEDIA_STREAM_TYPE_VIDEO]
    assert len(video_streams) == 1, streams
    stream_id, h, _, state, direction, pending = video_streams[0]
    assert stream_id == video_stream_id, (stream_id, video_stream_id)
    assert h == remote_handle, (h, remote_handle)
    assert state == cs.MEDIA_STREAM_STATE_CONNECTED, state
    assert direction == cs.MEDIA_STREAM_DIRECTION_RECEIVE, direction
    assert pending == cs.MEDIA_STREAM_PENDING_LOCAL_SEND, pending

    # Let's accept the stream; the direction should change, and we should be
    # told to start sending.
    call_async(q, sm, 'RequestStreamDirection', video_stream_id,
        cs.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL)

    # The stream's direction should change, and we should be told to start
    # playing.
    q.expect_many(
        EventPattern('dbus-signal', signal='StreamDirectionChanged',
            args=[video_stream_id, cs.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL, 0]),
        EventPattern('dbus-signal', signal='SetStreamSending', args=[True]),
        )

    # That'll do, pig. That'll do.

if __name__ == '__main__':
    exec_test(test)
    exec_test(test_bare_jid)
示例#41
0
        assertEquals(expected_recipient, e.to)

    features = [ ns.JINGLE_RTP, ns.JINGLE_RTP_AUDIO, ns.JINGLE_RTP_VIDEO
               ] + all_transports

    # My cat is signed in with their laptop (which is available)...
    laptop_jid = 'cat@windowsill/Laptop'
    sign_in_a_cat(laptop_jid, ['client/pc//clocks'])

    # ...and a web client, which is away.
    cloud_jid = 'cat@windowsill/Cloud'
    sign_in_a_cat(cloud_jid, ['client/web//zomg'], show='away')

    # The laptop is more available, so the call should go there.
    make_call(expected_recipient=laptop_jid)

    # But if my cat signs in with a phone, also set to away...
    phone_jid = 'cat@windowsill/Fido'
    sign_in_a_cat(phone_jid, ['client/phone//mars rover'], show='away')

    # ...then calls should go there, even though the laptop is more available.
    make_call(expected_recipient=phone_jid)

if __name__ == '__main__':
    exec_test(test)

    exec_test(partial(test_prefer_phones, expect_disco=True))
    # And again, this time pulling the caps from the cache. This tests that the
    # quirk is cached!
    exec_test(partial(test_prefer_phones, expect_disco=False))
示例#42
0
    assertEquals(ERRORS[which], e.args[1])
    assertContains('debug-message', e.args[2])

    e = q.expect('dbus-signal', signal='ConnectionError')
    assertEquals(ERRORS[which], e.args[0])
    assertContains('debug-message', e.args[1])

    e = q.expect('dbus-signal', signal='StatusChanged')
    assertEquals(cs.CONN_STATUS_DISCONNECTED, e.args[0])
    assertEquals(CSRS[which], e.args[1])

def test_jabber_pass_not_authorized(q, bus, conn, stream):
    test_jabber_pass_fail(q, bus, conn, stream, 'not-authorized')

def test_jabber_pass_conflict(q, bus, conn, stream):
    test_jabber_pass_fail(q, bus, conn, stream, 'conflict')

def test_jabber_pass_not_acceptable(q, bus, conn, stream):
    test_jabber_pass_fail(q, bus, conn, stream, 'not-acceptable')

if __name__ == '__main__':
    for test in (
            # these are Examples 5 to 8 of XEP-0078
            test_jabber_pass_success, test_jabber_pass_not_authorized,
            test_jabber_pass_conflict, test_jabber_pass_not_acceptable):
        exec_test(
            test, {'password': None, 'account' : JID},
            protocol=JabberXmlStream,
            authenticator=JabberAuthenticator(JID.split('@')[0], PASSWORD,
                emit_events=True), do_connect=False)
示例#43
0
    assert 'image/jpeg' in types, types
    assert 'image/gif' in types, types
    assert minw == 32, minw
    assert minh == 32, minh
    assert maxw == 96, maxw
    assert maxh == 96, maxh
    assert maxb == 8192, maxb
    assert recw == 64, recw
    assert rech == 64, rech

def test(q, bus, conn, stream):
    test_get_all(conn)

    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged',
            args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])

    test_get_all(conn)

    # deprecated version
    props = conn.Properties.GetAll(cs.CONN_IFACE_AVATARS)
    assertEquals(['image/png', 'image/jpeg', 'image/gif'], props['SupportedAvatarMIMETypes'])
    assertEquals(32, props['MinimumAvatarWidth'])
    assertEquals(32, props['MinimumAvatarHeight'])
    assertEquals(96, props['MaximumAvatarWidth'])
    assertEquals(96, props['MaximumAvatarHeight'])
    assertEquals(8192, props['MaximumAvatarBytes'])

if __name__ == '__main__':
    exec_test(test, do_connect=False)
    e = q.expect('dbus-signal', signal='MessageReceived')
    message, = e.args
    assertLength(1, message)
    header = message[0]

    assertEquals(handle, header['message-sender'])
    assertEquals(cs.MT_DELIVERY_REPORT, header['message-type'])
    assertEquals(cs.DELIVERY_STATUS_ACCEPTED, header['delivery-status'])

    assertContains('delivery-echo', header)
    echo = header['delivery-echo']
    echo_header, echo_body = echo

    assertEquals(conn.GetSelfHandle(), echo_header['message-sender'])
    assertEquals('text/plain', echo_body['content-type'])
    assertEquals(text, echo_body['content'])

    channel.Text.AcknowledgePendingMessages([header['pending-message-id']])
    channel.Close()

    # Now test receiving an own-message stanza for a message sent to a contact
    # we don't have a channel open for. It should be ignored (but acked). This
    # is consistent with delivery failure reports.
    q.forbid_events([EventPattern('dbus-signal', signal='MessageReceived')])
    send_own_message(to='*****@*****.**',
        text=u'please ignore this message')
    sync_dbus(bus, q, conn)

if __name__ == '__main__':
    exec_test(test, params={'account': '*****@*****.**'})
示例#45
0
def test_dialects(f, dialects):
    for dialect in dialects:
        exec_test(partial(f, dialect()))
             value='*****@*****.**',
             action='deny',
             order='2')(elem(u'message'))
    ])

    # We redundantly re-activate the 'invisible' list. These lines also
    # check to see that we didn't switch over to 'invisible-gabble'
    activate_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set')
    active = xpath.queryForNodes('//active', activate_list.stanza)[0]
    assertEquals(active["name"], 'invisible')
    acknowledge_iq(stream, activate_list.stanza)


if __name__ == '__main__':
    exec_test(test_invisible,
              protocol=ManualPrivacyListStream,
              do_connect=False)
    exec_test(test_invisible_on_connect,
              protocol=ManualPrivacyListStream,
              do_connect=False)
    exec_test(test_create_invisible_list,
              protocol=ManualPrivacyListStream,
              do_connect=False)
    exec_test(test_create_invisible_list_failed,
              protocol=ManualPrivacyListStream,
              do_connect=False)
    exec_test(test_invisible_on_connect_fail_no_list,
              protocol=ManualPrivacyListStream,
              do_connect=False)
    exec_test(test_invisible_on_connect_fail_invalid_list,
              protocol=ManualPrivacyListStream,
"""
Regression test.

 - the 'alias' connection parameter is set
 - our vCard doesn't have a NICKNAME field
 - we crash when trying to save a vcard with NICKNAME set to the alias
   parameter
"""

from gabbletest import (exec_test, expect_and_handle_get_vcard,
                        expect_and_handle_set_vcard)


def test(q, bus, conn, stream):
    expect_and_handle_get_vcard(q, stream)

    def check_vcard(vcard):
        for e in vcard.elements():
            if e.name == 'NICKNAME':
                assert str(e) == 'Some Guy', e.toXml()
                return
        assert False, vcard.toXml()

    expect_and_handle_set_vcard(q, stream, check_vcard)


if __name__ == '__main__':
    exec_test(test, params={'alias': 'Some Guy'})
    # But then Bob kicks us.
    bob_jid = '%s/bob' % MUC
    bob_handle = conn.get_contact_handle_sync(bob_jid)
    stream.send(
        elem('presence', from_=muc_self_jid,
             type='unavailable')(elem(ns.MUC_USER, 'x')(
                 elem('item',
                      affiliation='none', role='none')(elem('actor',
                                                            jid=bob_jid),
                                                       elem('reason')(u'bye')),
                 elem('status', code='307'),
             )))

    mcd_event = q.expect('dbus-signal', signal='MembersChangedDetailed')
    added, removed, local_pending, remote_pending, details = mcd_event.args
    assertEquals([], added)
    assertEquals([muc_self_handle], removed)
    assertEquals([], local_pending)
    assertEquals([], remote_pending)
    assertContains('actor', details)
    assertEquals(bob_handle, details['actor'])
    assertEquals(cs.GC_REASON_KICKED, details['change-reason'])
    assertEquals('bye', details['message'])

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


if __name__ == '__main__':
    exec_test(test)
示例#49
0
    conn.SimplePresence.SetPresence('testbusy', '')

    conn.Connect()

    # ... gabble asks for all the available lists on the server ...
    stream.handle_get_all_privacy_lists(q, bus, conn,
        lists=["foo-list", "test-busy-list", "bar-list"])

    get_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set')
    list_node = xpath.queryForNodes('//active', get_list.query)[0]

    # ... and then activates the one linked with the requested status
    # Note: testbusy status is linked to test-busy-list by test plugin
    assertEquals('test-busy-list', list_node['name'])
    acknowledge_iq(stream, get_list.stanza)

    q.expect('dbus-signal', signal='PresencesChanged',
        args=[{1L: (cs.PRESENCE_BUSY, u'testbusy', '')}])
    q.expect('dbus-signal', signal='StatusChanged',
        args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])

    # ... testaway is not supposed to be settable on us
    call_async(q, conn.SimplePresence, 'SetPresence', 'testaway', '')
    q.expect('dbus-error', method='SetPresence', name=cs.INVALID_ARGUMENT)


if __name__ == '__main__':
    exec_test(test, protocol=ManualPrivacyListStream, do_connect=False)
    exec_test(test_with_xep0186, protocol=Xep0186AndManualPrivacyListStream, do_connect=False)

def test(q, bus, conn, stream, is_google=False):
    props = conn.GetAll(cs.CONN_IFACE_CONTACT_INFO,
                        dbus_interface=cs.PROPERTIES_IFACE)
    check_normal_props(props)

    conn.Connect()

    q.expect('dbus-signal',
             signal='StatusChanged',
             args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])

    props = conn.GetAll(cs.CONN_IFACE_CONTACT_INFO,
                        dbus_interface=cs.PROPERTIES_IFACE)

    if is_google:
        check_google_props(props)

        # on a Google server, we can't use most vCard fields
        call_async(q, conn.ContactInfo, 'SetContactInfo',
                   [('x-jabber', [], ['*****@*****.**'])])
        q.expect('dbus-error',
                 method='SetContactInfo',
                 name=cs.INVALID_ARGUMENT)
    else:
        check_normal_props(props)


if __name__ == '__main__':
    exec_test(test, do_connect=False)
    exec_test(test_google, protocol=GoogleXmlStream, do_connect=False)
    # close the channel early
    chan.Close()

    # we expect the fallback verification process to not accept the hostname;
    # it doesn't match the JID's hostname nor the hostnames in the
    # extra-certificate-identities parameter
    q.expect_many(
        EventPattern('dbus-signal', signal='Closed'),
        EventPattern('dbus-signal', signal='ChannelClosed'),
        EventPattern('dbus-signal', signal='StatusChanged',
                     args=[cs.CONN_STATUS_DISCONNECTED, cs.CSR_CERT_HOSTNAME_MISMATCH])
        )

if __name__ == '__main__':
    exec_test(test_connect_success, { 'account' : JID },
              authenticator=TlsAuthenticator(username='******', password='******'), do_connect=False)
    exec_test(test_connect_fail, { 'account' : JID },
              authenticator=TlsAuthenticator(username='******', password='******'), do_connect=False)
    exec_test(test_connect_early_close_success,
              { 'account' : JID,
                'ignore-ssl-errors' : False,
                'require-encryption' : False },
              authenticator=TlsAuthenticator(username='******', password='******'), do_connect=False)
    exec_test(test_connect_early_close_fail,
              { 'account' : JID,
                'ignore-ssl-errors' : False,
                'require-encryption' : True },
              authenticator=TlsAuthenticator(username='******', password='******'), do_connect=False)
    exec_test(test_disconnect_inbetween, { 'account' : JID },
              authenticator=TlsAuthenticator(username='******', password='******'), do_connect=False)
import constants as cs

from config import FILE_TRANSFER_ENABLED

if not FILE_TRANSFER_ENABLED:
    print "NOTE: built with --disable-file-transfer"
    raise SystemExit(77)

class IbbTooEarlyTest (ReceiveFileTest):
    def __init__ (self):
        ReceiveFileTest.__init__ (self,
            bytestream.BytestreamIBBMsg,
            File (),
            cs.SOCKET_ADDRESS_TYPE_UNIX,
            cs.SOCKET_ACCESS_CONTROL_LOCALHOST,
            "")

    def accept_file (self):
        # Instead of us accepting the other side starts sending the iq open
        # skip the open step explicitely
        self.bytestream.checked = True
        event = self.bytestream.open_bytestream(
            expected_after = [ EventPattern ('stream-iq', iq_type = 'error') ] )
        return True



if __name__ == '__main__':
    exec_test (IbbTooEarlyTest().test)
示例#53
0
import ns

def disco_bundle(q, bus, conn, stream, node, features):
    request = \
        elem_iq(stream, 'get', from_='[email protected]/resource')(
          elem(ns.DISCO_INFO, 'query', node=node)
        )
    stream.send(request)

    disco_response = q.expect('stream-iq', query_ns=ns.DISCO_INFO,
            iq_id=request['id'])
    nodes = xpath.queryForNodes('/iq/query/feature', disco_response.stanza)
    vars = [n["var"] for n in nodes]
    assertEquals(set(features), set(vars))

def run_test(q, bus, conn, stream):
    event_stream = q.expect('stream-presence')

    c_nodes = xpath.queryForNodes('/presence/c', event_stream.stanza)
    assert c_nodes is not None
    assert len(c_nodes) == 1
    node = c_nodes[0].attributes['node']

    disco_bundle(q, bus, conn, stream, node + '#voice-v1',
            set([ns.GOOGLE_FEAT_VOICE]))
    disco_bundle(q, bus, conn, stream, node + '#video-v1',
            set([ns.GOOGLE_FEAT_VIDEO]))

if __name__ == '__main__':
    exec_test(run_test)
示例#54
0
                         event.stanza['id'] == set_id),
        EventPattern('stream-iq', query_ns=ns.PRIVACY, iq_type="get"))

    stream.send_privacy_list(req_list.stanza,
        [elem('item', action='deny', order='1')(elem(u'presence-out')),
         elem('item', type='jid', value='*****@*****.**', action='deny',
              order='2')(elem(u'message'))])

    # We redundantly re-activate the 'invisible' list. These lines also
    # check to see that we didn't switch over to 'invisible-gabble'
    activate_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set')
    active = xpath.queryForNodes('//active', activate_list.stanza)[0]
    assertEquals(active["name"], 'invisible')
    acknowledge_iq (stream, activate_list.stanza)

if __name__ == '__main__':
    exec_test(test_invisible, protocol=ManualPrivacyListStream,
              do_connect=False)
    exec_test(test_invisible_on_connect, protocol=ManualPrivacyListStream,
              do_connect=False)
    exec_test(test_create_invisible_list, protocol=ManualPrivacyListStream,
              do_connect=False)
    exec_test(test_invisible_on_connect_fail_no_list,
              protocol=ManualPrivacyListStream, do_connect=False)
    exec_test(test_invisible_on_connect_fail_invalid_list,
              protocol=ManualPrivacyListStream, do_connect=False)
    exec_test(test_privacy_list_push_valid, protocol=ManualPrivacyListStream,
              do_connect=False)
    exec_test(test_privacy_list_push_conflict, protocol=ManualPrivacyListStream,
              do_connect=False)
示例#55
0
import dbus

from servicetest import EventPattern
from gabbletest import exec_test
import constants as cs
from saslutil import connect_and_get_sasl_channel

JID = '*****@*****.**'

def test_no_password(q, bus, conn, stream):
    chan, props = connect_and_get_sasl_channel(q, bus, conn)

    chan.Close()

    q.expect_many(
            EventPattern('dbus-signal', path=chan.object_path,
                signal='Closed'),
            EventPattern('dbus-signal', path=conn.object_path,
                signal='ChannelClosed', args=[chan.object_path]),
            EventPattern('dbus-signal', path=conn.object_path,
                signal='ConnectionError',
                predicate=lambda e: e.args[0] == cs.AUTHENTICATION_FAILED),
            EventPattern('dbus-signal', path=conn.object_path,
                signal='StatusChanged', args=[cs.CONN_STATUS_DISCONNECTED,
                    cs.CSR_AUTHENTICATION_FAILED]),
            )

if __name__ == '__main__':
    exec_test(test_no_password, {'password': None,'account' : JID}, do_connect=False)
    assertEquals(transport_stanza['ufrag'], jt2.remote_transports[0][7])
    # password
    assertEquals(transport_stanza['pwd'], jt2.remote_transports[0][8])

    children = list(transport_stanza.elements())
    assertLength(1, children)

    stream.send(jp.xml(jp.ResultIq('test@localhost', e.stanza, [])))

    # Set codec intersection so gabble can accept the session
    stream_handler.SupportedCodecs(jt2.get_audio_codecs_dbus())

    # Second one is session-accept
    e = q.expect('stream-iq', predicate=jp.action_predicate('session-accept'))
    assert xpath.queryForNodes("/iq/jingle/content/transport[@xmlns='%s']" %
        ns.JINGLE_TRANSPORT_ICEUDP, e.stanza)

    stream.send(jp.xml(jp.ResultIq('test@localhost', e.stanza, [])))

    # Connected! Blah, blah, ...

    jt2.terminate()

    e = q.expect('dbus-signal', signal='Close')

def test031(q, bus, conn, stream):
    return worker(JingleProtocol031(),q, bus, conn, stream)

if __name__ == '__main__':
    exec_test(test031)
示例#57
0
    # Fredrik switches too.
    stream.send(make_muc_presence('none', 'participant', MUC, 'fredrik',
          photo=AVATAR_1_SHA1))
    q.expect('dbus-signal', signal='AvatarUpdated',
        args=[fredrik, AVATAR_1_SHA1])

    # And we switch to some other avatar. Gabble should update its vCard, and
    # then update its MUC presence (which the test, acting as the MUC server,
    # must echo).
    call_async(q, conn.Avatars, 'SetAvatar', AVATAR_2_DATA, AVATAR_2_MIME_TYPE)
    expect_and_handle_get_vcard(q, stream)
    expect_and_handle_set_vcard(q, stream)

    muc_presence = q.expect('stream-presence', to=('%s/test' % MUC))
    directed_hash = extract_hash_from_presence(muc_presence.stanza)
    stream.send(make_muc_presence('owner', 'moderator', MUC, 'test',
          photo=directed_hash))

    # Gabble should signal an avatar update for both our global self-handle and
    # our MUC self-handle. (The first of these of course does not need to wait
    # for the MUC server to echo our presence.)
    q.expect_many(
        EventPattern('dbus-signal', signal='AvatarUpdated',
            args=[self_handle, AVATAR_2_SHA1]),
        EventPattern('dbus-signal', signal='AvatarUpdated',
            args=[muc_self_handle, AVATAR_2_SHA1]),
        )

if __name__ == '__main__':
    exec_test(test)
示例#58
0
        for status in ('not going to', 'be actually set'):
            _test_local_status(q, conn, stream, status, show)
            assertEquals(expected_list, stream.shared_status_lists)

def test_shared_status_chat(q, bus, conn, stream):
    '''Test that 'chat' is not supported with shared status'''
    q.expect_many(EventPattern('stream-iq', query_ns=ns.GOOGLE_SHARED_STATUS,
                               iq_type='get'),
                  EventPattern('stream-iq', query_ns=ns.GOOGLE_SHARED_STATUS,
                               iq_type='set'),
                  EventPattern('stream-presence'))

    try:
        conn.SimplePresence.SetPresence('chat', 'This is not going to work')
    except dbus.DBusException, e:
        assert e.get_dbus_name() == cs.NOT_AVAILABLE
    else:
        assert False

if __name__ == '__main__':
    exec_test(test, protocol=SharedStatusStream)
    exec_test(test_connect_available, protocol=SharedStatusStream, do_connect=False)
    exec_test(test_connect_chat, protocol=SharedStatusStream, do_connect=False)
    exec_test(test_connect_dnd, protocol=SharedStatusStream, do_connect=False)
    exec_test(test_connect_hidden, protocol=SharedStatusStream, do_connect=False)
    exec_test(test_connect_hidden_future_version, protocol=SharedStatusStream, do_connect=False)
    exec_test(test_connect_hidden_not_available, protocol=SharedStatusStream, do_connect=False)
    exec_test(test_shared_status_list, protocol=SharedStatusStream)
    exec_test(test_shared_status_away, protocol=SharedStatusStream)
    exec_test(test_shared_status_chat, protocol=SharedStatusStream)