def test_google_caps(q, bus, conn, stream): i = 1 # we want to make sure all permutations of voice-v1 and video-v1 # result in the correct caps, so let's do exactly that. for j in (1, 2): for ext_set in permutations(['voice-v1', 'video-v1'], j): jid = 'larry%s@page/mountainview' % i i += 1 # order of these ext values shouldn't matter gcaps = { 'node': 'blahblahthiskeepsonchanging', 'ver': '1.1', 'ext': ' '.join(ext_set) } handle = conn.get_contact_handle_sync(jid) send_presence(q, conn, stream, jid, gcaps, initial=True) e = q.expect('dbus-signal', signal='ContactCapabilitiesChanged', predicate=lambda e: handle in e.args[0]) assertEquals(1, len(e.args[0])) rccs = e.args[0][handle] found = False for fixed, allowed in rccs: if fixed[cs.CHANNEL_TYPE] != cs.CHANNEL_TYPE_CALL: continue # we should only have InitialAudio or InitialVideo if # voice-v1 or video-v1 is present respectively for a, b in [('voice-v1' in ext_set, cs.CALL_INITIAL_AUDIO), ('video-v1' in ext_set, cs.CALL_INITIAL_VIDEO)]: if a: assertContains(b, allowed) else: assertDoesNotContain(b, allowed) found = True assert found
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']]), )
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)
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)