def check_NewChannels_signal(conn, args, channel_type, chan_path, contact_handle, contact_id, initiator_handle): """ Checks the first argument, a one-tuple of arguments from NewChannels, matches the other arguments. """ assert len(args) == 1, args assert len(args[0]) == 1 # one channel path, props = args[0][0] assert path == chan_path, (emitted_path, chan_path) assert props[cs.CHANNEL_TYPE] == channel_type, (props, channel_type) assert props[cs.TARGET_HANDLE_TYPE] == cs.HT_CONTACT, props assert props[cs.TARGET_HANDLE] == contact_handle, (props, contact_handle) assert props[cs.TARGET_ID] == contact_id, (props, contact_id) assert props[cs.REQUESTED] == True, props assert props[cs.INITIATOR_HANDLE] == initiator_handle, \ (props, initiator_handle) assert props[cs.INITIATOR_ID] == 'test@localhost', props # check that the newly announced channel is in the channels list all_channels = conn.Get(cs.CONN_IFACE_REQUESTS, 'Channels', dbus_interface=cs.PROPERTIES_IFACE, byte_arrays=True) assertContains((path, props), all_channels)
def test(q, bus, conn, stream): # The user happily joins a MUC chan, _, _ = join_muc(q, bus, conn, stream, MUC) muc_self_handle = chan.Properties.Get(cs.CHANNEL_IFACE_GROUP, "SelfHandle") muc_self_jid = conn.inspect_contact_sync(muc_self_handle) # But then Bob kicks us. bob_jid = '%s/bob' % MUC bob_handle = conn.get_contact_handle_sync(bob_jid) stream.send( elem('presence', from_=muc_self_jid, type='unavailable')(elem(ns.MUC_USER, 'x')( elem('item', affiliation='none', role='none')(elem('actor', jid=bob_jid), elem('reason')(u'bye')), elem('status', code='307'), ))) mcd_event = q.expect('dbus-signal', signal='MembersChangedDetailed') added, removed, local_pending, remote_pending, details = mcd_event.args assertEquals([], added) assertEquals([muc_self_handle], removed) assertEquals([], local_pending) assertEquals([], remote_pending) assertContains('actor', details) assertEquals(bob_handle, details['actor']) assertEquals(cs.GC_REASON_KICKED, details['change-reason']) assertEquals('bye', details['message']) q.expect('dbus-signal', signal='ChannelClosed')
def test_with_xep0186(q, bus, conn, stream): statuses = conn.Properties.Get(cs.CONN_IFACE_SIMPLE_PRESENCE, 'Statuses') # testbusy and testaway are provided by test plugin assertContains('testbusy', statuses) assertContains('testaway', statuses) assertEquals(statuses['testbusy'][0], cs.PRESENCE_BUSY) assertEquals(statuses['testaway'][0], cs.PRESENCE_AWAY) conn.SimplePresence.SetPresence('testbusy', '') conn.Connect() # ... gabble asks for all the available lists on the server ... stream.handle_get_all_privacy_lists( q, bus, conn, lists=["foo-list", "test-busy-list", "bar-list"]) get_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set') list_node = xpath.queryForNodes('//active', get_list.query)[0] # ... and then activates the one linked with the requested status # Note: testbusy status is linked to test-busy-list by test plugin assertEquals('test-busy-list', list_node['name']) acknowledge_iq(stream, get_list.stanza) q.expect('dbus-signal', signal='PresencesChanged', args=[{ 1L: (cs.PRESENCE_BUSY, u'testbusy', '') }])
def test_create_invisible_list(q, bus, conn, stream): conn.SimplePresence.SetPresence("away", "") conn.Connect() stream.handle_get_all_privacy_lists(q, bus, conn) get_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='get') list_node = xpath.queryForNodes('//list', get_list.query)[0] assertEquals('invisible', list_node['name']) error = domish.Element((None, 'error')) error['type'] = 'cancel' error.addElement((ns.STANZA, 'item-not-found')) send_error_reply (stream, get_list.stanza, error) create_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set') list_node = xpath.queryForNodes('//list', create_list.query)[0] assertEquals('invisible', list_node['name']) assertNotEquals([], xpath.queryForNodes('/query/list/item/presence-out', create_list.query)) acknowledge_iq(stream, create_list.stanza) q.expect('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]) assertContains("hidden", conn.Properties.Get(cs.CONN_IFACE_SIMPLE_PRESENCE, "Statuses"))
def test_error(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') error = domish.Element((None, 'error')) error.addElement((ns.STANZA, 'service-unavailable')) send_error_reply(stream, stanza, error) q.expect('dbus-error', method='SetPowerSaving', name=cs.NOT_AVAILABLE) # Power saving state should remain false assertEquals( False, conn.Get(cs.CONN_IFACE_POWER_SAVING, "PowerSavingActive", dbus_interface=cs.PROPERTIES_IFACE))
def receiving_failed(self, content): self.receiving = False assert self.contents[0].stream.Properties.Get(cs.CALL_STREAM_IFACE_MEDIA, 'SendingState') == cs.CALL_STREAM_FLOW_STATE_STARTED content.stream.Media.ReportReceivingFailure( cs.CALL_STATE_CHANGE_REASON_MEDIA_ERROR, "", "receiving error") o = self.q.expect_many( EventPattern('dbus-signal', signal='ReceivingStateChanged', args=[cs.CALL_STREAM_FLOW_STATE_STOPPED], path=content.stream.__dbus_object_path__), EventPattern('dbus-signal', signal='RemoteMembersChanged', path=content.stream.__dbus_object_path__, predicate=lambda e: e.args[0] == {self.remote_handle: cs.CALL_SENDING_STATE_PENDING_STOP_SENDING}), EventPattern('sip-invite')) reinvite_event = o[2] assertContains('a=sendonly', reinvite_event.sip_message.body) self.context.check_call_sdp(reinvite_event.sip_message.body) body = reinvite_event.sip_message.body.replace( 'sendonly', self.sending and 'recvonly' or 'inactive') self.context.accept(reinvite_event.sip_message, body) ack_cseq = "%s ACK" % reinvite_event.cseq.split()[0] self.q.expect('sip-ack', cseq=ack_cseq) self.start_receiving(content)
def advertise_caps(q, bus, conn, stream, filters, expected_features, unexpected_features, expected_caps): # make sure nothing from a previous update is still running sync_dbus(bus, q, conn) self_handle = conn.Properties.Get(cs.CONN, "SelfHandle") ret_caps = conn.ContactCapabilities.UpdateCapabilities( [(cs.CLIENT + '.Foo', filters, [])]) # Expect Gabble to reply with the correct caps event, namespaces, _, signaled_caps = receive_presence_and_ask_caps(q, stream) assertSameElements(expected_caps, signaled_caps[self_handle]) assertContains(ns.TP_FT_METADATA, namespaces) for var in expected_features: assertContains(var, namespaces) for var in unexpected_features: assertDoesNotContain(var, namespaces) # Check our own caps caps = get_contacts_capabilities_sync(conn, [self_handle]) assertSameElements(expected_caps, caps[self_handle]) # check the Contacts interface give the same caps caps_via_contacts_iface = conn.Contacts.GetContactAttributes( [self_handle], [cs.CONN_IFACE_CONTACT_CAPS], False) \ [self_handle][cs.ATTR_CONTACT_CAPABILITIES] assertSameElements(caps[self_handle], caps_via_contacts_iface)
def build_request(conn, channel_name, use_room): rccs = conn.Properties.Get(cs.CONN_IFACE_REQUESTS, 'RequestableChannelClasses') if use_room: # We allow TargetHandleType in Room-flavoured requests, but it has to # be None if specified. assertContains( ({ cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT }, [cs.TARGET_HANDLE_TYPE, cs.ROOM_NAME], ), rccs) request = { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.ROOM_NAME: '#idletest' } else: assertContains( ({ cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_ROOM, }, [cs.TARGET_HANDLE, cs.TARGET_ID] ), rccs) request = { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_ROOM, cs.TARGET_ID: '#idletest', } return dbus.Dictionary(request, signature='sv')
def test_create_invisible_list(q, bus, conn, stream): conn.SimplePresence.SetPresence("away", "") conn.Connect() stream.handle_get_all_privacy_lists(q, bus, conn) get_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='get') list_node = xpath.queryForNodes('//list', get_list.query)[0] assertEquals('invisible', list_node['name']) error = domish.Element((None, 'error')) error['type'] = 'cancel' error.addElement((ns.STANZA, 'item-not-found')) send_error_reply(stream, get_list.stanza, error) create_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set') list_node = xpath.queryForNodes('//list', create_list.query)[0] assertEquals('invisible', list_node['name']) assertNotEquals([], xpath.queryForNodes('/query/list/item/presence-out', create_list.query)) acknowledge_iq(stream, create_list.stanza) q.expect('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]) assertContains( "hidden", conn.Properties.Get(cs.CONN_IFACE_SIMPLE_PRESENCE, "Statuses"))
def sending_failed(self, content): self.sending = False content.stream.Media.ReportSendingFailure( cs.CALL_STATE_CHANGE_REASON_MEDIA_ERROR, "", "sending error") o = self.q.expect_many( EventPattern('dbus-signal', signal='SendingStateChanged', args=[cs.CALL_STREAM_FLOW_STATE_STOPPED], path=content.stream.__dbus_object_path__), EventPattern('dbus-signal', signal='LocalSendingStateChanged', path=content.stream.__dbus_object_path__, predicate=lambda e: e.args[0] == 0), EventPattern('sip-invite')) assertEquals(cs.CALL_SENDING_STATE_NONE, o[1].args[0]) assertEquals(self.self_handle, o[1].args[1][0]) reinvite_event = o[2] assertContains('a=recvonly', reinvite_event.sip_message.body) self.context.check_call_sdp(reinvite_event.sip_message.body) body = reinvite_event.sip_message.body.replace( 'recvonly', self.receiving and 'sendonly' or 'inactive') self.context.accept(reinvite_event.sip_message, body) ack_cseq = "%s ACK" % reinvite_event.cseq.split()[0] self.q.expect('sip-ack', cseq=ack_cseq) self.start_sending(content)
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)
def test_invisible(q, bus, conn, stream): assertContains("hidden", conn.Properties.Get(cs.CONN_IFACE_SIMPLE_PRESENCE, "Statuses")) conn.SimplePresence.SetPresence("hidden", "") # First we send an <invisible/> command. event = q.expect('stream-iq', query_name='invisible') acknowledge_iq(stream, event.stanza) # When that's returned successfully, we can signal the change on D-Bus. q.expect('dbus-signal', signal='PresencesChanged', interface=cs.CONN_IFACE_SIMPLE_PRESENCE, args=[{1: (5, 'hidden', '')}]) conn.SimplePresence.SetPresence("away", "gone") # First Gabble sends a <visible/> command. event = q.expect('stream-iq', query_name='visible') acknowledge_iq(stream, event.stanza) # Then: "It is the responsibility of the client to send an undirected # presence notification to the server". Plus, we should signal the change # on D-Bus. q.expect_many( EventPattern('stream-presence', to=None), EventPattern('dbus-signal', signal='PresencesChanged', interface=cs.CONN_IFACE_SIMPLE_PRESENCE, args=[{1: (3, 'away', 'gone')}]))
def test(q, bus, conn, stream): # The user happily joins a MUC chan, _, _ = join_muc(q, bus, conn, stream, MUC) muc_self_handle = chan.Properties.Get(cs.CHANNEL_IFACE_GROUP, "SelfHandle") muc_self_jid = conn.inspect_contact_sync(muc_self_handle) # But then Bob kicks us. bob_jid = '%s/bob' % MUC bob_handle = conn.get_contact_handle_sync(bob_jid) stream.send( elem('presence', from_=muc_self_jid, type='unavailable')( elem(ns.MUC_USER, 'x')( elem('item', affiliation='none', role='none')( elem('actor', jid=bob_jid), elem('reason')( u'bye' ) ), elem('status', code='307'), ) )) mcd_event = q.expect('dbus-signal', signal='MembersChangedDetailed') added, removed, local_pending, remote_pending, details = mcd_event.args assertEquals([], added) assertEquals([muc_self_handle], removed) assertEquals([], local_pending) assertEquals([], remote_pending) assertContains('actor', details) assertEquals(bob_handle, details['actor']) assertEquals(cs.GC_REASON_KICKED, details['change-reason']) assertEquals('bye', details['message']) q.expect('dbus-signal', signal='ChannelClosed')
def test_error(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') error = domish.Element((None, 'error')) error.addElement((ns.STANZA, 'service-unavailable')) send_error_reply(stream, stanza, error) q.expect('dbus-error', method='SetPowerSaving', name=cs.NOT_AVAILABLE) # Power saving state should remain false assertEquals (False, conn.Get(cs.CONN_IFACE_POWER_SAVING, "PowerSavingActive", dbus_interface=cs.PROPERTIES_IFACE))
def build_request(conn, channel_name, use_room): rccs = conn.Properties.Get(cs.CONN_IFACE_REQUESTS, 'RequestableChannelClasses') if use_room: # We allow TargetHandleType in Room-flavoured requests, but it has to # be None if specified. assertContains(( { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT }, [cs.TARGET_HANDLE_TYPE, cs.ROOM_NAME], ), rccs) request = { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.ROOM_NAME: '#idletest' } else: assertContains(({ cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_ROOM, }, [cs.TARGET_HANDLE, cs.TARGET_ID]), rccs) request = { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_ROOM, cs.TARGET_ID: '#idletest', } return dbus.Dictionary(request, signature='sv')
def advertise_caps(q, conn, stream, filters, expected_features, unexpected_features, expected_caps): self_handle = conn.GetSelfHandle() ret_caps = conn.ContactCapabilities.UpdateCapabilities( [(cs.CLIENT + '.Foo', filters, [])]) # Expect Gabble to reply with the correct caps event, namespaces, _, signaled_caps = receive_presence_and_ask_caps(q, stream) assertSameElements(expected_caps, signaled_caps) assertContains(ns.TUBES, namespaces) for var in expected_features: assertContains(var, namespaces) for var in unexpected_features: assertDoesNotContain(var, namespaces) # Check our own caps caps = conn.ContactCapabilities.GetContactCapabilities([self_handle]) assertSameElements(expected_caps, caps) # check the Contacts interface give the same caps caps_via_contacts_iface = conn.Contacts.GetContactAttributes( [self_handle], [cs.CONN_IFACE_CONTACT_CAPS], False) \ [self_handle][cs.ATTR_CONTACT_CAPABILITIES] assertSameElements(caps[self_handle], caps_via_contacts_iface)
def test_content_addition(self): path = self.chan.AddContent("Webcam", cs.CALL_MEDIA_TYPE_VIDEO, cs.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL, dbus_interface=cs.CHANNEL_TYPE_CALL) content = self.bus.get_object(self.conn.bus_name, path) content_properties = content.GetAll(cs.CALL_CONTENT, dbus_interface=dbus.PROPERTIES_IFACE) assertEquals(cs.CALL_DISPOSITION_NONE, content_properties["Disposition"]) #assertEquals(self_handle, content_properties["Creator"]) assertContains("Webcam", content_properties["Name"]) md = self.jt2.get_call_video_md_dbus() self.check_and_accept_offer(content, md) cstream = self.bus.get_object(self.conn.bus_name, content_properties["Streams"][0]) candidates = self.jt2.get_call_remote_transports_dbus() cstream.AddCandidates(candidates, dbus_interface=cs.CALL_STREAM_IFACE_MEDIA) self.q.expect('stream-iq', predicate=self.jp.action_predicate('content-add')) content.Remove(dbus_interface=cs.CALL_CONTENT) self.q.expect('stream-iq', predicate=self.jp.action_predicate('content-remove'))
def test(q, bus, conn): cm = bus.get_object(cs.CM + '.ring', tp_path_prefix + '/ConnectionManager/ring') cm_iface = dbus.Interface(cm, cs.CM) cm_prop_iface = dbus.Interface(cm, cs.PROPERTIES_IFACE) protocols = unwrap(cm_prop_iface.Get(cs.CM, 'Protocols')) assertEquals(set(['tel']), set(protocols.keys())) protocol_names = unwrap(cm_iface.ListProtocols()) assertEquals(set(['tel']), set(protocol_names)) cm_params = cm_iface.GetParameters('tel') local_props = protocols['tel'] local_params = local_props[cs.PROTOCOL + '.Parameters'] assertEquals(cm_params, local_params) proto = bus.get_object(cm.bus_name, cm.object_path + '/tel') proto_prop_iface = dbus.Interface(proto, cs.PROPERTIES_IFACE) proto_props = unwrap(proto_prop_iface.GetAll(cs.PROTOCOL)) for key in [ 'Parameters', 'Interfaces', 'ConnectionInterfaces', 'RequestableChannelClasses', u'VCardField', u'EnglishName', u'Icon' ]: a = local_props[cs.PROTOCOL + '.' + key] b = proto_props[key] assertEquals(a, b) assertEquals('tel', proto_props['VCardField']) assertEquals('Mobile Telephony', proto_props['EnglishName']) assertEquals('im-tel', proto_props['Icon']) assertContains(cs.CONN_IFACE_REQUESTS, proto_props['ConnectionInterfaces'])
def test_deny_unblock_remove(q, bus, conn, stream, stored, deny): """ Test unblocking a contact, and, while that request is pending, deleting them. """ self_handle = conn.GetSelfHandle() # This contact was on our roster, blocked and subscribed, when we started. contact = '*****@*****.**' handle = conn.RequestHandles(cs.HT_CONTACT, [contact])[0] # They're blocked, and we have a bidi subscription, so they should be on # deny and stored. (We already checked this earlier, but we've been messing # with the roster so let's be sure the preconditions are okay...) assertContains(handle, deny.Properties.Get(cs.CHANNEL_IFACE_GROUP, "Members")) assertContains(handle, stored.Properties.Get(cs.CHANNEL_IFACE_GROUP, "Members")) # Unblock them. call_async(q, deny.Group, 'RemoveMembers', [handle], "") roster_event = q.expect('stream-iq', query_ns=ns.ROSTER) item = roster_event.query.firstChildElement() assertEquals(contact, item['jid']) assertDoesNotContain((ns.GOOGLE_ROSTER, 't'), item.attributes) # If we now remove them from stored, the edit shouldn't be sent until the # unblock event has had a reply. q.forbid_events(remove_events) call_async(q, stored.Group, 'RemoveMembers', [handle], "") # Make sure if the remove is sent prematurely, we catch it. sync_stream(q, stream) q.unforbid_events(remove_events) # So now we send a roster push and reply for the unblock request. stream.send(make_set_roster_iq(stream, 'test@localhost/Resource', contact, 'both', False, attrs={})) acknowledge_iq(stream, roster_event.stanza) # And on receiving the push and reply, Gabble should show them being # removed from deny, and send a remove. _, roster_event = q.expect_many( EventPattern('dbus-signal', signal='MembersChanged', args=['', [], [handle], [], [], self_handle, cs.GC_REASON_NONE], predicate=is_deny), remove_events[0], ) item = roster_event.query.firstChildElement() assertEquals(contact, item['jid']) stream.send(make_set_roster_iq(stream, 'test@localhost/Resource', contact, 'remove', False, attrs={})) acknowledge_iq(stream, roster_event.stanza) q.expect('dbus-signal', signal='MembersChanged', args=['', [], [handle], [], [], 0, cs.GC_REASON_NONE], predicate=is_stored)
def test_plain_fail_helper(q, bus, conn, stream, element, error, csr): chan, props = connect_and_get_sasl_channel(q, bus, conn) chan.SASLAuthentication.StartMechanismWithData('PLAIN', INITIAL_RESPONSE) e, _ = q.expect_many( EventPattern('sasl-auth', initial_response=INITIAL_RESPONSE), EventPattern('dbus-signal', signal='SASLStatusChanged', interface=cs.CHANNEL_IFACE_SASL_AUTH, args=[cs.SASL_STATUS_IN_PROGRESS, '', {}]), ) authenticator = e.authenticator authenticator.failure(element) e = q.expect('dbus-signal', signal='SASLStatusChanged', interface=cs.CHANNEL_IFACE_SASL_AUTH) assertEquals([cs.SASL_STATUS_SERVER_FAILED, error], e.args[:2]) assertContains('debug-message', e.args[2]) e = q.expect('dbus-signal', signal='ConnectionError') assertEquals(error, e.args[0]) q.expect('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_DISCONNECTED, csr])
def test_with_xep0186(q, bus, conn, stream): statuses = conn.Properties.Get(cs.CONN_IFACE_SIMPLE_PRESENCE, 'Statuses') # testbusy and testaway are provided by test plugin assertContains('testbusy', statuses) assertContains('testaway', statuses) assertEquals(statuses['testbusy'][0], cs.PRESENCE_BUSY) assertEquals(statuses['testaway'][0], cs.PRESENCE_AWAY) conn.SimplePresence.SetPresence('testbusy', '') conn.Connect() # ... gabble asks for all the available lists on the server ... stream.handle_get_all_privacy_lists(q, bus, conn, lists=["foo-list", "test-busy-list", "bar-list"]) get_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set') list_node = xpath.queryForNodes('//active', get_list.query)[0] # ... and then activates the one linked with the requested status # Note: testbusy status is linked to test-busy-list by test plugin assertEquals('test-busy-list', list_node['name']) acknowledge_iq(stream, get_list.stanza) q.expect('dbus-signal', signal='PresencesChanged', args=[{1L: (cs.PRESENCE_BUSY, u'testbusy', '')}])
def advertise_caps(q, conn, stream, filters, expected_features, unexpected_features, expected_caps): self_handle = conn.Properties.Get(cs.CONN, "SelfHandle") ret_caps = conn.ContactCapabilities.UpdateCapabilities([ (cs.CLIENT + '.Foo', filters, []) ]) # Expect Gabble to reply with the correct caps event, namespaces, _, signaled_caps = receive_presence_and_ask_caps( q, stream) assertSameElements(expected_caps, signaled_caps) assertContains(ns.TUBES, namespaces) for var in expected_features: assertContains(var, namespaces) for var in unexpected_features: assertDoesNotContain(var, namespaces) # Check our own caps caps = get_contacts_capabilities_sync(conn, [self_handle]) assertSameElements(expected_caps, caps) # check the Contacts interface give the same caps caps_via_contacts_iface = conn.Contacts.GetContactAttributes( [self_handle], [cs.CONN_IFACE_CONTACT_CAPS], False) \ [self_handle][cs.ATTR_CONTACT_CAPABILITIES] assertSameElements(caps[self_handle], caps_via_contacts_iface)
def test(q, bus, conn, stream): # The user happily joins a MUC _, chan, _, _ = join_muc(q, bus, conn, stream, MUC) muc_self_handle = chan.Group.GetSelfHandle() muc_self_jid, = conn.InspectHandles(cs.HT_CONTACT, [muc_self_handle]) # But then Bob kicks us. bob_jid = "%s/bob" % MUC bob_handle, = conn.RequestHandles(cs.HT_CONTACT, [bob_jid]) stream.send( elem("presence", from_=muc_self_jid, type="unavailable")( elem(ns.MUC_USER, "x")( elem("item", affiliation="none", role="none")(elem("actor", jid=bob_jid), elem("reason")(u"bye")), elem("status", code="307"), ) ) ) mcd_event = q.expect("dbus-signal", signal="MembersChangedDetailed") added, removed, local_pending, remote_pending, details = mcd_event.args assertEquals([], added) assertEquals([muc_self_handle], removed) assertEquals([], local_pending) assertEquals([], remote_pending) assertContains("actor", details) assertEquals(bob_handle, details["actor"]) assertEquals(cs.GC_REASON_KICKED, details["change-reason"]) assertEquals("bye", details["message"]) q.expect("dbus-signal", signal="ChannelClosed")
def test(q, bus, conn): cm = bus.get_object(cs.CM + '.ring', tp_path_prefix + '/ConnectionManager/ring') cm_iface = dbus.Interface(cm, cs.CM) cm_prop_iface = dbus.Interface(cm, cs.PROPERTIES_IFACE) protocols = unwrap(cm_prop_iface.Get(cs.CM, 'Protocols')) assertEquals(set(['tel']), set(protocols.keys())) protocol_names = unwrap(cm_iface.ListProtocols()) assertEquals(set(['tel']), set(protocol_names)) cm_params = cm_iface.GetParameters('tel') local_props = protocols['tel'] local_params = local_props[cs.PROTOCOL + '.Parameters'] assertEquals(cm_params, local_params) proto = bus.get_object(cm.bus_name, cm.object_path + '/tel') proto_prop_iface = dbus.Interface(proto, cs.PROPERTIES_IFACE) proto_props = unwrap(proto_prop_iface.GetAll(cs.PROTOCOL)) for key in ['Parameters', 'Interfaces', 'ConnectionInterfaces', 'RequestableChannelClasses', u'VCardField', u'EnglishName', u'Icon']: a = local_props[cs.PROTOCOL + '.' + key] b = proto_props[key] assertEquals(a, b) assertEquals('tel', proto_props['VCardField']) assertEquals('Mobile Telephony', proto_props['EnglishName']) assertEquals('im-tel', proto_props['Icon']) assertContains(cs.CONN_IFACE_REQUESTS, proto_props['ConnectionInterfaces'])
def stop_sending(self, content): self.sending = False content.stream.SetSending(False) self.q.expect('dbus-signal', signal='SendingStateChanged', args=[cs.CALL_STREAM_FLOW_STATE_PENDING_STOP], path=content.stream.__dbus_object_path__) content.stream.Media.CompleteSendingStateChange( cs.CALL_STREAM_FLOW_STATE_STOPPED) o = self.q.expect_many( EventPattern('dbus-signal', signal='SendingStateChanged', args=[cs.CALL_STREAM_FLOW_STATE_STOPPED], path=content.stream.__dbus_object_path__), EventPattern('dbus-signal', signal='LocalSendingStateChanged', path=content.stream.__dbus_object_path__), EventPattern('sip-invite')) assertEquals(cs.CALL_SENDING_STATE_NONE, o[1].args[0]) assertEquals(self.self_handle, o[1].args[1][0]) reinvite_event = o[2] assertContains('a=recvonly', reinvite_event.sip_message.body) self.context.check_call_sdp(reinvite_event.sip_message.body) body = reinvite_event.sip_message.body.replace( 'recvonly', self.receiving and 'sendonly' or 'inactive') self.context.accept(reinvite_event.sip_message, body) ack_cseq = "%s ACK" % reinvite_event.cseq.split()[0] self.q.expect('sip-ack', cseq=ack_cseq)
def test(q, bus, conn, stream): self_handle = conn.GetSelfHandle() jid = '*****@*****.**' foo_handle = conn.RequestHandles(cs.HT_CONTACT, [jid])[0] properties = conn.GetAll( cs.CONN_IFACE_REQUESTS, dbus_interface=dbus.PROPERTIES_IFACE) assert properties.get('Channels') == [], properties['Channels'] assert ({cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT, }, [cs.TARGET_HANDLE, cs.TARGET_ID], ) in properties.get('RequestableChannelClasses'),\ properties['RequestableChannelClasses'] call_async(q, conn.Requests, 'CreateChannel', { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT, cs.TARGET_HANDLE: foo_handle, }) ret, old_sig, new_sig = q.expect_many( EventPattern('dbus-return', method='CreateChannel'), EventPattern('dbus-signal', signal='NewChannel'), EventPattern('dbus-signal', signal='NewChannels'), ) assert len(ret.value) == 2 emitted_props = ret.value[1] assert emitted_props[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_TEXT assert emitted_props[cs.TARGET_HANDLE_TYPE] == cs.HT_CONTACT assert emitted_props[cs.TARGET_HANDLE] == foo_handle assert emitted_props[cs.TARGET_ID] == jid assert emitted_props[cs.REQUESTED] == True assert emitted_props[cs.INITIATOR_HANDLE] == self_handle assert emitted_props[cs.INITIATOR_ID] == 'test@localhost' assertContains('text/plain', emitted_props[cs.SUPPORTED_CONTENT_TYPES]) assertEquals(0, emitted_props[cs.MESSAGE_PART_SUPPORT_FLAGS]) assertEquals(cs.DELIVERY_REPORTING_SUPPORT_FLAGS_RECEIVE_FAILURES, emitted_props[cs.DELIVERY_REPORTING_SUPPORT]) assert old_sig.args[0] == ret.value[0] assert old_sig.args[1] == cs.CHANNEL_TYPE_TEXT assert old_sig.args[2] == cs.HT_CONTACT assert old_sig.args[3] == foo_handle assert old_sig.args[4] == True # suppress handler assert len(new_sig.args) == 1 assert len(new_sig.args[0]) == 1 # one channel assert len(new_sig.args[0][0]) == 2 # two struct members assert new_sig.args[0][0][0] == ret.value[0] assert new_sig.args[0][0][1] == ret.value[1] properties = conn.GetAll( cs.CONN_IFACE_REQUESTS, dbus_interface=dbus.PROPERTIES_IFACE) assert new_sig.args[0][0] in properties['Channels'], \ (new_sig.args[0][0], properties['Channels'])
def test(q, bus, conn, stream): conn.Connect() q.expect('dbus-signal', signal='StatusChanged', args=[0, 1]) self_handle = conn.Get(cs.CONN, 'SelfHandle', dbus_interface=cs.PROPERTIES_IFACE) self_uri = conn.inspect_contact_sync(self_handle) uri = 'sip:[email protected]' foo_handle = conn.get_contact_handle_sync(uri) properties = conn.GetAll(cs.CONN_IFACE_REQUESTS, dbus_interface=cs.PROPERTIES_IFACE) assertEquals([], properties.get('Channels')) assertContains(({ cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT }, [cs.TARGET_HANDLE, cs.TARGET_ID]), properties['RequestableChannelClasses']) requestotron = dbus.Interface(conn, cs.CONN_IFACE_REQUESTS) call_async( q, requestotron, 'CreateChannel', { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT, cs.TARGET_HANDLE: foo_handle }) ret, new_sig = q.expect_many( EventPattern('dbus-return', method='CreateChannel'), EventPattern('dbus-signal', signal='NewChannels'), ) assert len(ret.value) == 2 emitted_props = ret.value[1] assertEquals(cs.CHANNEL_TYPE_TEXT, emitted_props[cs.CHANNEL_TYPE]) assertEquals(cs.HT_CONTACT, emitted_props[cs.TARGET_HANDLE_TYPE]) assertEquals(foo_handle, emitted_props[cs.TARGET_HANDLE]) assertEquals(uri, emitted_props[cs.TARGET_ID]) assertEquals(True, emitted_props[cs.REQUESTED]) assertEquals(self_handle, emitted_props[cs.INITIATOR_HANDLE]) assertEquals(self_uri, emitted_props[cs.INITIATOR_ID]) assert len(new_sig.args) == 1 assert len(new_sig.args[0]) == 1 # one channel assert len(new_sig.args[0][0]) == 2 # two struct members assert new_sig.args[0][0][0] == ret.value[0] assert new_sig.args[0][0][1] == ret.value[1] properties = conn.GetAll(cs.CONN_IFACE_REQUESTS, dbus_interface=cs.PROPERTIES_IFACE) assert new_sig.args[0][0] in properties['Channels'], \ (new_sig.args[0][0], properties['Channels']) conn.Disconnect() q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
def test(q, bus, conn, stream, access_control): iq_event = q.expect('stream-iq', to=None, query_ns='vcard-temp', query_name='vCard') acknowledge_iq(stream, iq_event.stanza) # check if we can request muc D-Bus tube t.check_conn_properties(q, conn) self_handle = conn.Properties.Get(cs.CONN, "SelfHandle") self_name = conn.inspect_contact_sync(self_handle) # offer a D-Bus tube to another room using new API muc = '*****@*****.**' request = { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_DBUS_TUBE, cs.TARGET_HANDLE_TYPE: cs.HT_ROOM, cs.TARGET_ID: '*****@*****.**', cs.DBUS_TUBE_SERVICE_NAME: 'com.example.TestCase', } join_muc(q, bus, conn, stream, muc, request=request) e = q.expect('dbus-signal', signal='NewChannels') channels = e.args[0] assert len(channels) == 1 path, prop = channels[0] assert prop[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_DBUS_TUBE assert prop[cs.INITIATOR_ID] == '[email protected]/test' assert prop[cs.REQUESTED] == True assert prop[cs.TARGET_HANDLE_TYPE] == cs.HT_ROOM assert prop[cs.TARGET_ID] == '*****@*****.**' assert prop[cs.DBUS_TUBE_SERVICE_NAME] == 'com.example.TestCase' assert prop[cs.DBUS_TUBE_SUPPORTED_ACCESS_CONTROLS] == [ cs.SOCKET_ACCESS_CONTROL_CREDENTIALS, cs.SOCKET_ACCESS_CONTROL_LOCALHOST ] # check that the tube channel is in the channels list all_channels = conn.Get(cs.CONN_IFACE_REQUESTS, 'Channels', dbus_interface=cs.PROPERTIES_IFACE, byte_arrays=True) assertContains((path, prop), all_channels) tube_chan = wrap_channel(bus.get_object(conn.bus_name, path), 'DBusTube') tube_props = tube_chan.Properties.GetAll(cs.CHANNEL_IFACE_TUBE, byte_arrays=True) assert tube_props['State'] == cs.TUBE_CHANNEL_STATE_NOT_OFFERED # try to offer using a wrong access control try: tube_chan.DBusTube.Offer(sample_parameters, cs.SOCKET_ACCESS_CONTROL_PORT) except dbus.DBusException, e: assertEquals(e.get_dbus_name(), cs.INVALID_ARGUMENT)
def test_contact_blocking(q, bus, conn, stream, stored, deny): """test ContactBlocking API""" assertContains(cs.CONN_IFACE_CONTACT_BLOCKING, conn.Properties.Get(cs.CONN, "Interfaces")) # 3 contacts are blocked blocked = conn.RequestBlockedContacts(dbus_interface=cs.CONN_IFACE_CONTACT_BLOCKING) assertLength(3, blocked)
def test_contact_blocking(q, bus, conn, stream): """test ContactBlocking API""" assertContains(cs.CONN_IFACE_CONTACT_BLOCKING, conn.Properties.Get(cs.CONN, "Interfaces")) # 3 contacts are blocked blocked = conn.RequestBlockedContacts(dbus_interface=cs.CONN_IFACE_CONTACT_BLOCKING) assertLength(3, blocked)
def test(q, bus, conn, stream): self_handle = conn.Properties.Get(cs.CONN, "SelfHandle") jid = '*****@*****.**' foo_handle = conn.get_contact_handle_sync(jid) properties = conn.GetAll(cs.CONN_IFACE_REQUESTS, dbus_interface=dbus.PROPERTIES_IFACE) # Difference from Gabble: Haze's roster channels spring to life even if you # haven't received the XMPP roster. text_channels = [ c for c in properties.get('Channels') if c[1][cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_TEXT ] assert text_channels == [], text_channels assert ({cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT, }, [cs.TARGET_HANDLE, cs.TARGET_ID], ) in properties.get('RequestableChannelClasses'),\ properties['RequestableChannelClasses'] call_async( q, conn.Requests, 'CreateChannel', { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT, cs.TARGET_HANDLE: foo_handle, }) ret, sig = q.expect_many( EventPattern('dbus-return', method='CreateChannel'), EventPattern('dbus-signal', signal='NewChannels'), ) assert len(ret.value) == 2 emitted_props = ret.value[1] assertEquals(cs.CHANNEL_TYPE_TEXT, emitted_props[cs.CHANNEL_TYPE]) assertEquals(cs.HT_CONTACT, emitted_props[cs.TARGET_HANDLE_TYPE]) assertEquals(foo_handle, emitted_props[cs.TARGET_HANDLE]) assertEquals(jid, emitted_props[cs.TARGET_ID]) assertEquals(True, emitted_props[cs.REQUESTED]) assertEquals(self_handle, emitted_props[cs.INITIATOR_HANDLE]) assertEquals('test@localhost', emitted_props[cs.INITIATOR_ID]) assertLength(1, sig.args) assertLength(1, sig.args[0]) # one channel assertLength(2, sig.args[0][0]) # two struct members assertEquals(ret.value[0], sig.args[0][0][0]) assertEquals(ret.value[1], sig.args[0][0][1]) properties = conn.GetAll(cs.CONN_IFACE_REQUESTS, dbus_interface=dbus.PROPERTIES_IFACE) assertContains(sig.args[0][0], properties['Channels']) conn.Disconnect() q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
def test(q, bus, conn, stream): statuses = conn.Properties.Get(cs.CONN_IFACE_SIMPLE_PRESENCE, 'Statuses') # testbusy and testaway are provided by test plugin assertContains('testbusy', statuses) assertContains('testaway', statuses) assertEquals(statuses['testbusy'][0], cs.PRESENCE_BUSY) assertEquals(statuses['testaway'][0], cs.PRESENCE_AWAY) conn.SimplePresence.SetPresence('testbusy', '') conn.Connect() # ... gabble asks for all the available lists on the server ... stream.handle_get_all_privacy_lists( q, bus, conn, lists=["foo-list", "test-busy-list", "bar-list"]) # ... gabble checks whether there's usable invisible list on the server ... get_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='get') list_node = xpath.queryForNodes('//list', get_list.query)[0] assertEquals('invisible', list_node['name']) error = domish.Element((None, 'error')) error['type'] = 'cancel' error.addElement((ns.STANZA, 'item-not-found')) send_error_reply(stream, get_list.stanza, error) # ... since there is none, Gabble creates it ... create_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set') list_node = xpath.queryForNodes('//list', create_list.query)[0] assertEquals('invisible', list_node['name']) assertNotEquals([], xpath.queryForNodes('/query/list/item/presence-out', create_list.query)) acknowledge_iq(stream, create_list.stanza) get_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set') list_node = xpath.queryForNodes('//active', get_list.query)[0] # ... and then activates the one linked with the requested status # Note: testbusy status is linked to test-busy-list by test plugin assertEquals('test-busy-list', list_node['name']) acknowledge_iq(stream, get_list.stanza) q.expect('dbus-signal', signal='PresencesChanged', args=[{ 1: (cs.PRESENCE_BUSY, u'testbusy', '') }]) q.expect('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]) # ... testaway is not supposed to be settable on us call_async(q, conn.SimplePresence, 'SetPresence', 'testaway', '') q.expect('dbus-error', method='SetPresence', name=cs.INVALID_ARGUMENT)
def test_deny_unblock_remove(q, bus, conn, stream): """ Test unblocking a contact, and, while that request is pending, deleting them. """ # This contact was on our roster, blocked and subscribed, when we started. contact = '*****@*****.**' handle = conn.get_contact_handle_sync(contact) check_contact_roster(conn, contact, [], cs.SUBSCRIPTION_STATE_YES, cs.SUBSCRIPTION_STATE_YES) # They're blocked, and we have a bidi subscription, so they should be on # deny and stored. (We already checked this earlier, but we've been messing # with the roster so let's be sure the preconditions are okay...) assertContains(handle, conn.ContactBlocking.RequestBlockedContacts().keys()) # Unblock them. call_async(q, conn.ContactBlocking, 'UnblockContacts', [handle]) roster_event = q.expect('stream-iq', query_ns=ns.ROSTER) item = roster_event.query.firstChildElement() assertEquals(contact, item['jid']) assertDoesNotContain((ns.GOOGLE_ROSTER, 't'), item.attributes) # If we now remove them from stored, the edit shouldn't be sent until the # unblock event has had a reply. q.forbid_events(remove_events) call_async(q, conn.ContactList, 'RemoveContacts', [handle]) # Make sure if the remove is sent prematurely, we catch it. sync_stream(q, stream) q.unforbid_events(remove_events) # So now we send a roster push and reply for the unblock request. stream.send(make_set_roster_iq(stream, 'test@localhost/Resource', contact, 'both', False, attrs={})) acknowledge_iq(stream, roster_event.stanza) # And on receiving the push and reply, Gabble should show them being # removed from deny, and send a remove. _, roster_event = q.expect_many( EventPattern('dbus-signal', signal='BlockedContactsChanged', predicate=lambda e: blocked_contacts_changed_predicate(e, [], [contact])), remove_events[0], ) item = roster_event.query.firstChildElement() assertEquals(contact, item['jid']) stream.send(make_set_roster_iq(stream, 'test@localhost/Resource', contact, 'remove', False, attrs={})) acknowledge_iq(stream, roster_event.stanza)
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))
def test(q, bus, conn, stream): self_handle = conn.Properties.Get(cs.CONN, "SelfHandle") jid = '*****@*****.**' foo_handle = conn.get_contact_handle_sync(jid) properties = conn.GetAll(cs.CONN_IFACE_REQUESTS, dbus_interface=dbus.PROPERTIES_IFACE) # Difference from Gabble: Haze's roster channels spring to life even if you # haven't received the XMPP roster. text_channels = [c for c in properties.get('Channels') if c[1][cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_TEXT ] assert text_channels == [], text_channels assert ({cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT, }, [cs.TARGET_HANDLE, cs.TARGET_ID], ) in properties.get('RequestableChannelClasses'),\ properties['RequestableChannelClasses'] call_async(q, conn.Requests, 'CreateChannel', { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT, cs.TARGET_HANDLE: foo_handle, }) ret, sig = q.expect_many( EventPattern('dbus-return', method='CreateChannel'), EventPattern('dbus-signal', signal='NewChannels'), ) assert len(ret.value) == 2 emitted_props = ret.value[1] assertEquals(cs.CHANNEL_TYPE_TEXT, emitted_props[cs.CHANNEL_TYPE]) assertEquals(cs.HT_CONTACT, emitted_props[cs.TARGET_HANDLE_TYPE]) assertEquals(foo_handle, emitted_props[cs.TARGET_HANDLE]) assertEquals(jid, emitted_props[cs.TARGET_ID]) assertEquals(True, emitted_props[cs.REQUESTED]) assertEquals(self_handle, emitted_props[cs.INITIATOR_HANDLE]) assertEquals('test@localhost', emitted_props[cs.INITIATOR_ID]) assertLength(1, sig.args) assertLength(1, sig.args[0]) # one channel assertLength(2, sig.args[0][0]) # two struct members assertEquals(ret.value[0], sig.args[0][0][0]) assertEquals(ret.value[1], sig.args[0][0][1]) properties = conn.GetAll(cs.CONN_IFACE_REQUESTS, dbus_interface=dbus.PROPERTIES_IFACE) assertContains(sig.args[0][0], properties['Channels']) conn.Disconnect() q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
def test(q, bus, conn, stream): rccs = conn.Properties.Get(cs.CONN_IFACE_REQUESTS, 'RequestableChannelClasses') # These values are from plugins/test.c fixed = { cs.CHANNEL_TYPE: "com.jonnylamb.lolbags", cs.TARGET_HANDLE_TYPE: cs.HT_NONE, } allowed = ["com.jonnylamb.omg", "com.jonnylamb.brokethebuild"] assertContains((fixed, allowed), rccs)
def badger(event): assertEquals(chan.object_path, event.path) message, = event.args header = message[0] assertContains('scrollback', header) assert header['scrollback'] assertContains('message-sender', header) return header['message-sender']
def test(q, bus, conn, server): cm = bus.get_object(cs.CM + '.idle', tp_path_prefix + '/ConnectionManager/idle') cm_iface = dbus.Interface(cm, cs.CM) cm_prop_iface = dbus.Interface(cm, cs.PROPERTIES_IFACE) protocols = unwrap(cm_prop_iface.Get(cs.CM, 'Protocols')) assertEquals(set(['irc']), set(protocols.keys())) protocol_names = unwrap(cm_iface.ListProtocols()) assertEquals(set(['irc']), set(protocol_names)) cm_params = cm_iface.GetParameters('irc') local_props = protocols['irc'] local_params = local_props[cs.PROTOCOL + '.Parameters'] assertEquals(cm_params, local_params) proto = bus.get_object(cm.bus_name, cm.object_path + '/irc') proto_iface = dbus.Interface(proto, cs.PROTOCOL) proto_prop_iface = dbus.Interface(proto, cs.PROPERTIES_IFACE) proto_props = unwrap(proto_prop_iface.GetAll(cs.PROTOCOL)) for key in [ 'Parameters', 'Interfaces', 'ConnectionInterfaces', 'RequestableChannelClasses', 'VCardField', 'EnglishName', 'Icon' ]: a = local_props[cs.PROTOCOL + '.' + key] b = proto_props[key] assertEquals(a, b) assertEquals('x-irc', proto_props['VCardField']) assertEquals('IRC', proto_props['EnglishName']) assertEquals('im-irc', proto_props['Icon']) assertContains(cs.CONN_IFACE_ALIASING, proto_props['ConnectionInterfaces']) assertContains(cs.CONN_IFACE_REQUESTS, proto_props['ConnectionInterfaces']) assertEquals('robot101', unwrap(proto_iface.NormalizeContact('Robot101'))) call_async(q, proto_iface, 'IdentifyAccount', {'account': 'Robot101'}) q.expect('dbus-error', method='IdentifyAccount', name=cs.INVALID_ARGUMENT) test_params = {'account': 'Robot101', 'server': 'irc.oftc.net'} acc_name = unwrap(proto_iface.IdentifyAccount(test_params)) assertEquals('*****@*****.**', acc_name) # Test validating 'username' test_params = { 'account': 'Robot101', 'server': 'irc.oftc.net', 'username': '******', } call_async(q, proto_iface, 'IdentifyAccount', test_params) q.expect('dbus-error', method='IdentifyAccount', name=cs.INVALID_ARGUMENT)
def test_caps(q, conn, stream, contact, features, audio, video, google=False): caps['ver'] = compute_caps_hash ([], features, {}) h = presence_and_disco(q, conn, stream, contact, True, client, caps, features) cflags = 0 stream_expected_media_caps = [] call_expected_media_caps = [] if audio: cflags |= cs.MEDIA_CAP_AUDIO stream_expected_media_caps.append (cs.INITIAL_AUDIO) call_expected_media_caps.append (cs.CALL_INITIAL_AUDIO) call_expected_media_caps.append (cs.CALL_INITIAL_AUDIO_NAME) if video: cflags |= cs.MEDIA_CAP_VIDEO stream_expected_media_caps.append (cs.INITIAL_VIDEO) call_expected_media_caps.append (cs.CALL_INITIAL_VIDEO) call_expected_media_caps.append (cs.CALL_INITIAL_VIDEO_NAME) # If the contact can only do one of audio or video, or uses a Google # client, they'll have the ImmutableStreams cap. if cflags < (cs.MEDIA_CAP_AUDIO | cs.MEDIA_CAP_VIDEO) or google: cflags |= cs.MEDIA_CAP_IMMUTABLE_STREAMS stream_expected_media_caps.append(cs.IMMUTABLE_STREAMS) else: call_expected_media_caps.append(cs.CALL_MUTABLE_CONTENTS) _, event = q.expect_many( EventPattern('dbus-signal', signal='CapabilitiesChanged', args = [[ ( h, cs.CHANNEL_TYPE_STREAMED_MEDIA, 0, # old generic 3, # new generic (can create and receive these) 0, # old specific cflags ) ]] # new specific ), EventPattern('dbus-signal', signal='ContactCapabilitiesChanged') ) assertContains((h, cs.CHANNEL_TYPE_STREAMED_MEDIA, 3, cflags), conn.Capabilities.GetCapabilities([h])) # Check Contact capabilities for streamed media assertEquals(len(event.args), 1) assertEquals (event.args[0], conn.ContactCapabilities.GetContactCapabilities([h])) check_contact_caps (event.args[0][h], cs.CHANNEL_TYPE_STREAMED_MEDIA, stream_expected_media_caps) check_contact_caps (event.args[0][h], cs.CHANNEL_TYPE_CALL, call_expected_media_caps)
def test(q, bus, conn, stream): conn.Connect() q.expect('dbus-signal', signal='StatusChanged', args=[0, 1]) self_handle = conn.Get(cs.CONN, 'SelfHandle', dbus_interface=cs.PROPERTIES_IFACE) self_uri = conn.inspect_contact_sync(self_handle) uri = 'sip:[email protected]' foo_handle = conn.get_contact_handle_sync(uri) properties = conn.GetAll(cs.CONN_IFACE_REQUESTS, dbus_interface=cs.PROPERTIES_IFACE) assertEquals([], properties.get('Channels')) assertContains( ({ cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT }, [ cs.TARGET_HANDLE, cs.TARGET_ID ]), properties['RequestableChannelClasses']) requestotron = dbus.Interface(conn, cs.CONN_IFACE_REQUESTS) call_async(q, requestotron, 'CreateChannel', { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT, cs.TARGET_HANDLE: foo_handle }) ret, new_sig = q.expect_many( EventPattern('dbus-return', method='CreateChannel'), EventPattern('dbus-signal', signal='NewChannels'), ) assert len(ret.value) == 2 emitted_props = ret.value[1] assertEquals(cs.CHANNEL_TYPE_TEXT, emitted_props[cs.CHANNEL_TYPE]) assertEquals(cs.HT_CONTACT, emitted_props[cs.TARGET_HANDLE_TYPE]) assertEquals(foo_handle, emitted_props[cs.TARGET_HANDLE]) assertEquals(uri, emitted_props[cs.TARGET_ID]) assertEquals(True, emitted_props[cs.REQUESTED]) assertEquals(self_handle, emitted_props[cs.INITIATOR_HANDLE]) assertEquals(self_uri, emitted_props[cs.INITIATOR_ID]) assert len(new_sig.args) == 1 assert len(new_sig.args[0]) == 1 # one channel assert len(new_sig.args[0][0]) == 2 # two struct members assert new_sig.args[0][0][0] == ret.value[0] assert new_sig.args[0][0][1] == ret.value[1] properties = conn.GetAll(cs.CONN_IFACE_REQUESTS, dbus_interface=cs.PROPERTIES_IFACE) assert new_sig.args[0][0] in properties['Channels'], \ (new_sig.args[0][0], properties['Channels']) conn.Disconnect() q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
def test(q, bus, conn, stream): def send_own_message(to, text): iq = elem_iq(stream, 'set', from_='chat.facebook.com')(elem(NS_FACEBOOK_MESSAGES, 'own-message', to=to, self='false')( elem('body')(text))) stream.send(iq) q.expect('stream-iq', iq_type='result', iq_id=iq['id']) # First, test receiving an own-message stanza for a message sent to a # contact we have an open channel for. jid = '*****@*****.**' _, path, props = conn.Requests.EnsureChannel({ cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT, cs.TARGET_ID: jid, }) channel = wrap_channel(bus.get_object(conn.bus_name, path), 'Text', ['Messages']) handle = props[cs.TARGET_HANDLE] text = u'omg omg its ur birthdayy <3 <3 xoxoxoxo' send_own_message(to=jid, text=text) e = q.expect('dbus-signal', signal='MessageReceived') message, = e.args assertLength(1, message) header = message[0] assertEquals(handle, header['message-sender']) assertEquals(cs.MT_DELIVERY_REPORT, header['message-type']) assertEquals(cs.DELIVERY_STATUS_ACCEPTED, header['delivery-status']) assertContains('delivery-echo', header) echo = header['delivery-echo'] echo_header, echo_body = echo assertEquals(conn.Properties.Get(cs.CONN, "SelfHandle"), echo_header['message-sender']) assertEquals('text/plain', echo_body['content-type']) assertEquals(text, echo_body['content']) channel.Text.AcknowledgePendingMessages([header['pending-message-id']]) channel.Close() # Now test receiving an own-message stanza for a message sent to a contact # we don't have a channel open for. It should be ignored (but acked). This # is consistent with delivery failure reports. q.forbid_events([EventPattern('dbus-signal', signal='MessageReceived')]) send_own_message(to='*****@*****.**', text=u'please ignore this message') sync_dbus(bus, q, conn)
def test(q, bus, conn, server): cm = bus.get_object(cs.CM + '.idle', tp_path_prefix + '/ConnectionManager/idle') cm_iface = dbus.Interface(cm, cs.CM) cm_prop_iface = dbus.Interface(cm, cs.PROPERTIES_IFACE) protocols = unwrap(cm_prop_iface.Get(cs.CM, 'Protocols')) assertEquals(set(['irc']), set(protocols.keys())) protocol_names = unwrap(cm_iface.ListProtocols()) assertEquals(set(['irc']), set(protocol_names)) cm_params = cm_iface.GetParameters('irc') local_props = protocols['irc'] local_params = local_props[cs.PROTOCOL + '.Parameters'] assertEquals(cm_params, local_params) proto = bus.get_object(cm.bus_name, cm.object_path + '/irc') proto_iface = dbus.Interface(proto, cs.PROTOCOL) proto_prop_iface = dbus.Interface(proto, cs.PROPERTIES_IFACE) proto_props = unwrap(proto_prop_iface.GetAll(cs.PROTOCOL)) for key in ['Parameters', 'Interfaces', 'ConnectionInterfaces', 'RequestableChannelClasses', u'VCardField', u'EnglishName', u'Icon']: a = local_props[cs.PROTOCOL + '.' + key] b = proto_props[key] assertEquals(a, b) assertEquals('x-irc', proto_props['VCardField']) assertEquals('IRC', proto_props['EnglishName']) assertEquals('im-irc', proto_props['Icon']) assertContains(cs.CONN_IFACE_ALIASING, proto_props['ConnectionInterfaces']) assertContains(cs.CONN_IFACE_REQUESTS, proto_props['ConnectionInterfaces']) assertEquals('robot101', unwrap(proto_iface.NormalizeContact('Robot101'))) call_async(q, proto_iface, 'IdentifyAccount', {'account': 'Robot101'}) q.expect('dbus-error', method='IdentifyAccount', name=cs.INVALID_ARGUMENT) test_params = {'account': 'Robot101', 'server': 'irc.oftc.net' } acc_name = unwrap(proto_iface.IdentifyAccount(test_params)) assertEquals('*****@*****.**', acc_name) # Test validating 'username' test_params = { 'account': 'Robot101', 'server': 'irc.oftc.net', 'username': '******', } call_async(q, proto_iface, 'IdentifyAccount', test_params) q.expect('dbus-error', method='IdentifyAccount', name=cs.INVALID_ARGUMENT)
def test(q, bus, conn, stream): conn.Connect() q.expect('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_CONNECTING, cs.CSR_REQUESTED]) e = q.expect('dbus-signal', signal='ConnectionError') error, details = e.args assertEquals(cs.CONNECTION_FAILED, error) assertContains('debug-message', details) q.expect('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_DISCONNECTED, cs.CSR_NETWORK_ERROR])
def check_caps(namespaces, desired): """Assert that all the FIXED_CAPS are supported, and of the VARIABLE_CAPS, every capability in desired is supported, and every other capability is not. """ for c in FIXED_CAPS: assertContains(c, namespaces) for c in VARIABLE_CAPS: if c in desired: assertContains(c, namespaces) else: assertDoesNotContain(c, namespaces)
def test(q, bus, conn, stream): def send_own_message(to, text): iq = elem_iq(stream, 'set', from_='chat.facebook.com')( elem(NS_FACEBOOK_MESSAGES, 'own-message', to=to, self='false')( elem('body')(text) ) ) stream.send(iq) q.expect('stream-iq', iq_type='result', iq_id=iq['id']) # First, test receiving an own-message stanza for a message sent to a # contact we have an open channel for. jid = '*****@*****.**' _, path, props = conn.Requests.EnsureChannel({ cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT, cs.TARGET_ID: jid, }) channel = wrap_channel(bus.get_object(conn.bus_name, path), 'Text', ['Messages']) handle = props[cs.TARGET_HANDLE] text = u'omg omg its ur birthdayy <3 <3 xoxoxoxo' send_own_message(to=jid, text=text) e = q.expect('dbus-signal', signal='MessageReceived') message, = e.args assertLength(1, message) header = message[0] assertEquals(handle, header['message-sender']) assertEquals(cs.MT_DELIVERY_REPORT, header['message-type']) assertEquals(cs.DELIVERY_STATUS_ACCEPTED, header['delivery-status']) assertContains('delivery-echo', header) echo = header['delivery-echo'] echo_header, echo_body = echo assertEquals(conn.GetSelfHandle(), echo_header['message-sender']) assertEquals('text/plain', echo_body['content-type']) assertEquals(text, echo_body['content']) channel.Text.AcknowledgePendingMessages([header['pending-message-id']]) channel.Close() # Now test receiving an own-message stanza for a message sent to a contact # we don't have a channel open for. It should be ignored (but acked). This # is consistent with delivery failure reports. q.forbid_events([EventPattern('dbus-signal', signal='MessageReceived')]) send_own_message(to='*****@*****.**', text=u'please ignore this message') sync_dbus(bus, q, conn)
def test_invisible_fails(q, bus, conn, stream): assertContains("hidden", conn.Properties.Get(cs.CONN_IFACE_SIMPLE_PRESENCE, "Statuses")) conn.SimplePresence.SetPresence("hidden", "") # First we send an <invisible/> command. event = q.expect('stream-iq', query_name='invisible') send_error_reply(stream, event.stanza) # When that fails, we should expect our status to change to dnd. q.expect('dbus-signal', signal='PresencesChanged', interface=cs.CONN_IFACE_SIMPLE_PRESENCE, args=[{1: (6, 'dnd', '')}])
def check_contact_info(info, txt): first = txt.get('1st', '') last = txt.get('last', '') if first != '' or last != '': values = [last, first, '', '', ''] assertContains(('n', [], values), info) fn = ' '.join([x for x in [first, last] if x != '']) assertContains(('fn', [], [fn]), info) else: assertOmitsField('n', info) assertOmitsField('fn', info) email = txt.get('email', '') if email != '': assertContains(('email', ['type=internet'], [email]), info) else: assertOmitsField('email', info) jid = txt.get('jid', '') if jid != '': assertContains(('x-jabber', [], [jid]), info) else: assertOmitsField('x-jabber', info)
def advertise_caps(q, bus, conn, service, filters, expected_features, unexpected_features, expected_caps): # make sure nothing from a previous update is still running sync_dbus(bus, q, conn) self_handle = conn.Properties.Get(cs.CONN, "SelfHandle") self_handle_name = conn.Properties.Get(cs.CONN, "SelfID") ret_caps = conn.ContactCapabilities.UpdateCapabilities([ (cs.CLIENT + '.Foo', filters, []) ]) presence, event_dbus = q.expect_many( EventPattern('service-resolved', service=service), EventPattern('dbus-signal', signal='ContactCapabilitiesChanged')) assertLength(1, event_dbus.args) signaled_caps = event_dbus.args[0] outbound = connect_to_stream(q, 'test@foobar', self_handle_name, str(presence.pt), presence.port) e = q.expect('connection-result') assert e.succeeded, e.reason e = q.expect('stream-opened', connection=outbound) # Expect Salut to reply with the correct caps event, namespaces = disco_caps(q, outbound, presence.txt) assertSameElements(expected_caps, signaled_caps[self_handle]) assertContains(ns.TP_FT_METADATA, namespaces) for var in expected_features: assertContains(var, namespaces) for var in unexpected_features: assertDoesNotContain(var, namespaces) # check the Contacts interface give the same caps caps_via_contacts_iface = conn.Contacts.GetContactAttributes( [self_handle], [cs.CONN_IFACE_CONTACT_CAPS], False) \ [self_handle][cs.ATTR_CONTACT_CAPABILITIES] assertSameElements(expected_caps, caps_via_contacts_iface) # close things... outbound.send('</stream:stream>') sync_dbus(bus, q, conn) outbound.transport.loseConnection()
def test_disconnect(q, bus, conn, stream): assertContains( cs.CONN_IFACE_POWER_SAVING, conn.Get(cs.CONN, "Interfaces", dbus_interface=cs.PROPERTIES_IFACE)) assertEquals( False, conn.Get(cs.CONN_IFACE_POWER_SAVING, "PowerSavingActive", dbus_interface=cs.PROPERTIES_IFACE)) call_async(q, conn.PowerSaving, 'SetPowerSaving', True) stanza = expect_command(q, 'enable') disconnect_conn(q, conn, stream)
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