예제 #1
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)
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)
def two_contacts_with_the_same_hash(q, bus, conn, stream, bare_jids):
    contact1 = '*****@*****.**'
    contact2 = '*****@*****.**'

    if not bare_jids:
        contact1 += '/lol'
        contact2 += '/whut'

    h1, h2 = conn.get_contact_handles_sync([contact1, contact2])
    ver = compute_caps_hash(BANANAPHONE, features, {})
    caps = {
        # Uniquify slightly with a stringified boolean ;-)
        'node': '%s%s' % (client_base, bare_jids),
        'ver': ver,
        'hash': 'sha-1',
    }

    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']]),
    )
예제 #4
0
def two_contacts_with_the_same_hash(q, bus, conn, stream, bare_jids):
    contact1 = '*****@*****.**'
    contact2 = '*****@*****.**'

    if not bare_jids:
        contact1 += '/lol'
        contact2 += '/whut'

    h1, h2 = conn.get_contact_handles_sync([contact1, contact2])
    ver = compute_caps_hash(BANANAPHONE, features, {})
    caps = {
        # Uniquify slightly with a stringified boolean ;-)
        'node': '%s%s' % (client_base, bare_jids),
        'ver':  ver,
        'hash': 'sha-1',
        }

    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']]),
        )
예제 #5
0
def test(q, bus, conn, stream):
    caps = {
        'node': client,
        'ver':  '0.1',
        }

    update_contact_caps(q, conn, stream, '[email protected]/Foo', caps)
    update_contact_caps(q, conn, stream, '[email protected]/Foo', caps)

    # Meredith signs in from one resource.
    update_contact_caps(q, conn, stream, '[email protected]/One', caps)
    # Meredith signs in from another resource with the same client. We don't
    # need to disco her, even though we don't trust this caps node in general
    # yet, because she's already told us what it means.
    meredith_two = '[email protected]/Two'
    q.forbid_events([
        EventPattern('stream-iq', to=meredith_two, query_ns=ns.DISCO_INFO)
        ])
    stream.send(make_presence(meredith_two, 'hello', caps=caps))
    sync_stream(q, stream)

    # Jens signs in from one resource, which is slow to answer the disco query.
    jens_one = '[email protected]/One'
    j = send_presence(q, conn, stream, jens_one, caps)
    j_stanza = expect_disco(q, jens_one, client, caps)

    # Jens now signs in elsewhere with the same client; we disco it (maybe
    # it'll reply sooner? Maybe his first client's network connection went away
    # and the server hasn't noticed yet?) and it replies immediately.
    update_contact_caps (q, conn, stream, '[email protected]/Two', caps,
        initial=False)

    # Jens' first client replies. We don't expect any caps changes here, and
    # this shouldn't count as a second point towards the five we need to trust
    # this caps node.
    send_disco_reply(stream, j_stanza, [], features)
    check_caps (conn, j)

    update_contact_caps (q, conn, stream, '[email protected]/Foo', caps)

    # Now five distinct contacts have told us what this caps node means, we
    # trust it.
    update_contact_caps (q, conn, stream, '[email protected]/Foo', caps,
        disco = False)
    update_contact_caps (q, conn, stream, '[email protected]/Foo', caps,
        disco = False)

    caps = {
        'node': client,
        'ver':  compute_caps_hash([], features, fake_client_dataforms),
        'hash': 'sha-1',
        }

    update_contact_caps(q, conn, stream, '[email protected]/Foo',
       caps,  dataforms = fake_client_dataforms)
    # We can verify the reply for these caps against the hash, and thus never
    # need to disco it again.
    update_contact_caps(q, conn, stream, '[email protected]/Foo', caps,
        disco = False, dataforms = fake_client_dataforms)
    update_contact_caps(q, conn, stream, '[email protected]/Foo', caps,
        disco = False, dataforms = fake_client_dataforms)
def test(q, bus, conn, stream):
    # check all these types appear as they should
    contact_online(q, conn, stream, '[email protected]/lol', BOT)
    contact_online(q, conn, stream, '[email protected]/lol', CONSOLE)
    contact_online(q, conn, stream, '[email protected]/lol', GAME)
    contact_online(q, conn, stream, '[email protected]/lol', HANDHELD)
    contact_online(q, conn, stream, '[email protected]/lol', PC)
    contact_online(q, conn, stream, '[email protected]/lol', PHONE)
    contact_online(q, conn, stream, '[email protected]/lol', WEB)
    contact_online(q, conn, stream, '[email protected]/lol', SMS)

    meredith_one = '[email protected]/One'
    meredith_two = '[email protected]/Two'
    meredith_three = '[email protected]/Three'
    meredith_handle = conn.get_contact_handle_sync(meredith_one)

    # Meredith signs in from one resource
    contact_online(q, conn, stream, meredith_one, PC, show='chat')

    # * One: chat: pc
    # ClientTypes should be: ['pc']

    # Meredith signs in from another resource
    contact_online(q,
                   conn,
                   stream,
                   meredith_two,
                   PHONE,
                   show='dnd',
                   initial=False)

    # * One: chat: pc
    # * Two: dnd: phone
    # ClientTypes should be: ['pc']

    # check we're still a PC
    types = get_client_types(conn, meredith_handle)

    assertLength(1, types)
    assertEquals('pc', types[0])

    types = conn.RequestClientTypes(meredith_handle,
                                    dbus_interface=cs.CONN_IFACE_CLIENT_TYPES)

    assertLength(1, types)
    assertEquals('pc', types[0])

    # Two now becomes more available
    stream.send(make_presence(meredith_two, show='chat'))

    # * One: chat: pc
    # * Two: chat: phone
    # ClientTypes should be: ['pc']

    types = get_client_types(conn, meredith_handle)
    assertEquals('pc', types[0])

    # One now becomes less available
    stream.send(make_presence(meredith_one, show='away'))

    # * One: away: pc
    # * Two: chat: phone
    # ClientTypes should be: ['phone']

    # wait for the presence change
    q.expect('dbus-signal',
             signal='PresencesChanged',
             args=[{
                 meredith_handle: (cs.PRESENCE_AVAILABLE, 'chat', '')
             }])

    # now wait for the change in client type
    event = q.expect('dbus-signal', signal='ClientTypesUpdated')
    assertEquals([meredith_handle, ['phone']], event.args)

    # make One more available again
    stream.send(make_presence(meredith_one, show='chat', status='lawl'))

    # * One: chat: pc
    # * Two: chat: phone
    # ClientTypes should be: ['pc']

    # wait for the presence change
    q.expect('dbus-signal',
             signal='PresencesChanged',
             args=[{
                 meredith_handle: (cs.PRESENCE_AVAILABLE, 'chat', 'lawl')
             }])

    # now wait for the change in client type
    event = q.expect('dbus-signal', signal='ClientTypesUpdated')
    assertEquals([meredith_handle, ['pc']], event.args)

    # both One and Two go away
    stream.send(make_presence(meredith_one, show='away'))

    # * One: away: pc
    # * Two: chat: phone
    # ClientTypes should be: ['phone']

    stream.send(make_presence(meredith_two, show='away'))

    # * One: away: pc
    # * Two: away: phone
    # ClientTypes should be: ['pc']

    # wait for the presence change
    q.expect('dbus-signal',
             signal='PresencesChanged',
             args=[{
                 meredith_handle: (cs.PRESENCE_AWAY, 'away', '')
             }])

    # check it still thinks we're a PC
    types = get_client_types(conn, meredith_handle)
    assertEquals('pc', types[0])

    # Three, with multiple identities, signs in
    identities = [PHONE[0], CONSOLE[0], HANDHELD[0], BOT[0]]
    contact_online(q,
                   conn,
                   stream,
                   meredith_three,
                   identities,
                   show='chat',
                   initial=False)

    # * One: away: pc
    # * Two: away: phone
    # * Three: chat: phone, console, handheld, bot
    # ClientTypes should be: ['phone', 'console', 'handheld', 'bot'] in some order

    # wait for the presence change
    q.expect('dbus-signal',
             signal='PresencesChanged',
             args=[{
                 meredith_handle: (cs.PRESENCE_AVAILABLE, 'chat', 'hello')
             }])

    # now wait for the change in client type
    event = q.expect('dbus-signal', signal='ClientTypesUpdated')
    assertEquals(meredith_handle, event.args[0])
    assertEquals(['bot', 'console', 'handheld', 'phone'],
                 sorted(event.args[1]))

    # that'll do
    #
    # ...
    #
    # wait wait! no it won't! Here's a regression test for
    # <https://bugs.freedesktop.org/show_bug.cgi?id=31772>.
    (caps, client, types) = build_stuff(TRANSIENT_PHONE)
    contact = '[email protected]/hai'
    send_presence(q, conn, stream, contact, caps)
    stanza = expect_disco(q, contact, client, caps)
    stream.send(make_presence(contact, type='unavailable'))
    send_disco_reply(stream, stanza, TRANSIENT_PHONE, [])

    # Gabble used to crash upon receiving a disco reply from a contact who's no
    # longer in the presence cache. So we sync here to check if it's died.
    sync_stream(q, stream)
예제 #7
0
def test(q, bus, conn, stream):
    caps = {
        'node': client,
        'ver':  '0.1',
        }

    update_contact_caps(q, conn, stream, '[email protected]/Foo', caps)
    update_contact_caps(q, conn, stream, '[email protected]/Foo', caps)

    # Meredith signs in from one resource.
    update_contact_caps(q, conn, stream, '[email protected]/One', caps)
    # Meredith signs in from another resource with the same client. We don't
    # need to disco her, even though we don't trust this caps node in general
    # yet, because she's already told us what it means.
    meredith_two = '[email protected]/Two'
    q.forbid_events([
        EventPattern('stream-iq', to=meredith_two, query_ns=ns.DISCO_INFO)
        ])
    stream.send(make_presence(meredith_two, 'hello', caps=caps))
    sync_stream(q, stream)

    # Jens signs in from one resource, which is slow to answer the disco query.
    jens_one = '[email protected]/One'
    j = send_presence(q, conn, stream, jens_one, caps)
    j_stanza = expect_disco(q, jens_one, client, caps)

    # Jens now signs in elsewhere with the same client; we disco it (maybe
    # it'll reply sooner? Maybe his first client's network connection went away
    # and the server hasn't noticed yet?) and it replies immediately.
    update_contact_caps (q, conn, stream, '[email protected]/Two', caps,
        initial=False)

    # Jens' first client replies. We don't expect any caps changes here, and
    # this shouldn't count as a second point towards the five we need to trust
    # this caps node.
    send_disco_reply(stream, j_stanza, [], features)
    check_caps (conn, j)

    update_contact_caps (q, conn, stream, '[email protected]/Foo', caps)

    # Now five distinct contacts have told us what this caps node means, we
    # trust it.
    update_contact_caps (q, conn, stream, '[email protected]/Foo', caps,
        disco = False)
    update_contact_caps (q, conn, stream, '[email protected]/Foo', caps,
        disco = False)

    caps = {
        'node': client,
        'ver':  compute_caps_hash([], features, fake_client_dataforms),
        'hash': 'sha-1',
        }

    update_contact_caps(q, conn, stream, '[email protected]/Foo',
       caps,  dataforms = fake_client_dataforms)
    # We can verify the reply for these caps against the hash, and thus never
    # need to disco it again.
    update_contact_caps(q, conn, stream, '[email protected]/Foo', caps,
        disco = False, dataforms = fake_client_dataforms)
    update_contact_caps(q, conn, stream, '[email protected]/Foo', caps,
        disco = False, dataforms = fake_client_dataforms)
예제 #8
0
def test(q, bus, conn, stream):
    # check all these types appear as they should
    contact_online(q, conn, stream, '[email protected]/lol', BOT)
    contact_online(q, conn, stream, '[email protected]/lol', CONSOLE)
    contact_online(q, conn, stream, '[email protected]/lol', GAME)
    contact_online(q, conn, stream, '[email protected]/lol', HANDHELD)
    contact_online(q, conn, stream, '[email protected]/lol', PC)
    contact_online(q, conn, stream, '[email protected]/lol', PHONE)
    contact_online(q, conn, stream, '[email protected]/lol', WEB)
    contact_online(q, conn, stream, '[email protected]/lol', SMS)

    meredith_one = '[email protected]/One'
    meredith_two = '[email protected]/Two'
    meredith_three = '[email protected]/Three'
    meredith_handle = conn.get_contact_handle_sync(meredith_one)

    # Meredith signs in from one resource
    contact_online(q, conn, stream, meredith_one, PC, show='chat')

    # * One: chat: pc
    # ClientTypes should be: ['pc']

    # Meredith signs in from another resource
    contact_online(q, conn, stream, meredith_two, PHONE, show='dnd', initial=False)

    # * One: chat: pc
    # * Two: dnd: phone
    # ClientTypes should be: ['pc']

    # check we're still a PC
    types = get_client_types(conn, meredith_handle)

    assertLength(1, types)
    assertEquals('pc', types[0])

    types = conn.RequestClientTypes(meredith_handle,
            dbus_interface=cs.CONN_IFACE_CLIENT_TYPES)

    assertLength(1, types)
    assertEquals('pc', types[0])

    # Two now becomes more available
    stream.send(make_presence(meredith_two, show='chat'))

    # * One: chat: pc
    # * Two: chat: phone
    # ClientTypes should be: ['pc']

    types = get_client_types(conn, meredith_handle)
    assertEquals('pc', types[0])

    # One now becomes less available
    stream.send(make_presence(meredith_one, show='away'))

    # * One: away: pc
    # * Two: chat: phone
    # ClientTypes should be: ['phone']

    # wait for the presence change
    q.expect('dbus-signal', signal='PresencesChanged',
             args=[{meredith_handle: (cs.PRESENCE_AVAILABLE, 'chat', '')}])

    # now wait for the change in client type
    event = q.expect('dbus-signal', signal='ClientTypesUpdated')
    assertEquals([meredith_handle, ['phone']], event.args)

    # make One more available again
    stream.send(make_presence(meredith_one, show='chat', status='lawl'))

    # * One: chat: pc
    # * Two: chat: phone
    # ClientTypes should be: ['pc']

    # wait for the presence change
    q.expect('dbus-signal', signal='PresencesChanged',
             args=[{meredith_handle: (cs.PRESENCE_AVAILABLE, 'chat', 'lawl')}])

    # now wait for the change in client type
    event = q.expect('dbus-signal', signal='ClientTypesUpdated')
    assertEquals([meredith_handle, ['pc']], event.args)

    # both One and Two go away
    stream.send(make_presence(meredith_one, show='away'))

    # * One: away: pc
    # * Two: chat: phone
    # ClientTypes should be: ['phone']

    stream.send(make_presence(meredith_two, show='away'))

    # * One: away: pc
    # * Two: away: phone
    # ClientTypes should be: ['pc']

    # wait for the presence change
    q.expect('dbus-signal', signal='PresencesChanged',
             args=[{meredith_handle: (cs.PRESENCE_AWAY, 'away', '')}])

    # check it still thinks we're a PC
    types = get_client_types(conn, meredith_handle)
    assertEquals('pc', types[0])

    # Three, with multiple identities, signs in
    identities = [PHONE[0], CONSOLE[0], HANDHELD[0], BOT[0]]
    contact_online(q, conn, stream, meredith_three, identities,
                   show='chat', initial=False)

    # * One: away: pc
    # * Two: away: phone
    # * Three: chat: phone, console, handheld, bot
    # ClientTypes should be: ['phone', 'console', 'handheld', 'bot'] in some order

    # wait for the presence change
    q.expect('dbus-signal', signal='PresencesChanged',
             args=[{meredith_handle: (cs.PRESENCE_AVAILABLE, 'chat', 'hello')}])

    # now wait for the change in client type
    event = q.expect('dbus-signal', signal='ClientTypesUpdated')
    assertEquals(meredith_handle, event.args[0])
    assertEquals(['bot', 'console', 'handheld', 'phone'], sorted(event.args[1]))

    # that'll do
    #
    # ...
    #
    # wait wait! no it won't! Here's a regression test for
    # <https://bugs.freedesktop.org/show_bug.cgi?id=31772>.
    (caps, client, types) = build_stuff(TRANSIENT_PHONE)
    contact = '[email protected]/hai'
    send_presence(q, conn, stream, contact, caps)
    stanza = expect_disco(q, contact, client, caps)
    stream.send(make_presence(contact, type='unavailable'))
    send_disco_reply(stream, stanza, TRANSIENT_PHONE, [])

    # Gabble used to crash upon receiving a disco reply from a contact who's no
    # longer in the presence cache. So we sync here to check if it's died.
    sync_stream(q, stream)