Ejemplo n.º 1
0
def test(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')

    stream.send(make_result_iq(stream, stanza, False))

    q.expect_many(EventPattern('dbus-return', method='SetPowerSaving'),
                  EventPattern('dbus-signal', signal='PowerSavingChanged',
                               args=[True]))

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

    pattern = [EventPattern('stream-iq', query_name='query',
                            query_ns=ns.GOOGLE_QUEUE),
               EventPattern('dbus-signal', signal='PowerSavingChanged',
                            args=[True])]

    q.forbid_events(pattern)

    # Enabling power saving again should be a no-op.
    call_async(q, conn.PowerSaving, 'SetPowerSaving', True)

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

    q.unforbid_events(pattern)

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

    stanza = expect_command(q, 'disable')

    stream.send(make_result_iq(stream, stanza, False))

    event, _, _ = q.expect_many(
        EventPattern('stream-iq', query_name='query', query_ns=ns.GOOGLE_QUEUE),
        EventPattern('dbus-return', method='SetPowerSaving'),
        EventPattern('dbus-signal', signal='PowerSavingChanged',
                     args=[False]))

    command = event.query.firstChildElement()
    assertEquals("flush", command.name)

    assertEquals (False, conn.Get(cs.CONN_IFACE_POWER_SAVING,
                                  "PowerSavingActive",
                                  dbus_interface=cs.PROPERTIES_IFACE))
Ejemplo n.º 2
0
def proxies_telepathy_im(q, bus, conn, stream):
    # Test if proxies.telepathy.im is properly used when no fallback proxies
    # are passed to Gabble
    connect_and_announce_alice(q, bus, conn, stream)

    send_file_to_alice(q, conn)

    # Gabble asks for a proxy list to our server
    return_event, e, = q.expect_many(
        EventPattern('dbus-return', method='CreateChannel'),
        EventPattern('stream-iq',
                     to='proxies.telepathy.im',
                     iq_type='get',
                     query_ns=ns.DISCO_ITEMS))

    # reply with 2 servers
    reply = make_result_iq(stream, e.stanza)
    query = xpath.queryForNodes('/iq/query', reply)[0]
    item = query.addElement((None, 'item'))
    item['jid'] = 'proxy1.localhost'
    item = query.addElement((None, 'item'))
    item['jid'] = 'proxy2.localhost'
    stream.send(reply)

    # These servers are queried
    e1, e2 = q.expect_many(
        EventPattern('stream-iq',
                     to='proxy1.localhost',
                     iq_type='get',
                     query_ns=ns.BYTESTREAMS),
        EventPattern('stream-iq',
                     to='proxy2.localhost',
                     iq_type='get',
                     query_ns=ns.BYTESTREAMS))
def test(q, bus, conn, stream):
    conn.Connect()
    _, iq_event = q.expect_many(
        EventPattern('dbus-signal', signal='StatusChanged',
            args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]),
        EventPattern('stream-iq', to=None, query_ns='vcard-temp',
            query_name='vCard'))

    acknowledge_iq(stream, iq_event.stanza)

    handle = conn.RequestHandles(1, ['*****@*****.**'])[0]
    conn.Avatars.RequestAvatars([handle])
    conn.Avatars.RequestAvatars([handle])
    conn.Avatars.RequestAvatars([handle])
    conn.Avatars.RequestAvatars([handle])

    iq_event = q.expect('stream-iq', to='*****@*****.**', query_ns='vcard-temp',
        query_name='vCard')
    iq = make_result_iq(stream, iq_event.stanza)
    vcard = iq.firstChildElement()
    photo = vcard.addElement('PHOTO')
    photo.addElement('TYPE', content='image/png')
    photo.addElement('BINVAL', content=base64.b64encode('hello'))
    stream.send(iq)

    event = q.expect('dbus-signal', signal='AvatarRetrieved')

    q.forbid_events([EventPattern('dbus-signal', signal='AvatarRetrieved')])
def test(q, bus, conn, stream):
    conn.Connect()
    _, event = q.expect_many(
        EventPattern('dbus-signal', signal='StatusChanged',
            args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]),
        EventPattern('stream-iq', to=None, query_ns='vcard-temp',
            query_name='vCard'))

    acknowledge_iq(stream, event.stanza)
    # Force Gabble to process the vCard before calling any methods.
    sync_stream(q, stream)

    handle = conn.GetSelfHandle()
    call_async(q, conn.Avatars, 'SetAvatar', 'william shatner',
        'image/x-actor-name')

    event = q.expect('stream-iq', iq_type='get', to=None,
        query_ns='vcard-temp', query_name='vCard')
    reply = make_result_iq(stream, event.stanza)
    reply['type'] = 'error'
    reply.addChild(elem('error')(
        elem(ns.STANZA, 'forbidden')(),
        elem(ns.STANZA, 'text')(u'zomg whoops')))
    stream.send(reply)

    event = q.expect('dbus-error', method='SetAvatar', name=cs.NOT_AVAILABLE)
def make_caps_disco_reply(stream, req, identities, features, dataforms={}):
    iq = make_result_iq(stream, req)
    query = iq.firstChildElement()

    for identity in identities:
        category, type_, lang, name = identity.split('/')
        el = query.addElement('identity')
        el['category'] = category
        el['type'] = type_
        el['name'] = name
        el['xml:lang'] = lang

    for f in features:
        el = domish.Element((None, 'feature'))
        el['var'] = f
        query.addChild(el)

    for type, fields in dataforms.iteritems():
        x = query.addElement((ns.X_DATA, 'x'))
        x['type'] = 'result'

        field = x.addElement('field')
        field['var'] = 'FORM_TYPE'
        field['type'] = 'hidden'
        field.addElement('value', content=type)

        for var, values in fields.iteritems():
            field = x.addElement('field')
            field['var'] = var

            for value in values:
                field.addElement('value', content=value)

    return iq
Ejemplo n.º 6
0
def send_results_extended(stream, iq, results, fields):
    result = make_result_iq(stream, iq)
    query = result.firstChildElement()

    x = query.addElement((ns.X_DATA, 'x'))
    x['type'] = 'result'

    x.addElement('title', content='Search result')

    # add reported fields
    reported = x.addElement('reported')
    for var, type, label, options in fields:
        field = reported.addElement('field')
        field['var'] = var
        field['label'] = label

    # add results
    for r in results:
        item = x.addElement('item')
        for var, value in r.items():
            field = item.addElement('field')
            field['var'] = var
            field.addElement('value', content=value)

    stream.send(result)
Ejemplo n.º 7
0
def no_server_discovered(q, bus, conn, stream, server=None):
    iq_event, disco_event = q.expect_many(
        EventPattern('stream-iq',
                     to=None,
                     query_ns='vcard-temp',
                     query_name='vCard'),
        EventPattern('stream-iq', to='localhost', query_ns=ns.DISCO_ITEMS))

    acknowledge_iq(stream, iq_event.stanza)

    # no search server has been discovered yet. The CreateChannel operation
    # will fail once the disco process is finished.
    call_create(q, conn, server=server)

    # reply to IQ query. No search server is present
    reply = make_result_iq(stream, disco_event.stanza)
    stream.send(reply)

    # creation of the channel failed
    e = q.expect('dbus-error',
                 method='CreateChannel',
                 name=cs.INVALID_ARGUMENT)

    # This server doesn't have a search server. We can't create Search channel
    # without specifying a Server property
    call_create(q, conn, server=server)
    e = q.expect('dbus-error', method='CreateChannel')
    assertEquals(cs.INVALID_ARGUMENT, e.error.get_dbus_name())
Ejemplo n.º 8
0
def test(q, bus, conn, stream):
    event = q.expect('stream-iq', to=None, query_ns='vcard-temp',
            query_name='vCard')

    acknowledge_iq(stream, event.stanza)

    handle = conn.RequestHandles(1, ['*****@*****.**'])[0]
    call_async(q, conn.Aliasing, 'RequestAliases', [handle])

    # Nack PEP query.
    event = q.expect('stream-iq', to='*****@*****.**', iq_type='get',
        query_ns='http://jabber.org/protocol/pubsub', query_name='pubsub')
    items = event.query.firstChildElement()
    assert items.name == 'items'
    assert items['node'] == "http://jabber.org/protocol/nick"
    result = make_result_iq(stream, event.stanza)
    result['type'] = 'error'
    error = result.addElement('error')
    error['type'] = 'auth'
    error.addElement('forbidden', 'urn:ietf:params:xml:ns:xmpp-stanzas')
    stream.send(result)

    event = q.expect('stream-iq', to='*****@*****.**', query_ns='vcard-temp',
        query_name='vCard')
    acknowledge_iq(stream, event.stanza)

    q.expect('dbus-return', method='RequestAliases',
        value=([u'*****@*****.**'],))

    # A second request should be satisfied from the cache.
    assert conn.Aliasing.RequestAliases([handle]) == ['*****@*****.**']
Ejemplo n.º 9
0
    def get_data(self, size=0):
        # wait for IBB stanza. Gabble always uses IQ

        binary = b''
        received = False
        while not received:
            ibb_event = self.q.expect('stream-iq', query_ns=ns.IBB)

            data_nodes = xpath.queryForNodes('/iq/data[@xmlns="%s"]' % ns.IBB,
                                             ibb_event.stanza)
            assert data_nodes is not None
            assert len(data_nodes) == 1
            ibb_data = data_nodes[0]
            binary += base64.b64decode(str(ibb_data))

            assert ibb_data['sid'] == self.stream_id

            # ack the IQ
            result = make_result_iq(self.stream, ibb_event.stanza)
            result.send()

            if len(binary) >= size or size == 0:
                received = True

        return binary
Ejemplo n.º 10
0
def test_39464(q, bus, conn, stream):
    """
    Regression test for an issue where a form with no type='' attribute on the
    <x/> node would crash Gabble.
    """
    client = 'fake:qutim'
    hash = 'blahblah'
    contact = '[email protected]/foo'
    caps = {
        'node': client,
        'ver': hash,
        'hash': 'sha-1',
        }
    presence = make_presence(contact, status='hello', caps=caps)
    stream.send(presence)

    # Gabble looks up our capabilities
    event = q.expect('stream-iq', to=contact, query_ns=ns.DISCO_INFO)

    # Send a reply with a form without a type=''
    result = make_result_iq(stream, event.stanza, add_query_node=False)
    result.addChild(
        elem(ns.DISCO_INFO, 'query', node='%s#%s' % (client, hash))(
          # NB. no type='' attribute
          elem(ns.X_DATA, 'x')
        )
      )
    stream.send(result)
    # We don't really care what Gabble does, as long as it doesn't crash.
    sync_stream(q, stream)
Ejemplo n.º 11
0
def make_caps_disco_reply(stream, req, features, dataforms={}):
    iq = make_result_iq(stream, req)
    query = iq.firstChildElement()

    for f in features:
        el = domish.Element((None, 'feature'))
        el['var'] = f
        query.addChild(el)

    for type, fields in dataforms.iteritems():
        x = query.addElement((ns.X_DATA, 'x'))
        x['type'] = 'result'

        field = x.addElement('field')
        field['var'] = 'FORM_TYPE'
        field['type'] = 'hidden'
        field.addElement('value', content=type)

        for var, values in fields.iteritems():
            field = x.addElement('field')
            field['var'] = var

            for value in values:
                field.addElement('value', content=value)

    return iq
Ejemplo n.º 12
0
def test(q, bus, conn, stream):
    event = q.expect('stream-iq',
                     to=None,
                     query_ns='vcard-temp',
                     query_name='vCard')

    acknowledge_iq(stream, event.stanza)
    # Force Gabble to process the vCard before calling any methods.
    sync_stream(q, stream)

    handle = conn.Properties.Get(cs.CONN, "SelfHandle")
    call_async(q, conn.Avatars, 'SetAvatar', 'william shatner',
               'image/x-actor-name')

    event = q.expect('stream-iq',
                     iq_type='get',
                     to=None,
                     query_ns='vcard-temp',
                     query_name='vCard')
    reply = make_result_iq(stream, event.stanza)
    reply['type'] = 'error'
    reply.addChild(
        elem('error')(elem(ns.STANZA, 'forbidden')(),
                      elem(ns.STANZA, 'text')(u'zomg whoops')))
    stream.send(reply)

    event = q.expect('dbus-error', method='SetAvatar', name=cs.NOT_AVAILABLE)
def proxies_telepathy_im(q, bus, conn, stream):
    # Test if proxies.telepathy.im is properly used when no fallback proxies
    # are passed to Gabble
    connect_and_announce_alice(q, bus, conn, stream)

    send_file_to_alice(q, conn)

    # Gabble asks for a proxy list to our server
    return_event, e, = q.expect_many(
        EventPattern('dbus-return', method='CreateChannel'),
        EventPattern('stream-iq', to='proxies.telepathy.im', iq_type='get', query_ns=ns.DISCO_ITEMS))

    # reply with 2 servers
    reply = make_result_iq(stream, e.stanza)
    query = xpath.queryForNodes('/iq/query', reply)[0]
    item = query.addElement((None, 'item'))
    item['jid'] = 'proxy1.localhost'
    item = query.addElement((None, 'item'))
    item['jid'] = 'proxy2.localhost'
    stream.send(reply)

    # These servers are queried
    e1, e2 = q.expect_many(
        EventPattern('stream-iq', to='proxy1.localhost', iq_type='get', query_ns=ns.BYTESTREAMS),
        EventPattern('stream-iq', to='proxy2.localhost', iq_type='get', query_ns=ns.BYTESTREAMS))
def make_caps_disco_reply(stream, req, identities, features, dataforms={}):
    iq = make_result_iq(stream, req)
    query = iq.firstChildElement()

    for identity in identities:
        category, type_, lang, name = identity.split('/')
        el = query.addElement('identity')
        el['category'] = category
        el['type'] = type_
        el['name'] = name
        el['xml:lang'] = lang

    for f in features:
        el = domish.Element((None, 'feature'))
        el['var'] = f
        query.addChild(el)

    for type, fields in dataforms.iteritems():
        x = query.addElement((ns.X_DATA, 'x'))
        x['type'] = 'result'

        field = x.addElement('field')
        field['var'] = 'FORM_TYPE'
        field['type'] = 'hidden'
        field.addElement('value', content=type)

        for var, values in fields.iteritems():
            field = x.addElement('field')
            field['var'] = var

            for value in values:
                field.addElement('value', content=value)

    return iq
Ejemplo n.º 15
0
def send_reply_to_activity_view_request(stream, stanza, activities):
    reply = make_result_iq(stream, stanza)
    reply['from'] = 'gadget.localhost'
    reply['to'] = 'test@localhost'
    view = xpath.queryForNodes('/iq/view', reply)[0]
    for id, room, props, buddies in activities:
        activity = view.addElement((None, "activity"))
        activity['room'] = room
        activity['id'] = id
        if props:
            properties = activity.addElement((ns.OLPC_ACTIVITY_PROPS,
                "properties"))
            for child in properties_to_xml(props):
                properties.addChild(child)

        for jid, props in buddies:
            buddy = activity.addElement((None, 'buddy'))
            buddy['jid'] = jid
            if props:
                properties = buddy.addElement((ns.OLPC_BUDDY_PROPS,
                    "properties"))
                for child in properties_to_xml(props):
                    properties.addChild(child)

    stream.send(reply)
Ejemplo n.º 16
0
def test(q, bus, conn, stream):
    event = q.expect('stream-iq', to=None, query_ns='vcard-temp',
            query_name='vCard')

    acknowledge_iq(stream, event.stanza)

    handle = conn.get_contact_handle_sync('*****@*****.**')
    call_async(q, conn.Aliasing, 'RequestAliases', [handle])

    # Nack PEP query.
    event = q.expect('stream-iq', to='*****@*****.**', iq_type='get',
        query_ns='http://jabber.org/protocol/pubsub', query_name='pubsub')
    items = event.query.firstChildElement()
    assert items.name == 'items'
    assert items['node'] == "http://jabber.org/protocol/nick"
    result = make_result_iq(stream, event.stanza)
    result['type'] = 'error'
    error = result.addElement('error')
    error['type'] = 'auth'
    error.addElement('forbidden', 'urn:ietf:params:xml:ns:xmpp-stanzas')
    stream.send(result)

    event = q.expect('stream-iq', to='*****@*****.**', query_ns='vcard-temp',
        query_name='vCard')
    acknowledge_iq(stream, event.stanza)

    q.expect('dbus-return', method='RequestAliases',
        value=([u'*****@*****.**'],))

    # A second request should be satisfied from the cache.
    assert conn.Aliasing.RequestAliases([handle]) == ['*****@*****.**']
Ejemplo n.º 17
0
def test(q, bus, conn, stream):
    event = q.expect('stream-iq', to=None, query_ns=ns.ROSTER,
            query_name='query')

    result = make_result_iq(stream, event.stanza)
    item = result.addElement('item')
    item['jid'] = '*****@*****.**'
    item['subscription'] = 'both'

    item = result.addElement('item')
    item['jid'] = '*****@*****.**'
    item['subscription'] = 'both'

    item = result.addElement('item')
    item['jid'] = '*****@*****.**'
    item['subscription'] = 'both'
    stream.send(result)

    stream.send(make_presence('*****@*****.**', 'SHA1SUM-FOR-AMY'))
    stream.send(make_presence('*****@*****.**', 'SHA1SUM-FOR-BOB'))
    stream.send(make_presence('*****@*****.**', None))

    q.expect('dbus-signal', signal='AvatarUpdated')
    handles = conn.RequestHandles(1, [
        '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**' ])

    tokens = unwrap(conn.Avatars.GetAvatarTokens(handles))
    assert tokens == ['SHA1SUM-FOR-AMY', 'SHA1SUM-FOR-BOB', '', '']

    tokens = unwrap(conn.Avatars.GetKnownAvatarTokens(handles))
    tokens = sorted(tokens.items())
    assert tokens == [(2, 'SHA1SUM-FOR-AMY'), (3, 'SHA1SUM-FOR-BOB'), (4, u'')]
Ejemplo n.º 18
0
def test(q, bus, conn, stream, is_google):
    iq_event = q.expect('stream-iq', to=None, query_ns='vcard-temp',
            query_name='vCard')

    result = make_result_iq(stream, iq_event.stanza)

    # Testing reveals that Google's vCard server does not actually support
    # NICKNAME (or indeed any fields beside FN, N and PHOTO): if you set a
    # vCard including it, it accepts the request but strips out the unsupported
    # fields. So if the server looks like Google, it's a redundant set
    # operation on FN that we want to avoid.
    if is_google:
        vcard = result.firstChildElement()
        vcard.addElement('FN', content='oh hello there')
    else:
        vcard = result.firstChildElement()
        vcard.addElement('NICKNAME', content='oh hello there')

    stream.send(result)

    q.forbid_events([
        EventPattern('stream-iq', iq_type='set', query_ns='vcard-temp',
            query_name='vCard')
        ])
    sync_stream(q, stream)
    sync_dbus(bus, q, conn)
Ejemplo n.º 19
0
def handle_disco_info_iq(stream, stanza):
    iq = make_result_iq(stream, stanza)

    query = iq.firstChildElement()

    # Title
    identity = query.addElement('identity')
    identity['category'] = 'conference'
    identity['type'] = 'text'
    identity['name'] = ROOM_NAME

    for var in [ns.MUC,
                'muc_anonymous', # Anonymous
                'muc_open', # ¬InviteOnly
                # Limit lives in the data form
                'muc_moderated', # Moderated
                # Title is above
                # Description is below
                'muc_temporary', # ¬Persistent
                'muc_hidden', # Private
                'muc_unsecure', # ¬PasswordProtected
                # Password is in the owner form.
               ]:
        f = query.addElement('feature')
        f['var'] = var

    # Description
    x = query.addElement((ns.X_DATA, 'x'))
    x['type'] = 'result'
    add_field(x, 'hidden', 'FORM_TYPE', ns.MUC_ROOMINFO)
    add_field(x, None, 'muc#roominfo_description', ROOM_DESCRIPTION)

    stream.send(iq)
Ejemplo n.º 20
0
def test(q, bus, conn, stream):
    event = q.expect('stream-iq', to=None, query_ns=ns.ROSTER,
            query_name='query')

    result = make_result_iq(stream, event.stanza)
    item = result.addElement('item')
    item['jid'] = '*****@*****.**'
    item['subscription'] = 'both'

    item = result.addElement('item')
    item['jid'] = '*****@*****.**'
    item['subscription'] = 'both'

    item = result.addElement('item')
    item['jid'] = '*****@*****.**'
    item['subscription'] = 'both'
    stream.send(result)

    stream.send(make_presence('*****@*****.**', 'SHA1SUM-FOR-AMY'))
    stream.send(make_presence('*****@*****.**', 'SHA1SUM-FOR-BOB'))
    stream.send(make_presence('*****@*****.**', None))

    q.expect('dbus-signal', signal='AvatarUpdated')
    handles = conn.get_contact_handles_sync([
        '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**' ])

    h2asv = conn.Contacts.GetContactAttributes(handles, [cs.CONN_IFACE_AVATARS], False)
    assertEquals('SHA1SUM-FOR-AMY', h2asv[handles[0]][cs.ATTR_AVATAR_TOKEN])
    assertEquals('SHA1SUM-FOR-BOB', h2asv[handles[1]][cs.ATTR_AVATAR_TOKEN])
    assertEquals('', h2asv[handles[2]][cs.ATTR_AVATAR_TOKEN])
    assertEquals(None, h2asv[handles[3]].get(cs.ATTR_AVATAR_TOKEN))

    tokens = unwrap(conn.Avatars.GetKnownAvatarTokens(handles))
    tokens = sorted(tokens.items())
    assert tokens == [(2, 'SHA1SUM-FOR-AMY'), (3, 'SHA1SUM-FOR-BOB'), (4, u'')]
Ejemplo n.º 21
0
def announce_socks5_proxy(q, stream, disco_stanza):
    reply = make_result_iq(stream, disco_stanza)
    query = xpath.queryForNodes('/iq/query', reply)[0]
    item = query.addElement((None, 'item'))
    item['jid'] = 'proxy.localhost'
    stream.send(reply)

    # wait for proxy disco#info query
    event = q.expect('stream-iq', to='proxy.localhost', query_ns=ns.DISCO_INFO,
        iq_type='get')

    reply = elem_iq(stream, 'result', from_='proxy.localhost', id=event.stanza['id'])(
        elem(ns.DISCO_INFO, 'query')(
            elem('identity', category='proxy', type='bytestreams', name='SOCKS5 Bytestreams')(),
            elem('feature', var=ns.BYTESTREAMS)()))
    stream.send(reply)

    # Gabble asks for SOCKS5 info
    event = q.expect('stream-iq', to='proxy.localhost', query_ns=ns.BYTESTREAMS,
        iq_type='get')

    port = listen_socks5(q)
    reply = elem_iq(stream, 'result', id=event.stanza['id'], from_='proxy.localhost')(
        elem(ns.BYTESTREAMS, 'query')(
            elem('streamhost', jid='proxy.localhost', host='127.0.0.1', port=str(port))()))
    stream.send(reply)
Ejemplo n.º 22
0
def test_get_avatar(q, bus, conn, stream, contact, handle, in_cache=False):
    conn.Avatars.RequestAvatars([handle])

    if in_cache:
        q.forbid_events([avatar_request_event])
    else:
        iq_event = q.expect('stream-iq',
                            to=contact,
                            query_ns='vcard-temp',
                            query_name='vCard')
        iq = make_result_iq(stream, iq_event.stanza)
        vcard = iq.firstChildElement()
        photo = vcard.addElement('PHOTO')
        photo.addElement('TYPE', content='image/png')
        photo.addElement('BINVAL', content=base64.b64encode(b'hello').decode())
        stream.send(iq)

    event = q.expect('dbus-signal', signal='AvatarRetrieved')
    assertEquals(handle, event.args[0])
    assertEquals(hashlib.sha1(b'hello').hexdigest(), event.args[1])
    assertEquals(b'hello', event.args[2])
    assertEquals('image/png', event.args[3])

    if in_cache:
        sync_stream(q, stream)
        q.unforbid_events([avatar_request_event])
Ejemplo n.º 23
0
    def announce_contact(self, name=CONTACT_NAME, metadata=True):
        self.contact_name = name
        self.contact_full_jid = '%s/Telepathy' % name
        self.handle = self.conn.get_contact_handle_sync(name)

        presence = domish.Element(('jabber:client', 'presence'))
        presence['from'] = self.contact_full_jid
        presence['to'] = 'test@localhost/Resource'
        c = presence.addElement('c')
        c['xmlns'] = 'http://jabber.org/protocol/caps'
        c['node'] = 'http://example.com/ISupportFT'
        c['ver'] = '1.0'
        self.stream.send(presence)

        disco_event, presence_event = self.q.expect_many(
            EventPattern('stream-iq', iq_type='get',
                query_ns='http://jabber.org/protocol/disco#info', to=self.contact_full_jid),
            EventPattern('dbus-signal', signal='PresencesChanged', args=[
                {self.handle: (cs.PRESENCE_AVAILABLE, u'available', u'')}]))

        assert disco_event.query['node'] == \
            'http://example.com/ISupportFT#1.0'
        result = make_result_iq(self.stream, disco_event.stanza)
        query = result.firstChildElement()
        feature = query.addElement('feature')
        feature['var'] = ns.FILE_TRANSFER
        if metadata:
            feature = query.addElement('feature')
            feature['var'] = ns.TP_FT_METADATA
        self.stream.send(result)

        sync_stream(self.q, self.stream)
Ejemplo n.º 24
0
def handle_jingle_info_query(q, stream, stun_server, stun_port):
    # See: http://code.google.com/apis/talk/jep_extensions/jingleinfo.html
    event = q.expect('stream-iq', query_ns=ns.GOOGLE_JINGLE_INFO,
        to=stream.authenticator.bare_jid)
    jingleinfo = make_result_iq(stream, event.stanza)
    add_jingle_info(jingleinfo, stun_server, stun_port)
    stream.send(jingleinfo)
Ejemplo n.º 25
0
def handle_disco_info_iq(stream, stanza):
    iq = make_result_iq(stream, stanza)

    query = iq.firstChildElement()

    # Title
    identity = query.addElement('identity')
    identity['category'] = 'conference'
    identity['type'] = 'text'
    identity['name'] = ROOM_NAME

    for var in [
            ns.MUC,
            'muc_anonymous',  # Anonymous
            'muc_open',  # ¬InviteOnly
            # Limit lives in the data form
            'muc_moderated',  # Moderated
            # Title is above
            # Description is below
            'muc_temporary',  # ¬Persistent
            'muc_hidden',  # Private
            'muc_unsecure',  # ¬PasswordProtected
            # Password is in the owner form.
    ]:
        f = query.addElement('feature')
        f['var'] = var

    # Description
    x = query.addElement((ns.X_DATA, 'x'))
    x['type'] = 'result'
    add_field(x, 'hidden', 'FORM_TYPE', ns.MUC_ROOMINFO)
    add_field(x, None, 'muc#roominfo_description', ROOM_DESCRIPTION)

    stream.send(iq)
def test(q, bus, conn, stream):
    """
    Check that when we receive a roster update we emit a single AliasesChanged
    for all the contacts.
    """

    conn.Connect()

    # Gabble asks the server for the initial roster
    event = q.expect('stream-iq', iq_type='get', query_ns=ns.ROSTER)
    result = make_result_iq(stream, event.stanza)

    # We reply with a roster with two contacts
    bob_jid = '*****@*****.**'
    bob_alias = 'Bob Smith'
    add_contact(result, bob_jid, bob_alias)

    alice_jid = '*****@*****.**'
    alice_alias = 'Alice'
    add_contact(result, alice_jid, alice_alias)

    stream.send(result)

    # Check we get a single AliasesChanged for both contacts
    event = q.expect('dbus-signal', signal='AliasesChanged')
    added = event.args[0]

    bob_handle, alice_handle = conn.get_contact_handles_sync(
            [bob_jid, alice_jid])

    assertLength(2, added)
    assertContains((bob_handle, bob_alias), added)
    assertContains((alice_handle, alice_alias), added)
Ejemplo n.º 27
0
    def get_data(self, size=0):
        # wait for IBB stanza. Gabble always uses IQ

        binary = ''
        received = False
        while not received:
            ibb_event = self.q.expect('stream-iq', query_ns=ns.IBB)

            data_nodes = xpath.queryForNodes('/iq/data[@xmlns="%s"]' % ns.IBB,
                ibb_event.stanza)
            assert data_nodes is not None
            assert len(data_nodes) == 1
            ibb_data = data_nodes[0]
            binary += base64.b64decode(str(ibb_data))

            assert ibb_data['sid'] == self.stream_id

            # ack the IQ
            result = make_result_iq(self.stream, ibb_event.stanza)
            result.send()

            if len(binary) >= size or size == 0:
                received = True

        return binary
Ejemplo n.º 28
0
def send_results_extended(stream, iq, results, fields):
    result = make_result_iq(stream, iq)
    query = result.firstChildElement()

    x = query.addElement((ns.X_DATA, 'x'))
    x['type'] = 'result'

    x.addElement('title', content='Search result')

    # add reported fields
    reported = x.addElement('reported')
    for var, type, label, options in fields:
        field = reported.addElement('field')
        field['var'] = var
        field['label'] = label

    # add results
    for r in results:
        item = x.addElement('item')
        for var, value in r.items():
            field = item.addElement('field')
            field['var'] = var
            field.addElement('value', content=value)

    stream.send(result)
Ejemplo n.º 29
0
def test(q, bus, conn, stream):
    conn.Connect()

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

    # Need to call this asynchronously as it involves Gabble sending us a
    # query.
    jids = ['*****@*****.**', '*****@*****.**']
    call_async(q, conn, 'RequestHandles', 2, jids)

    # Gabble is stupid and discos the alleged conf server twice.
    for i in [0,1]:
        event = q.expect('stream-iq', to='conf.localhost',
            query_ns='http://jabber.org/protocol/disco#info')
        result = make_result_iq(stream, event.stanza)
        feature = result.firstChildElement().addElement('feature')
        feature['var'] = 'http://jabber.org/protocol/muc'
        stream.send(result)

    event = q.expect('dbus-return', method='RequestHandles')
    room_handles = event.value[0]

    test_create_ensure(q, conn, bus, stream, jids[0], room_handles[0])
    test_ensure_ensure(q, conn, bus, stream, jids[1], room_handles[1])
def _local_content_add(jp, q, bus, conn, stream, initiate_call_func):
    jt, chan = initiate_call_func(jp, q, bus, conn, stream)

    remote_handle = conn.RequestHandles(cs.HT_CONTACT, [jt.peer])[0]

    chan.RequestStreams(remote_handle, [cs.MEDIA_STREAM_TYPE_VIDEO])

    nsh = q.expect('dbus-signal', signal='NewStreamHandler')
    stream_handler_path, stream_id, media_type, direction = nsh.args
    video_handler = make_channel_proxy(conn, stream_handler_path,
                                       'Media.StreamHandler')

    video_handler.NewNativeCandidate("fake", jt.get_remote_transports_dbus())
    video_handler.Ready(jt.get_audio_codecs_dbus())
    video_handler.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED)

    e = q.expect('stream-iq', predicate=jp.action_predicate('content-add'))
    c = e.query.firstChildElement()
    stream.send(make_result_iq(stream, e.stanza))

    node = jp.SetIq(jt.peer, jt.jid, [
            jp.Jingle(jt.sid, jt.peer, 'content-reject', [
                    ('reason', None, {}, [
                            ('failed-application', None, {}, [])]),
                    jp.Content(c['name'], c['creator'], c['senders']) ]) ])
    stream.send(jp.xml(node))

    q.expect('dbus-signal', signal='StreamError',
             args=[stream_id,
                   cs.MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED,
                   ""]),
    def announce_contact(self, name=CONTACT_NAME):
        self.contact_name = name
        self.contact_full_jid = '%s/Telepathy' % name
        self.handle = self.conn.RequestHandles(cs.HT_CONTACT, [name])[0]

        presence = domish.Element(('jabber:client', 'presence'))
        presence['from'] = self.contact_full_jid
        presence['to'] = 'test@localhost/Resource'
        c = presence.addElement('c')
        c['xmlns'] = 'http://jabber.org/protocol/caps'
        c['node'] = 'http://example.com/ISupportFT'
        c['ver'] = '1.0'
        self.stream.send(presence)

        disco_event, presence_event = self.q.expect_many(
            EventPattern('stream-iq', iq_type='get',
                query_ns='http://jabber.org/protocol/disco#info', to=self.contact_full_jid),
            EventPattern('dbus-signal', signal='PresencesChanged', args=[
                {self.handle: (cs.PRESENCE_AVAILABLE, u'available', u'')}]))

        assert disco_event.query['node'] == \
            'http://example.com/ISupportFT#1.0'
        result = make_result_iq(self.stream, disco_event.stanza)
        query = result.firstChildElement()
        feature = query.addElement('feature')
        feature['var'] = ns.FILE_TRANSFER
        self.stream.send(result)

        sync_stream(self.q, self.stream)
def _test(jp, q, bus, conn, stream,
          jingle_reason, group_change_reason, stream_error):
    remote_jid = '[email protected]/Foo'
    jt = JingleTest2(jp, conn, q, stream, 'test@localhost', remote_jid)

    jt.prepare()

    self_handle = conn.GetSelfHandle()
    remote_handle = conn.RequestHandles(cs.HT_CONTACT, [remote_jid])[0]

    path = conn.RequestChannel(cs.CHANNEL_TYPE_STREAMED_MEDIA,
        cs.HT_CONTACT, remote_handle, True)

    signalling_iface = make_channel_proxy(conn, path, 'Channel.Interface.MediaSignalling')
    media_iface = make_channel_proxy(conn, path, 'Channel.Type.StreamedMedia')

    media_iface.RequestStreams(remote_handle, [cs.MEDIA_STREAM_TYPE_AUDIO])

    # S-E gets notified about new session handler, and calls Ready on it
    e = q.expect('dbus-signal', signal='NewSessionHandler')
    assert e.args[1] == 'rtp'

    session_handler = make_channel_proxy(conn, e.args[0], 'Media.SessionHandler')
    session_handler.Ready()


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

    stream_handler = make_channel_proxy(conn, e.args[0], 'Media.StreamHandler')

    stream_handler.NewNativeCandidate("fake", jt.get_remote_transports_dbus())
    stream_handler.Ready(jt.get_audio_codecs_dbus())
    stream_handler.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED)

    e = q.expect('stream-iq', predicate=jp.action_predicate('session-initiate'))
    stream.send(make_result_iq(stream, e.stanza))

    text = u"begone!"

    jt.parse_session_initiate(e.query)
    jt.terminate(reason=jingle_reason, text=text)

    mc = q.expect('dbus-signal', signal='MembersChanged')
    message, added, removed, lp, rp, actor, reason = mc.args
    assert added == [], added
    assert set(removed) == set([self_handle, remote_handle]), \
        (removed, self_handle, remote_handle)
    assert lp == [], lp
    assert rp == [], rp
    assert actor == remote_handle, (actor, remote_handle)
    if jp.is_modern_jingle():
        assertEquals(text, message)
        assertEquals(group_change_reason, reason)

    if jp.is_modern_jingle() and stream_error:
        se = q.expect('dbus-signal', signal='StreamError')
        assertEquals(stream_error, se.args[1])

    q.expect('dbus-signal', signal='Close') #XXX - match against the path
def test(q, bus, conn, stream):
    conn.Connect()
    _, event, event2 = q.expect_many(
        EventPattern('dbus-signal', signal='StatusChanged',
            args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]),
        EventPattern('stream-iq', to=None, query_ns='vcard-temp',
            query_name='vCard'),
        EventPattern('stream-iq', query_ns=ns.ROSTER))

    acknowledge_iq(stream, event.stanza)
    acknowledge_iq(stream, event2.stanza)

    while True:
        event = q.expect('dbus-signal', signal='NewChannel')
        path, type, handle_type, handle, suppress_handler = event.args

        if type != cs.CHANNEL_TYPE_CONTACT_LIST:
            continue

        chan_name = conn.InspectHandles(handle_type, [handle])[0]

        if chan_name == 'subscribe':
            break

    # request subscription
    chan = bus.get_object(conn.bus_name, path)
    group_iface = dbus.Interface(chan, cs.CHANNEL_IFACE_GROUP)
    assert group_iface.GetMembers() == []
    handle = conn.RequestHandles(1, ['*****@*****.**'])[0]
    group_iface.AddMembers([handle], '')

    event = q.expect('stream-iq', iq_type='set', query_ns=ns.ROSTER)
    item = event.query.firstChildElement()

    acknowledge_iq(stream, event.stanza)

    call_async(q, conn.Aliasing, 'RequestAliases', [handle])

    event = q.expect('stream-iq', iq_type='get',
        query_ns='http://jabber.org/protocol/pubsub',
        to='*****@*****.**')

    result = make_result_iq(stream, event.stanza)
    pubsub = result.firstChildElement()
    items = pubsub.addElement('items')
    items['node'] = 'http://jabber.org/protocol/nick'
    item = items.addElement('item')
    item.addElement('nick', 'http://jabber.org/protocol/nick',
        content='Bobby')
    stream.send(result)

    event, _ = q.expect_many(
        EventPattern('stream-iq', iq_type='set', query_ns=ns.ROSTER),
        EventPattern('dbus-return', method='RequestAliases',
        value=(['Bobby'],)))

    item = event.query.firstChildElement()
    assert item['jid'] == '*****@*****.**'
    assert item['name'] == 'Bobby'
Ejemplo n.º 34
0
def test(jp, q, bus, conn, stream):
    if not jp.can_do_video_only():
        return

    remote_jid = '[email protected]/Foo'
    jt = JingleTest2(jp, conn, q, stream, 'test@localhost', remote_jid)
    jt.prepare()

    self_handle = conn.GetSelfHandle()
    handle = conn.RequestHandles(cs.HT_CONTACT, [remote_jid])[0]

    chan_path = conn.RequestChannel(cs.CHANNEL_TYPE_STREAMED_MEDIA,
            cs.HT_CONTACT, handle, True)
    chan = wrap_channel(bus.get_object(conn.bus_name, chan_path),
            'StreamedMedia', ['MediaSignalling', 'Group', 'CallState', 'DTMF'])
    chan_props = chan.Properties.GetAll(cs.CHANNEL)
    assert cs.CHANNEL_IFACE_DTMF in chan_props['Interfaces'], \
        chan_props['Interfaces']

    chan.StreamedMedia.RequestStreams(handle, [cs.MEDIA_STREAM_TYPE_VIDEO])

    # S-E gets notified about new session handler, and calls Ready on it
    e = q.expect('dbus-signal', signal='NewSessionHandler')
    assert e.args[1] == 'rtp'

    session_handler = make_channel_proxy(conn, e.args[0], 'Media.SessionHandler')
    session_handler.Ready()

    e = q.expect('dbus-signal', signal='NewStreamHandler')
    video_path = e.args[0]
    stream_handler = make_channel_proxy(conn, video_path, 'Media.StreamHandler')

    stream_handler.NewNativeCandidate("fake", jt.get_remote_transports_dbus())
    stream_handler.Ready(jt.get_video_codecs_dbus())
    stream_handler.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED)

    e = q.expect('stream-iq', predicate=jp.action_predicate('session-initiate'))
    stream.send(make_result_iq(stream, e.stanza))

    jt.parse_session_initiate(e.query)

    jt.accept()

    # Gabble tells s-e to start sending
    q.expect('dbus-signal', signal='SetStreamSending', args=[True],
            path=video_path)

    # We don't actually have an audio stream, so this is a non-starter.
    call_async(q, chan.DTMF, 'StartTone', 666, 3)
    q.expect('dbus-error', method='StartTone', name=cs.NOT_AVAILABLE)
    call_async(q, chan.DTMF, 'MultipleTones', '**666##')
    q.expect('dbus-error', method='MultipleTones', name=cs.NOT_AVAILABLE)

    # We can still stop all the tones that are playing (a no-op).
    call_async(q, chan.DTMF, 'StopTone', 666)
    q.expect('dbus-return', method='StopTone')

    chan.Group.RemoveMembers([self_handle], 'closed')
    e = q.expect('dbus-signal', signal='Closed', path=chan_path)
def send_pep_nick_reply(stream, stanza, nickname):
    result = make_result_iq(stream, stanza)
    pubsub = result.firstChildElement()
    items = pubsub.addElement('items')
    items['node'] = ns.NICK
    item = items.addElement('item')
    item.addElement('nick', ns.NICK, content=nickname)
    stream.send(result)
def send_pep_nick_reply(stream, stanza, nickname):
    result = make_result_iq(stream, stanza)
    pubsub = result.firstChildElement()
    items = pubsub.addElement('items')
    items['node'] = ns.NICK
    item = items.addElement('item')
    item.addElement('nick', ns.NICK, content=nickname)
    stream.send(result)
def test(q, bus, conn, stream):
    conn.Connect()
    _, event = q.expect_many(
        EventPattern('dbus-signal', signal='StatusChanged',
            args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]),
        EventPattern('stream-iq', to=None, query_ns='vcard-temp',
            query_name='vCard'))

    acknowledge_iq(stream, event.stanza)

    handle = conn.RequestHandles(cs.HT_CONTACT, ['*****@*****.**'])[0]
    call_async(q, conn.Aliasing, 'RequestAliases', [handle])

    event = q.expect('stream-iq', to='*****@*****.**', iq_type='get',
        query_ns=ns.PUBSUB, query_name='pubsub')
    items = event.query.firstChildElement()
    assertEquals('items', items.name)
    assertEquals(ns.NICK, items['node'])
    result = make_result_iq(stream, event.stanza)
    pubsub = result.firstChildElement()
    items = pubsub.addElement('items')
    items['node'] = ns.NICK
    item = items.addElement('item')
    item.addElement('nick', ns.NICK, content='Bobby')
    stream.send(result)

    q.expect('dbus-signal', signal='AliasesChanged',
        args=[[(handle, u'Bobby')]])
    q.expect('dbus-return', method='RequestAliases',
        value=(['Bobby'],))

    # A second request should be satisfied from the cache.
    assertEquals(['Bobby'], conn.Aliasing.RequestAliases([handle]))

    # Bobby grows up, decides he hates his nickname.
    # This is a regression test for
    # <https://bugs.freedesktop.org/show_bug.cgi?id=21817>, where this would
    # crash Gabble.
    message = elem('message', from_='*****@*****.**')(
        elem((ns.PUBSUB + "#event"), 'event')(
            elem('items', node=ns.NICK)(
                elem('item')(
                    elem(ns.NICK, 'nick')
                )
            )
        )
    )
    stream.send(message.toXml())

    event = q.expect('dbus-signal', signal='AliasesChanged')
    aliases = event.args[0]
    assertLength(1, aliases)
    h, a = aliases[0]
    assertEquals(handle, h)
    # The contact explicitly cleared their PEP nick; Gabble should fall back to
    # their JID.
    assertEquals(a, '*****@*****.**')
Ejemplo n.º 38
0
def test(q, bus, conn, stream):
    event = q.expect('stream-iq', to=None, query_ns='vcard-temp',
            query_name='vCard')

    acknowledge_iq(stream, event.stanza)

    handle = conn.RequestHandles(1, ['*****@*****.**'])[0]
    call_async(q, conn.ContactInfo, 'RefreshContactInfo', [handle])

    event = q.expect('stream-iq', to='*****@*****.**', query_ns='vcard-temp',
        query_name='vCard')
    result = make_result_iq(stream, event.stanza)
    result.firstChildElement().addElement('FN', content='Bob')
    n = result.firstChildElement().addElement('N')
    n.addElement('GIVEN', content='Bob')
    result.firstChildElement().addElement('NICKNAME',
        content=r'bob,bob1\,,bob2,bob3\,bob4')
    label = result.firstChildElement().addElement('LABEL')
    label.addElement('LINE', content='42 West Wallaby Street')
    label.addElement('LINE', content="Bishop's Stortford\n")
    label.addElement('LINE', content='Huntingdon')
    org = result.firstChildElement().addElement('ORG')
    # ORG is a sequence of decreasingly large org.units, starting
    # with the organisation name itself (but here we've moved the org name
    # to the end, to make sure that works.)
    org.addElement('ORGUNIT', content='Dept. of Examples')
    org.addElement('ORGUNIT', content='Exemplary Team')
    org.addElement('ORGNAME', content='Collabora Ltd.')
    stream.send(result)

    q.expect('dbus-signal', signal='ContactInfoChanged',
             args=[handle, [(u'fn', [], [u'Bob']),
                            (u'n', [], [u'', u'Bob', u'', u'', u'']),
                            (u'nickname', [], [r'bob,bob1\,,bob2,bob3\,bob4']),
                            # LABEL comes out as a single blob of text
                            (u'label', [], ['42 West Wallaby Street\n'
                            "Bishop's Stortford\n"
                            'Huntingdon\n']),
                            # ORG is a sequence of decreasingly large org.units, starting
                            # with the organisation
                            (u'org', [], [u'Collabora Ltd.', u'Dept. of Examples',
                            u'Exemplary Team']),
                            ]])

    # ContactInfoChanged should not be signalled again
    forbidden = [EventPattern('dbus-signal', signal='ContactInfoChanged')]
    q.forbid_events(forbidden)

    # Refresh the contact info again; gabble should contact the server again
    call_async(q, conn.ContactInfo, 'RefreshContactInfo', [handle])

    event = q.expect('stream-iq', to='*****@*****.**', query_ns='vcard-temp',
        query_name='vCard')

    sync_dbus(bus, q, conn)

    q.unforbid_events(forbidden)
Ejemplo n.º 39
0
def test(q, bus, conn, stream):
    event = q.expect('stream-iq', to=None, query_ns='vcard-temp',
            query_name='vCard')

    acknowledge_iq(stream, event.stanza)
    # returning an empty vcard will cause ContactInfoChanged to fire
    q.expect('dbus-signal', signal='ContactInfoChanged')

    handle = conn.RequestHandles(1, ['*****@*****.**'])[0]
    call_async(q, conn.ContactInfo, 'RefreshContactInfo', [handle])

    event = q.expect('stream-iq', to='*****@*****.**', query_ns='vcard-temp',
        query_name='vCard')
    result = make_result_iq(stream, event.stanza)
    result.firstChildElement().addElement('FN', content='Bob')
    n = result.firstChildElement().addElement('N')
    n.addElement('GIVEN', content='Bob')
    result.firstChildElement().addElement('NICKNAME',
        content=r'bob,bob1\,,bob2,bob3\,bob4')
    label = result.firstChildElement().addElement('LABEL')
    label.addElement('LINE', content='42 West Wallaby Street')
    label.addElement('LINE', content="Bishop's Stortford\n")
    label.addElement('LINE', content='Huntingdon')
    org = result.firstChildElement().addElement('ORG')
    # ORG is a sequence of decreasingly large org.units, starting
    # with the organisation name itself (but here we've moved the org name
    # to the end, to make sure that works.)
    org.addElement('ORGUNIT', content='Dept. of Examples')
    org.addElement('ORGUNIT', content='Exemplary Team')
    org.addElement('ORGNAME', content='Collabora Ltd.')
    stream.send(result)

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

    contact_info = [(u'fn', [], [u'Bob']),
                    (u'n', [], [u'', u'Bob', u'', u'', u'']),
                    (u'nickname', [], [r'bob,bob1\,,bob2,bob3\,bob4']),
                    # LABEL comes out as a single blob of text
                    (u'label', [], ['42 West Wallaby Street\n'
                                    "Bishop's Stortford\n"
                                    'Huntingdon\n']),
                    # ORG is a sequence of decreasingly large org.units, starting
                    # with the organisation
                    (u'org', [], [u'Collabora Ltd.', u'Dept. of Examples',
                                  u'Exemplary Team']),
                   ]
    # The request should be satisfied from the cache.
    assertEquals(
        {handle: contact_info}, conn.ContactInfo.GetContactInfo([handle]))

    # check the ContactAttribute
    assertEquals(
        {handle: {cs.CONN_IFACE_CONTACT_INFO + '/info': contact_info,
                  'org.freedesktop.Telepathy.Connection/contact-id': '*****@*****.**'}},
        conn.Contacts.GetContactAttributes([handle],
                                           [cs.CONN_IFACE_CONTACT_INFO], False))
Ejemplo n.º 40
0
def test(q, bus, conn, stream):
    jid = '[email protected]/hi'
    caps = { 'node': 'oh:hi',
             'ver': "dere",
           }
    h = caps_helper.send_presence(q, conn, stream, jid, caps, initial=False)
    request = caps_helper.expect_disco(q, jid, caps['node'], caps)
    result = make_result_iq(stream, request, add_query_node=False)
    stream.send(result)
    sync_stream(q, stream)
Ejemplo n.º 41
0
def _wait_for_server_query(q, stream, server):
    # Gabble asks the server what search fields it supports
    iq_event = q.expect('stream-iq', to=server, query_ns=ns.SEARCH)
    iq = iq_event.stanza

    result = make_result_iq(stream, iq)
    query = result.firstChildElement()
    query.addElement("instructions", content="cybar?")

    return result, query
Ejemplo n.º 42
0
def _wait_for_server_query(q, stream, server):
    # Gabble asks the server what search fields it supports
    iq_event = q.expect('stream-iq', to=server, query_ns=ns.SEARCH)
    iq = iq_event.stanza

    result = make_result_iq(stream, iq)
    query = result.firstChildElement()
    query.addElement("instructions", content="cybar?")

    return result, query
Ejemplo n.º 43
0
def receive_caps(q,
                 conn,
                 stream,
                 contact,
                 contact_handle,
                 features,
                 expected_caps,
                 expect_disco=True,
                 expect_ccc=True):
    presence = make_presence(contact, status='hello')
    c = presence.addElement((ns.CAPS, 'c'))
    c['node'] = client
    c['ver'] = compute_caps_hash([], features if features is not None else [],
                                 {})
    c['hash'] = 'sha-1'
    stream.send(presence)

    if expect_disco:
        # Gabble looks up our capabilities
        event = q.expect('stream-iq', to=contact, query_ns=ns.DISCO_INFO)
        query_node = xpath.queryForNodes('/iq/query', event.stanza)[0]
        assert query_node.attributes['node'] == \
            client + '#' + c['ver']

        # send good reply
        result = make_result_iq(stream, event.stanza)
        query = result.firstChildElement()
        query['node'] = client + '#' + c['ver']

        for f in features:
            feature = query.addElement('feature')
            feature['var'] = f

        stream.send(result)

    if expect_ccc:
        event = q.expect('dbus-signal', signal='ContactCapabilitiesChanged')
        announced_ccs, = event.args
        assertSameElements(expected_caps, announced_ccs)
    else:
        # Make sure Gabble's got the caps
        sync_stream(q, stream)

    caps = get_contacts_capabilities_sync(conn, [contact_handle])
    assertSameElements(expected_caps, caps)

    # test again, to check GetContactCapabilities does not have side effect
    caps = get_contacts_capabilities_sync(conn, [contact_handle])
    assertSameElements(expected_caps, caps)

    # check the Contacts interface give the same caps
    caps_via_contacts_iface = conn.Contacts.GetContactAttributes(
            [contact_handle], [cs.CONN_IFACE_CONTACT_CAPS], False) \
            [contact_handle][cs.ATTR_CONTACT_CAPABILITIES]
    assertSameElements(caps[contact_handle], caps_via_contacts_iface)
def test(q, bus, conn, stream):
    jid = '[email protected]/hi'
    caps = {
        'node': 'oh:hi',
        'ver': "dere",
    }
    h = caps_helper.send_presence(q, conn, stream, jid, caps, initial=False)
    request = caps_helper.expect_disco(q, jid, caps['node'], caps)
    result = make_result_iq(stream, request, add_query_node=False)
    stream.send(result)
    sync_stream(q, stream)
Ejemplo n.º 45
0
def send_results(stream, iq, results):
    result = make_result_iq(stream, iq)
    query = result.firstChildElement()
    for jid, first, last, nick in results:
        item = query.addElement('item')
        item['jid'] = jid
        item.addElement('first', content=first)
        item.addElement('last', content=last)
        item.addElement('nick', content=nick)
        item.addElement('email', content=jid)
    stream.send(result)
Ejemplo n.º 46
0
def returns_invalid_fields(q, stream, conn):
    iq = call_create(q, conn, 'broken.localhost')

    result = make_result_iq(stream, iq)
    query = result.firstChildElement()
    for f in ["first", "shoe-size", "nick", "star-sign"]:
        query.addElement(f)
    stream.send(result)

    event = q.expect('dbus-error', method='CreateChannel')
    assertDBusError(cs.NOT_AVAILABLE, event.error)
Ejemplo n.º 47
0
def test(q, bus, conn, stream):
    expect_and_handle_get_vcard(q, stream)

    # Ensure that Gabble's actually got the initial vCard reply; if it hasn't
    # processed it by the time we call SetAliases, the latter will wait for it
    # to reply and then set immediately.
    sync_stream(q, stream)

    handle = conn.Properties.Get(cs.CONN, "SelfHandle")

    call_async(q, conn.Aliasing, 'SetAliases', {handle: 'Some Guy'})

    # SetAliases requests vCard v1
    get_vcard_event = q.expect('stream-iq',
                               query_ns=ns.VCARD_TEMP,
                               query_name='vCard',
                               iq_type='get')

    iq = get_vcard_event.stanza
    vcard = iq.firstChildElement()
    assert vcard.name == 'vCard', vcard.toXml()

    call_async(q, conn.Avatars, 'SetAvatar', 'hello', 'image/png')

    # We don't expect Gabble to send a second vCard request, since there's one
    # outstanding. But we want to ensure that SetAvatar reaches Gabble before
    # the empty vCard does.
    sync_dbus(bus, q, conn)

    # Send back current empty vCard
    result = make_result_iq(stream, iq)
    # result already includes the <vCard/> from the query, which is all we need
    stream.send(result)

    def has_nickname_and_photo(vcard):
        nicknames = xpath.queryForNodes('/vCard/NICKNAME', vcard)
        assert nicknames is not None
        assert len(nicknames) == 1
        assert str(nicknames[0]) == 'Some Guy'

        photos = xpath.queryForNodes('/vCard/PHOTO', vcard)
        assert photos is not None and len(photos) == 1, repr(photos)
        types = xpath.queryForNodes('/PHOTO/TYPE', photos[0])
        binvals = xpath.queryForNodes('/PHOTO/BINVAL', photos[0])
        assert types is not None and len(types) == 1, repr(types)
        assert binvals is not None and len(binvals) == 1, repr(binvals)
        assert str(types[0]) == 'image/png'
        got = str(binvals[0]).strip()
        exp = base64.b64encode('hello')
        assertEquals(exp, got)

    # Now Gabble should set a new vCard with both of the above changes.
    expect_and_handle_set_vcard(q, stream, has_nickname_and_photo)
Ejemplo n.º 48
0
def outgoing_reply(q, bus, conn, stream):
    path, stanza = setup_outgoing_tests(q, bus, conn, stream)

    # reply with nothing
    reply = make_result_iq(stream, stanza)
    stream.send(reply)

    e = q.expect('dbus-signal', signal='Replied', path=path)
    args, xml = e.args
    assertEquals({}, args)
    assertEquals('<?xml version="1.0" encoding="UTF-8"?>\n' \
                 + '<message xmlns="urn:ytstenut:message"/>\n', xml)
Ejemplo n.º 49
0
def test(q, bus, conn, stream):
    event = q.expect('stream-iq', to=None, query_ns='vcard-temp',
            query_name='vCard')

    acknowledge_iq(stream, event.stanza)

    handle = conn.get_contact_handle_sync('*****@*****.**')
    call_async(q, conn.Aliasing, 'RequestAliases', [handle])

    event = q.expect('stream-iq', to='*****@*****.**', iq_type='get',
        query_ns=ns.PUBSUB, query_name='pubsub')
    items = event.query.firstChildElement()
    assertEquals('items', items.name)
    assertEquals(ns.NICK, items['node'])
    result = make_result_iq(stream, event.stanza)
    pubsub = result.firstChildElement()
    items = pubsub.addElement('items')
    items['node'] = ns.NICK
    item = items.addElement('item')
    item.addElement('nick', ns.NICK, content='Bobby')
    stream.send(result)

    q.expect('dbus-signal', signal='AliasesChanged',
        args=[[(handle, u'Bobby')]])
    q.expect('dbus-return', method='RequestAliases',
        value=(['Bobby'],))

    # A second request should be satisfied from the cache.
    assertEquals(['Bobby'], conn.Aliasing.RequestAliases([handle]))

    # Bobby grows up, decides he hates his nickname.
    # This is a regression test for
    # <https://bugs.freedesktop.org/show_bug.cgi?id=21817>, where this would
    # crash Gabble.
    message = elem('message', from_='*****@*****.**')(
        elem((ns.PUBSUB_EVENT), 'event')(
            elem('items', node=ns.NICK)(
                elem('item')(
                    elem(ns.NICK, 'nick')
                )
            )
        )
    )
    stream.send(message.toXml())

    event = q.expect('dbus-signal', signal='AliasesChanged')
    aliases = event.args[0]
    assertLength(1, aliases)
    h, a = aliases[0]
    assertEquals(handle, h)
    # The contact explicitly cleared their PEP nick; Gabble should fall back to
    # their JID.
    assertEquals(a, '*****@*****.**')
def test(q, bus, conn, stream):
    event = q.expect('stream-iq', to=None, query_ns='vcard-temp',
            query_name='vCard')

    acknowledge_iq(stream, event.stanza)
    # returning an empty vcard will cause ContactInfoChanged to fire
    q.expect('dbus-signal', signal='ContactInfoChanged')

    handle = conn.get_contact_handle_sync('*****@*****.**')
    call_async(q, conn.ContactInfo, 'RefreshContactInfo', [handle])

    event = q.expect('stream-iq', to='*****@*****.**', query_ns='vcard-temp',
        query_name='vCard')
    result = make_result_iq(stream, event.stanza)
    result.firstChildElement().addElement('FN', content='Bob')
    n = result.firstChildElement().addElement('N')
    n.addElement('GIVEN', content='Bob')
    result.firstChildElement().addElement('NICKNAME',
        content=r'bob,bob1\,,bob2,bob3\,bob4')
    label = result.firstChildElement().addElement('LABEL')
    label.addElement('LINE', content='42 West Wallaby Street')
    label.addElement('LINE', content="Bishop's Stortford\n")
    label.addElement('LINE', content='Huntingdon')
    org = result.firstChildElement().addElement('ORG')
    # ORG is a sequence of decreasingly large org.units, starting
    # with the organisation name itself (but here we've moved the org name
    # to the end, to make sure that works.)
    org.addElement('ORGUNIT', content='Dept. of Examples')
    org.addElement('ORGUNIT', content='Exemplary Team')
    org.addElement('ORGNAME', content='Collabora Ltd.')
    stream.send(result)

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

    contact_info = [(u'fn', [], [u'Bob']),
                    (u'n', [], [u'', u'Bob', u'', u'', u'']),
                    (u'nickname', [], [r'bob,bob1\,,bob2,bob3\,bob4']),
                    # LABEL comes out as a single blob of text
                    (u'label', [], ['42 West Wallaby Street\n'
                                    "Bishop's Stortford\n"
                                    'Huntingdon\n']),
                    # ORG is a sequence of decreasingly large org.units, starting
                    # with the organisation
                    (u'org', [], [u'Collabora Ltd.', u'Dept. of Examples',
                                  u'Exemplary Team']),
                   ]
    # The request should be satisfied from the cache.
    h2asv = conn.Contacts.GetContactAttributes([handle], [cs.CONN_IFACE_CONTACT_INFO], False)
    assertEquals(contact_info, h2asv[handle][cs.ATTR_CONTACT_INFO])
Ejemplo n.º 51
0
    def create_si_reply(self, iq, to=None):
        result = make_result_iq(self.stream, iq)
        result['from'] = iq['to']
        if to is None:
            result['to'] = self.initiator
        else:
            result['to'] = to
        res_si = result.firstChildElement()
        res_feature = res_si.addElement((ns.FEATURE_NEG, 'feature'))
        res_x = res_feature.addElement((ns.X_DATA, 'x'))
        res_x['type'] = 'submit'
        res_field = res_x.addElement((None, 'field'))
        res_field['var'] = 'stream-method'
        res_value = res_field.addElement((None, 'value'))
        res_value.addContent(self.get_ns())

        return result, res_si
Ejemplo n.º 52
0
    def create_si_reply(self, iq, to=None):
        result = make_result_iq(self.stream, iq)
        result['from'] = iq['to']
        if to is None:
            result['to'] = self.initiator
        else:
            result['to'] = to
        res_si = result.firstChildElement()
        si_multiple = res_si.addElement((ns.SI_MULTIPLE, 'si-multiple'))
        # add SOCKS5
        res_value = si_multiple.addElement((None, 'value'))
        res_value.addContent(self.socks5.get_ns())
        # add IBB
        res_value = si_multiple.addElement((None, 'value'))
        res_value.addContent(self.ibb.get_ns())

        return result, res_si
Ejemplo n.º 53
0
    def connect(self):
        vcard_event, roster_event, disco_event = self.q.expect_many(
            EventPattern('stream-iq', to=None, query_ns='vcard-temp',
                query_name='vCard'),
            EventPattern('stream-iq', query_ns=ns.ROSTER),
            EventPattern('stream-iq', to='localhost', query_ns=ns.DISCO_ITEMS))

        roster = make_result_iq(self.stream, roster_event.stanza)
        query = roster.firstChildElement()
        item = query.addElement('item')
        item['jid'] = self.CONTACT_FULL_JID
        item['subscription'] = 'both'
        self.stream.send(roster)

        announce_socks5_proxy(self.q, self.stream, disco_event.stanza)

        self.self_handle = self.conn.Properties.Get(cs.CONN, "SelfHandle")
        self.self_handle_name =  self.conn.inspect_contact_sync(self.self_handle)
Ejemplo n.º 54
0
def answer_to_current_act_pubsub_request(stream, request, id, room):
    # check request structure
    assert request['type'] == 'get'
    items = xpath.queryForNodes('/iq/pubsub[@xmlns="%s"]/items' % ns.PUBSUB,
                                request)[0]
    assert items['node'] == ns.OLPC_CURRENT_ACTIVITY

    reply = make_result_iq(stream, request)
    reply['from'] = request['to']
    pubsub = reply.firstChildElement()
    items = pubsub.addElement((None, 'items'))
    items['node'] = ns.OLPC_CURRENT_ACTIVITY
    item = items.addElement((None, 'item'))
    item['id'] = 'itemID'
    activity = item.addElement((ns.OLPC_CURRENT_ACTIVITY, 'activity'))
    activity['room'] = room
    activity['type'] = id
    reply.send()
Ejemplo n.º 55
0
def server_discovered(q, bus, conn, stream, server=None):
    iq_event, disco_event = q.expect_many(
        EventPattern('stream-iq',
                     to=None,
                     query_ns='vcard-temp',
                     query_name='vCard'),
        EventPattern('stream-iq', to='localhost', query_ns=ns.DISCO_ITEMS))

    acknowledge_iq(stream, iq_event.stanza)

    # no search server has been discovered yet. The CreateChannel operation
    # will be completed once the disco process is finished.
    call_create(q, conn, server=server)

    # reply to IQ query
    reply = make_result_iq(stream, disco_event.stanza)
    query = xpath.queryForNodes('/iq/query', reply)[0]
    item = query.addElement((None, 'item'))
    item['jid'] = JUD_SERVER
    stream.send(reply)

    # wait for the disco#info query
    event = q.expect('stream-iq', to=JUD_SERVER, query_ns=ns.DISCO_INFO)

    reply = elem_iq(stream, 'result', id=event.stanza['id'], from_=JUD_SERVER)(
        elem(ns.DISCO_INFO, 'query')(elem('identity',
                                          category='directory',
                                          type='user',
                                          name='vCard User Search')(),
                                     elem('feature', var=ns.SEARCH)()))

    stream.send(reply)

    # JUD_SERVER is used as default, and shows up as the Server property on the
    # resulting channel.
    ret, _ = answer_field_query(q, stream, JUD_SERVER)
    _, properties = ret.value
    assertEquals(JUD_SERVER, properties[cs.CONTACT_SEARCH_SERVER])

    # Now that the search server has been discovered, it is used right away.
    call_create(q, conn, server=server)
    ret, _ = answer_field_query(q, stream, JUD_SERVER)
    _, properties = ret.value
    assertEquals(JUD_SERVER, properties[cs.CONTACT_SEARCH_SERVER])
def test_data_forms(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("Hope you like x:data")
    # Use the same element names as in jabber:iq:register as per XEP 0077's
    # Extensibility section.
    x = query.addElement((ns.X_DATA, 'x'))
    x['type'] = 'form'
    x.addElement((None, 'title')).addChild("Account Registration")
    x.addElement(
        (None, 'instructions')).addChild("This is gratuitously a data form!")

    form_type = x.addElement((None, 'field'))
    form_type['type'] = 'hidden'
    form_type['var'] = 'FORM_TYPE'
    form_type.addElement((None, 'value')).addChild(ns.REGISTER)

    first = x.addElement((None, 'field'))
    first['type'] = 'text-single'
    first['label'] = 'Username'
    first['var'] = 'username'
    first.addElement((None, 'required'))

    first = x.addElement((None, 'field'))
    first['type'] = 'text-single'
    first['label'] = 'Password'
    first['var'] = 'password'
    first.addElement((None, 'required'))

    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])
Ejemplo n.º 57
0
def handle_muc_owner_get_iq(stream, stanza):
    iq = make_result_iq(stream, stanza)
    query = iq.firstChildElement()
    x = query.addElement(('jabber:x:data', 'x'))
    x['type'] = 'form'

    for var, values in get_default_form().iteritems():
        if len(values) > 1:
            field = x.addElement('field')
            field['type'] = 'list-multi'
            field['var'] = var
            for v in values:
                field.addElement('value', content=v)
                field.addElement('option', content=v)
        elif values[0] == '0' or values[0] == '1':
            add_field(x, 'boolean', var, values[0])
        else:
            add_field(x, 'text', var, values[0])

    stream.send(iq)