def run_cancel_test(q, bus, conn, stream): jp = JingleProtocol031 () jt = JingleTest2(jp, conn, q, stream, 'test@localhost', muc + '/bob') jt.prepare() for x in xrange (0, 10): (path, props) = create_muji_channel (q, conn, stream, muc, x > 0) channel = bus.get_object (conn.bus_name, path) contents = channel.Get (cs.CHANNEL_TYPE_CALL, "Contents", dbus_interface = dbus.PROPERTIES_IFACE) content = bus.get_object (conn.bus_name, contents[0]) md = jt.get_call_audio_md_dbus() check_and_accept_offer (q, bus, conn, content, md) # Accept the channel channel.Accept() e = q.expect('stream-presence', to = muc + "/test") mujinode = xpath.queryForNodes("/presence/muji/preparing", e.stanza) assertNotEquals(None, mujinode) channel.Hangup(0, "", "", dbus_interface=cs.CHANNEL_TYPE_CALL) e = q.expect('stream-presence', to = muc + "/test") mujinode = xpath.queryForNodes("/presence/muji/preparing", e.stanza) assertEquals(None, mujinode) if x % 2 == 0: channel.Close()
def test(q, bus, conn, stream): conn.Connect() q.expect('dbus-signal', signal='StatusChanged', args=[0, 1]) CHANNEL_NAME = '#idletest' call_async(q, conn.Requests, 'CreateChannel', { CHANNEL_TYPE: CHANNEL_TYPE_TEXT, TARGET_HANDLE_TYPE: HT_ROOM, TARGET_ID: CHANNEL_NAME }) ret = q.expect('dbus-return', method='CreateChannel') q.expect('dbus-signal', signal='MembersChanged') chan = bus.get_object(conn.bus_name, ret.value[0]) text_chan = dbus.Interface(chan, CHANNEL_TYPE_TEXT) # send a whole bunch of messages in a row and make sure they get delivered # in the proper order NUM_MESSAGES = 4 for i in range(NUM_MESSAGES): call_async(q, text_chan, 'Send', 0, str(i)) for i in range(NUM_MESSAGES): message = q.expect('stream-PRIVMSG') assertEquals([CHANNEL_NAME, str(i)], message.data) call_async(q, conn, 'Disconnect')
def send_presence(q, conn, stream, contact, caps, initial=True, show=None): h = conn.RequestHandles(cs.HT_CONTACT, [contact])[0] if initial: stream.send(make_presence(contact, status='hello')) q.expect_many( EventPattern('dbus-signal', signal='PresenceUpdate', args=[{ h: (0L, { u'available': { 'message': 'hello' } }) }]), EventPattern('dbus-signal', signal='PresencesChanged', args=[{ h: (2, u'available', 'hello') }])) # no special capabilities assertEquals([(h, cs.CHANNEL_TYPE_TEXT, 3, 0)], conn.Capabilities.GetCapabilities([h])) # send updated presence with caps info stream.send(make_presence(contact, show=show, status='hello', caps=caps)) return h
def disco_caps(q, stream, presence): c_nodes = xpath.queryForNodes('/presence/c', presence.stanza) assert c_nodes is not None assertLength(1, c_nodes) hash = c_nodes[0].attributes['hash'] ver = c_nodes[0].attributes['ver'] node = c_nodes[0].attributes['node'] assertEquals('sha-1', hash) # ask caps request = \ elem_iq(stream, 'get', from_='[email protected]/resource')( elem(ns.DISCO_INFO, 'query', node=(node + '#' + ver)) ) stream.send(request) # receive caps event = q.expect('stream-iq', query_ns=ns.DISCO_INFO, iq_id=request['id']) # Check that Gabble's announcing the identity we think it should be. (identities, features, dataforms) = extract_disco_parts(event.stanza) # Check if the hash matches the announced capabilities assertEquals(compute_caps_hash(identities, features, dataforms), ver) return (event, features, dataforms)
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 _cb_disco_iq(self, iq): nodes = xpath.queryForNodes("/iq/query", iq) query = nodes[0] if query.getAttribute('node') is None: return node = query.attributes['node'] ver = node.replace("http://telepathy.freedesktop.org/caps#", "") if iq.getAttribute('type') == 'result': if FileTransferTest.caps_identities is None or \ FileTransferTest.caps_features is None: identity_nodes = xpath.queryForNodes('/iq/query/identity', iq) assertLength(1, identity_nodes) identity_node = identity_nodes[0] identity_category = identity_node['category'] identity_type = identity_node['type'] identity_name = identity_node['name'] identity = '%s/%s//%s' % (identity_category, identity_type, identity_name) FileTransferTest.caps_identities = [identity] FileTransferTest.caps_features = [] for feature in xpath.queryForNodes('/iq/query/feature', iq): FileTransferTest.caps_features.append(feature['var']) # Check if the hash matches the announced capabilities assertEquals(compute_caps_hash(FileTransferTest.caps_identities, FileTransferTest.caps_features, {}), ver) if ver == FileTransferTest.caps_ft: caps_share = compute_caps_hash(FileTransferTest.caps_identities, FileTransferTest.caps_features + \ [ns.GOOGLE_FEAT_SHARE], {}) n = query.attributes['node'].replace(ver, caps_share) query.attributes['node'] = n for feature in xpath.queryForNodes('/iq/query/feature', iq): query.children.remove(feature) for f in FileTransferTest.caps_features + [ns.GOOGLE_FEAT_SHARE]: el = domish.Element((None, 'feature')) el['var'] = f query.addChild(el) elif iq.getAttribute('type') == 'get': caps_share = compute_caps_hash(FileTransferTest.caps_identities, FileTransferTest.caps_features + \ [ns.GOOGLE_FEAT_SHARE], {}) if ver == caps_share: n = query.attributes['node'].replace(ver, FileTransferTest.caps_ft) query.attributes['node'] = n
def test_new_channel(q, bus, conn, target_uri, initiator_uri, requested): event = q.expect('dbus-signal', signal='NewChannels') path, props = event.args[0][0] assertEquals(cs.CHANNEL_TYPE_TEXT, props[cs.CHANNEL_TYPE]) assertEquals(cs.HT_CONTACT, props[cs.TARGET_HANDLE_TYPE]) handle = props[cs.TARGET_HANDLE] obj = bus.get_object(conn._named_service, path) initiator_handle = conn.get_contact_handle_sync(initiator_uri) text_props = obj.GetAll(cs.CHANNEL, dbus_interface='org.freedesktop.DBus.Properties') assert text_props['ChannelType'] == cs.CHANNEL_TYPE_TEXT, text_props assert 'Interfaces' in text_props, text_props assertSameSets((cs.CHANNEL_IFACE_MESSAGES, cs.CHANNEL_IFACE_DESTROYABLE), text_props['Interfaces']) assert 'TargetHandle' in text_props, text_props assert text_props['TargetHandle'] == handle, \ (text_props, handle) assert 'TargetHandleType' in text_props, text_props assert text_props['TargetHandleType'] == 1, text_props assert text_props['TargetID'] == target_uri, text_props assert text_props['InitiatorHandle'] == initiator_handle, \ (text_props, initiator_handle) assert text_props['InitiatorID'] == initiator_uri, \ (text_props, initiator_uri) assert 'Requested' in text_props, text_props assert text_props['Requested'] == requested, text_props return obj, handle
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 accept(self): if self.incoming: self.chan.Call1.SetQueued() o = self.q.expect_many( EventPattern('sip-response', call_id=self.context.call_id, code=182), EventPattern('dbus-signal', signal='CallStateChanged')) assertEquals(cs.CALL_STATE_INITIALISED, o[1].args[0]) assertEquals(cs.CALL_FLAG_LOCALLY_QUEUED, o[1].args[1]) self.chan.Call1.SetRinging() o = self.q.expect_many( EventPattern('sip-response', call_id=self.context.call_id, code=180), EventPattern('dbus-signal', signal='CallStateChanged')) assertEquals(cs.CALL_STATE_INITIALISED, o[1].args[0]) assertEquals(cs.CALL_FLAG_LOCALLY_RINGING, o[1].args[1]) else: # Send Ringing self.context.pr_respond(self.invite_event, 180) o = self.q.expect('dbus-signal', signal='CallMembersChanged') assertEquals(cs.CALL_MEMBER_FLAG_RINGING, o.args[0][self.remote_handle]) return calltest.CallTest.accept(self)
def tube_then_text(q, bus, conn): jid = 'test-muc' connect(q, bus, conn) # first let's get a stream tube tube_chan, _, _ = stream_tube(q, bus, conn, 'CreateChannel', jid) # now let's try and ensure the text channel which should happen # immediately request_text_channel(q, bus, conn, 'EnsureChannel', jid) ret = q.expect('dbus-return', method='EnsureChannel') yours, text_path, text_props = ret.value assertEquals(True, yours) assertEquals(cs.CHANNEL_TYPE_TEXT, text_props[cs.CHANNEL_TYPE]) new_sig = q.expect('dbus-signal', signal='NewChannels') channels = new_sig.args[0] assertEquals(1, len(channels)) path, props = channels[0] assertEquals(text_path, path) assertEquals(text_props, props)
def test_with_message(q, stream, parts): invalid_utf8 = WELL_FORMED_BUT_INVALID_UTF8_BYTES.join(parts) # Idle's default character set is UTF-8. We send it a message which is # basically UTF-8, except that one of its code points is invalid. stream.sendMessage('PRIVMSG', stream.nick, ':%s' % invalid_utf8, prefix='remoteuser') # Idle should signal that *something* was received. If it hasn't validated # & sanitized the message properly, the dbus-daemon will kick it off. signal = q.expect('dbus-signal', signal='MessageReceived') message_parts = signal.args[0] text_plain = message_parts[1] content = text_plain['content'] # Don't make any assumption about how many U+FFFD REPLACEMENT CHARACTERs # are used to replace surprising bytes. received_parts = [ part for part in re.split("\ufffd|\\?", content) if part != '' ] if parts[0] == 'björk': # The valid UTF-8 gets lost in transit, because we fall back # to assuming ASCII when g_convert() fails (this didn't happen # when we tested with noncharacters - oh well). assertEquals(['bj', 'rk', 'bj', 'rk', 'bj', 'rk'], received_parts) else: assertEquals([s for s in parts if s != ''], received_parts)
def check_room_props(chan, subject_str, actor): # Room props props = chan.GetAll(cs.CHANNEL_IFACE_ROOM, dbus_interface=dbus.PROPERTIES_IFACE) subject = props['Subject'] assertEquals(subject_str, subject[0]) assertEquals(actor, subject[1])
def test_channel_reference_identity_with_extra(q, bus, conn, stream): props = connect_and_get_tls_properties(q, bus, conn) reference_identities = props["ReferenceIdentities"] assertSameSets(reference_identities, ["example.org", "hypnotoad.example.org", "localhost"]) assertEquals(props["Hostname"], "example.org")
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 run_test(q, bus, conn, stream, jt, decloak_allowed): """ Requests streams on a media channel to jt.remote_jid without having their presence at all. """ call_async(q, conn.Requests, 'CreateChannel', { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_CALL, cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT, cs.TARGET_ID: jt.peer, cs.CALL_INITIAL_AUDIO: True, cs.CALL_INITIAL_VIDEO: False, }) e = q.expect('stream-presence', to=jt.peer_bare_jid, presence_type=None) nodes = [ node for node in e.stanza.elements(uri=ns.TEMPPRES, name='temppres') ] assertLength(1, nodes) assertEquals('media', nodes[0].getAttribute('reason')) if decloak_allowed: jt.send_presence_and_caps() # RequestStreams should now happily complete q.expect('dbus-return', method='CreateChannel') else: q.expect('dbus-error', method='CreateChannel', name=cs.OFFLINE)
def test(q, bus, conn): # last value of the "ver" key we resolved. We use it to be sure that the # modified caps has already be announced. old_ver = None conn.Connect() q.expect('dbus-signal', signal='StatusChanged', args=[0, 0]) self_handle = conn.Properties.Get(cs.CONN, "SelfHandle") self_handle_name = conn.Properties.Get(cs.CONN, "SelfID") AvahiListener(q).listen_for_service("_presence._tcp") e = q.expect('service-added', name = self_handle_name, protocol = avahi.PROTO_INET) service = e.service service.resolve() e = q.expect('service-resolved', service = service) ver = txt_get_key(e.txt, "ver") while ver == old_ver: # be sure that the announced caps actually changes e = q.expect('service-resolved', service=service) ver = txt_get_key(e.txt, "ver") old_ver = ver caps = compute_caps_hash(['client/pc//%s' % PACKAGE_STRING], fixed_features, {}) assertEquals(caps, ver) test_ft_caps_from_contact(q, bus, conn, service, 'yo@momma') test_ft_caps_to_contact(q, bus, conn, service)
def test_create_invisible_list_failed(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)) send_error_reply(stream, create_list.stanza) q.expect('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]) assertDoesNotContain( "hidden", conn.Properties.Get(cs.CONN_IFACE_SIMPLE_PRESENCE, "Statuses"))
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_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 call_expected_media_caps = [] if audio: cflags |= cs.MEDIA_CAP_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 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 else: call_expected_media_caps.append(cs.CALL_MUTABLE_CONTENTS) event, = q.expect_many( EventPattern('dbus-signal', signal='ContactCapabilitiesChanged')) # Check Contact capabilities assertEquals(len(event.args), 1) assertEquals(event.args[0], get_contacts_capabilities_sync(conn, [h])) check_contact_caps(event.args[0][h], cs.CHANNEL_TYPE_CALL, call_expected_media_caps)
def test_plain_no_account(q, bus, conn, stream): chan, props = connect_and_get_sasl_channel(q, bus, conn) assertEquals('example.com', props.get(cs.SASL_DEFAULT_REALM)) assertEquals('', props.get(cs.SASL_DEFAULT_USERNAME)) 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.success(None) q.expect('dbus-signal', signal='SASLStatusChanged', interface=cs.CHANNEL_IFACE_SASL_AUTH, args=[cs.SASL_STATUS_SERVER_SUCCEEDED, '', {}]) chan.SASLAuthentication.AcceptSASL() q.expect('dbus-signal', signal='SASLStatusChanged', interface=cs.CHANNEL_IFACE_SASL_AUTH, args=[cs.SASL_STATUS_SUCCEEDED, '', {}]) e = q.expect('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])
def test_shared_status_list(q, bus, conn, stream): '''Test the shared status list usage''' test_statuses = { "dnd": [ 'I am not available now', 'I am busy with real work', 'I have a life, you know...', 'I am actually playing Duke Nukem', 'It is important to me' ], "available": [ 'I am twiddling my thumbs', 'Please chat me up', 'I am here for you', 'Message me already!' ] } max_statuses = int(stream.max_statuses) q.expect_many( EventPattern('stream-iq', query_ns=ns.GOOGLE_SHARED_STATUS, iq_type='get'), EventPattern('stream-iq', query_ns=ns.GOOGLE_SHARED_STATUS, iq_type='set'), EventPattern('stream-presence')) for show, statuses in test_statuses.items(): shared_show, _ = _show_to_shared_status_show(show) expected_list = stream.shared_status_lists[shared_show] for status in statuses: _test_local_status(q, conn, stream, status, show) expected_list = [status] + expected_list[:max_statuses - 1] assertEquals(expected_list, stream.shared_status_lists[shared_show])
def test(q, bus, conn, stream): event = q.expect('stream-iq', query_ns=ns.ROSTER) amy_handle = conn.get_contact_handle_sync('*****@*****.**') event.stanza['type'] = 'result' item = event.query.addElement('item') item['jid'] = '*****@*****.**' item['subscription'] = 'both' stream.send(event.stanza) stream.send(make_presence('*****@*****.**', show='away', status='At the pub')) q.expect('dbus-signal', signal='PresencesChanged', args=[{amy_handle: (cs.PRESENCE_AWAY, 'away', 'At the pub')}]) stream.send(make_presence( '*****@*****.**', show='chat', status='I may have been drinking')) e = q.expect('dbus-signal', signal='PresencesChanged', args=[{amy_handle: (cs.PRESENCE_AVAILABLE, 'chat', 'I may have been drinking')}]) amy_handle, asv = conn.Contacts.GetContactByID('*****@*****.**', [cs.CONN_IFACE_SIMPLE_PRESENCE]) assertEquals(e.args[0][amy_handle], asv.get(cs.ATTR_PRESENCE)) bob_handle, asv = conn.Contacts.GetContactByID('*****@*****.**', [cs.CONN_IFACE_SIMPLE_PRESENCE]) assertEquals((cs.PRESENCE_UNKNOWN, 'unknown', ''), asv.get(cs.ATTR_PRESENCE))
def check_and_accept_offer (q, bus, conn, content, md, in_remote_handle = 0, offer_path = None, md_changed = True): [path, remote_md] = content.Get(cs.CALL_CONTENT_IFACE_MEDIA, "MediaDescriptionOffer", dbus_interface=dbus.PROPERTIES_IFACE) remote_handle = remote_md[cs.CALL_CONTENT_MEDIADESCRIPTION + '.RemoteContact'] if in_remote_handle != 0: assertEquals(remote_handle, in_remote_handle) if offer_path != None: assertEquals (offer_path, path) assertNotEquals ("/", path) offer = bus.get_object (conn.bus_name, path) codecmap_property = offer.Get (cs.CALL_CONTENT_MEDIADESCRIPTION, "Codecs", dbus_interface=dbus.PROPERTIES_IFACE) assertEquals (remote_md[cs.CALL_CONTENT_MEDIADESCRIPTION + '.Codecs'], codecmap_property) offer.Accept (md, dbus_interface=cs.CALL_CONTENT_MEDIADESCRIPTION) current_md = content.Get(cs.CALL_CONTENT_IFACE_MEDIA, "LocalMediaDescriptions", dbus_interface=dbus.PROPERTIES_IFACE) assertEquals (md, current_md[remote_handle]) if md_changed: o = q.expect ('dbus-signal', signal='LocalMediaDescriptionChanged') assertEquals ([md], o.args)
def _check_oob_iq(self, iq_event): assert iq_event.iq_type == 'set' assert iq_event.connection == self.incoming self.iq = iq_event.stanza assert self.iq['to'] == self.contact_name query = self.iq.firstChildElement() assert query.uri == 'jabber:iq:oob' url_node = xpath.queryForNodes("/iq/query/url", self.iq)[0] assert url_node['type'] == 'file' assert url_node['size'] == str(self.file.size) assert url_node['mimeType'] == self.file.content_type self.url = url_node.children[0] _, self.host, self.filename, _, _, _ = urlparse.urlparse(self.url) urllib.unquote(self.filename) == self.file.name desc_node = xpath.queryForNodes("/iq/query/desc", self.iq)[0] self.desc = desc_node.children[0] assert self.desc == self.file.description # Metadata forms forms = extract_data_forms(xpath.queryForNodes('/iq/query/x', self.iq)) if self.service_name: assertEquals({'ServiceName': [self.service_name]}, forms[ns.TP_FT_METADATA_SERVICE]) else: assert ns.TP_FT_METADATA_SERVICE not in forms if self.metadata: assertEquals(self.metadata, forms[ns.TP_FT_METADATA]) else: assert ns.TP_FT_METADATA not in forms
def test(q, bus, conn, stream): # Request a sidecar thate we support before we're connected; it should just # wait around until we're connected. call_async(q, conn.Sidecars1, 'EnsureSidecar', PLUGIN_IFACE) conn.Connect() q.expect('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]) # Now we're connected, the call we made earlier should return. path, props = q.expect('dbus-return', method='EnsureSidecar').value # This sidecar doesn't even implement get_immutable_properties; it # should just get the empty dict filled in for it. assertEquals({}, props) gateways_iface = dbus.Interface(bus.get_object(conn.bus_name, path), PLUGIN_IFACE) test_success(q, gateways_iface, stream) test_conflict(q, gateways_iface, stream) test_not_acceptable(q, gateways_iface, stream) call_async(q, conn, 'Disconnect') q.expect_many( EventPattern('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_DISCONNECTED, cs.CSR_REQUESTED]), EventPattern('stream-closed'), ) stream.sendFooter() q.expect('dbus-return', method='Disconnect')
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())
def test(q, bus, conn, stream): conn.Connect() q.expect('dbus-signal', signal='StatusChanged', args=[0, 1]) CHANNEL_NAME = '#idletest' call_async( q, conn.Requests, 'CreateChannel', { CHANNEL_TYPE: CHANNEL_TYPE_TEXT, TARGET_HANDLE_TYPE: HT_ROOM, TARGET_ID: CHANNEL_NAME }) ret = q.expect('dbus-return', method='CreateChannel') q.expect('dbus-signal', signal='MembersChanged') chan = bus.get_object(conn.bus_name, ret.value[0]) text_chan = dbus.Interface(chan, CHANNEL_TYPE_TEXT) # send a whole bunch of messages in a row and make sure they get delivered # in the proper order NUM_MESSAGES = 4 for i in range(NUM_MESSAGES): call_async(q, text_chan, 'Send', 0, str(i)) for i in range(NUM_MESSAGES): message = q.expect('stream-PRIVMSG') assertEquals([CHANNEL_NAME, str(i)], message.data) call_async(q, conn, 'Disconnect')
def test_props_present(q, bus, conn, stream): chan = setup(q, bus, conn, stream) props = chan.Properties.GetAll(cs.CHANNEL_IFACE_ROOM_CONFIG) assertContains('PasswordProtected', props) assertContains('Password', props) assertContains('Description', props) assertContains('Title', props) assertContains('ConfigurationRetrieved', props) assertContains('Persistent', props) assertContains('Private', props) assertContains('Limit', props) assertContains('Anonymous', props) assertContains('CanUpdateConfiguration', props) assertContains('PasswordHint', props) assertContains('Moderated', props) assertContains('InviteOnly', props) assertContains('MutableProperties', props) # this should do nothing forbidden = [EventPattern('dbus-signal', signal='PropertiesChanged')] q.forbid_events(forbidden) call_async(q, chan.RoomConfig1, 'UpdateConfiguration', {}) sync_stream(q, stream) q.unforbid_events(forbidden) # we should have these mutable ones mutable_props = ['InviteOnly', 'Limit', 'Moderated', 'Private', 'PasswordProtected', 'Password'] assertEquals(mutable_props, props['MutableProperties'])
def check_normal_props(props): assertEquals(cs.CONTACT_INFO_FLAG_CAN_SET, props['ContactInfoFlags']) sf = props['SupportedFields'] sf.sort() for f in sf: f[1].sort() # type-parameters assertEquals([ ('adr', types('home work postal parcel dom intl pref'), 0, UNLIMITED), ('bday', [], PARAMS_EXACT, UNLIMITED), ('email', types('home work internet pref x400'), 0, UNLIMITED), ('fn', [], PARAMS_EXACT, 1), ('geo', [], PARAMS_EXACT, 1), ('label', types('home work postal parcel dom intl pref'), 0, UNLIMITED), ('mailer', [], PARAMS_EXACT, UNLIMITED), ('n', [], PARAMS_EXACT, 1), ('nickname', [], PARAMS_EXACT | OVERWRITTEN_BY_NICKNAME, UNLIMITED), ('note', [], PARAMS_EXACT, UNLIMITED), ('org', [], PARAMS_EXACT, UNLIMITED), ('prodid', [], PARAMS_EXACT, UNLIMITED), ('rev', [], PARAMS_EXACT, UNLIMITED), ('role', [], PARAMS_EXACT, UNLIMITED), ('sort-string', [], PARAMS_EXACT, UNLIMITED), ('tel', types('home work voice fax pager msg cell video bbs ' 'modem isdn pcs pref'), 0, UNLIMITED), ('title', [], PARAMS_EXACT, UNLIMITED), ('tz', [], PARAMS_EXACT, UNLIMITED), ('uid', [], PARAMS_EXACT, UNLIMITED), ('url', [], PARAMS_EXACT, UNLIMITED), ('x-desc', [], PARAMS_EXACT, UNLIMITED), ('x-jabber', [], PARAMS_EXACT, UNLIMITED), ], sf)
def test(q, bus, conn, stream): jp = JingleProtocol031() remote_jid = '[email protected]/misc' 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.Requests.CreateChannel({ cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_STREAMED_MEDIA, cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT, cs.TARGET_HANDLE: remote_handle}) chan = wrap_channel(bus.get_object(conn.bus_name, path), 'StreamedMedia') # In Gabble, the StreamedMedia channel is secretly also the SessionHandler. # Let's make up a proxy and call some methods on it. They should fail # gracefully, rather than crashing Gabble. session_handler = make_channel_proxy(conn, path, 'Media.SessionHandler') try: session_handler.Ready() except DBusException, e: assertEquals(cs.NOT_AVAILABLE, e.get_dbus_name())
def test(q, bus, conn): # last value of the "ver" key we resolved. We use it to be sure that the # modified caps has already be announced. old_ver = None conn.Connect() q.expect('dbus-signal', signal='StatusChanged', args=[0, 0]) self_handle = conn.Properties.Get(cs.CONN, "SelfHandle") self_handle_name = conn.Properties.Get(cs.CONN, "SelfID") AvahiListener(q).listen_for_service("_presence._tcp") e = q.expect('service-added', name=self_handle_name, protocol=avahi.PROTO_INET) service = e.service service.resolve() e = q.expect('service-resolved', service=service) ver = txt_get_key(e.txt, "ver") while ver == old_ver: # be sure that the announced caps actually changes e = q.expect('service-resolved', service=service) ver = txt_get_key(e.txt, "ver") old_ver = ver caps = compute_caps_hash(['client/pc//%s' % PACKAGE_STRING], fixed_features, {}) assertEquals(caps, ver) test_ft_caps_from_contact(q, bus, conn, service, 'yo@momma') test_ft_caps_to_contact(q, bus, conn, service)
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_invisible_on_connect(q, bus, conn, stream): props = conn.Properties.GetAll(cs.CONN_IFACE_SIMPLE_PRESENCE) assertNotEquals({}, props['Statuses']) presence_event_pattern = EventPattern('stream-presence') q.forbid_events([presence_event_pattern]) conn.SimplePresence.SetPresence("hidden", "") conn.Connect() stream.handle_get_all_privacy_lists(q, bus, conn, ['invisible']) 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']) stream.send_privacy_list( get_list.stanza, [elem('item', action='deny', order='1')(elem('presence-out'))]) set_active = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set') active = xpath.queryForNodes('//active', set_active.query)[0] assertEquals('invisible', active['name']) acknowledge_iq(stream, set_active.stanza) q.unforbid_events([presence_event_pattern]) q.expect('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])
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_invisible_on_connect_fail_no_list(q, bus, conn, stream): props = conn.Properties.GetAll(cs.CONN_IFACE_SIMPLE_PRESENCE) assertNotEquals({}, props['Statuses']) presence_event_pattern = EventPattern('stream-presence') q.forbid_events([presence_event_pattern]) conn.SimplePresence.SetPresence("hidden", "") 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']) send_error_reply(stream, get_list.stanza) q.unforbid_events([presence_event_pattern]) # Darn! At least we should have our presence set to DND. q.expect_many( EventPattern('dbus-signal', signal='PresencesChanged', interface=cs.CONN_IFACE_SIMPLE_PRESENCE, args=[{1: (6, 'dnd', '')}]), EventPattern('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])) # 'hidden' should not be an available status. assertDoesNotContain("hidden", conn.Properties.Get(cs.CONN_IFACE_SIMPLE_PRESENCE, "Statuses"))
def test_invisible_on_connect(q, bus, conn, stream): props = conn.Properties.GetAll(cs.CONN_IFACE_SIMPLE_PRESENCE) assertNotEquals({}, props['Statuses']) presence_event_pattern = EventPattern('stream-presence') q.forbid_events([presence_event_pattern]) conn.SimplePresence.SetPresence("hidden", "") conn.Connect() stream.handle_get_all_privacy_lists(q, bus, conn, ['invisible']) 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']) stream.send_privacy_list(get_list.stanza, [elem('item', action='deny', order='1')(elem('presence-out'))]) set_active = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set') active = xpath.queryForNodes('//active', set_active.query)[0] assertEquals('invisible', active['name']) acknowledge_iq(stream, set_active.stanza) q.unforbid_events([presence_event_pattern]) q.expect('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])
def test_privacy_list_push_conflict(q, bus, conn, stream): test_invisible_on_connect(q, bus, conn, stream) set_id = stream.send_privacy_list_push_iq("invisible") _, req_list = q.expect_many( EventPattern('stream-iq', iq_type='result', iq_id=set_id), EventPattern('stream-iq', query_ns=ns.PRIVACY, iq_type="get")) stream.send_privacy_list(req_list.stanza, [ elem('item', type='jid', value='*****@*****.**', action='allow', order='1')(elem('presence-out')), elem('item', action='deny', order='2')(elem('presence-out')) ]) create_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set') created = xpath.queryForNodes('//list', create_list.stanza)[0] assertEquals(created["name"], 'invisible-gabble') acknowledge_iq(stream, create_list.stanza) set_active = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set') active = xpath.queryForNodes('//active', set_active.query)[0] assertEquals('invisible-gabble', active['name']) acknowledge_iq(stream, set_active.stanza)
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 test_invisible_on_connect_fail(q, bus, conn, stream): props = conn.Properties.GetAll(cs.CONN_IFACE_SIMPLE_PRESENCE) assertNotEquals({}, props['Statuses']) presence_event_pattern = EventPattern('stream-presence') q.forbid_events([presence_event_pattern]) conn.SimplePresence.SetPresence("hidden", "") conn.Connect() stream.handle_get_all_privacy_lists(q, bus, conn) create_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set') # Check its name assertNotEquals([], xpath.queryForNodes('/query/list/item/presence-out', create_list.query)) acknowledge_iq(stream, create_list.stanza) set_active = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set') active = xpath.queryForNodes('//active', set_active.query)[0] assertEquals('invisible', active['name']) send_error_reply(stream, set_active.stanza) q.unforbid_events([presence_event_pattern]) # Darn! At least we should have our presence set to DND. q.expect_many( EventPattern('dbus-signal', signal='PresencesChanged', interface=cs.CONN_IFACE_SIMPLE_PRESENCE, args=[{1: (6, 'dnd', '')}]), EventPattern('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]))
def test(q, bus, conn, stream): # Request a sidecar thate we support before we're connected; it should just # wait around until we're connected. call_async(q, conn.Future, 'EnsureSidecar', PLUGIN_IFACE) conn.Connect() q.expect('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED]) # Now we're connected, the call we made earlier should return. path, props = q.expect('dbus-return', method='EnsureSidecar').value # This sidecar doesn't even implement get_immutable_properties; it # should just get the empty dict filled in for it. assertEquals({}, props) gateways_iface = dbus.Interface(bus.get_object(conn.bus_name, path), PLUGIN_IFACE) test_success(q, gateways_iface, stream) test_conflict(q, gateways_iface, stream) test_not_acceptable(q, gateways_iface, stream) call_async(q, conn, 'Disconnect') q.expect_many( EventPattern('dbus-signal', signal='StatusChanged', args=[cs.CONN_STATUS_DISCONNECTED, cs.CSR_REQUESTED]), EventPattern('stream-closed'), ) stream.sendFooter() q.expect('dbus-return', method='Disconnect')
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_shared_status_list(q, bus, conn, stream): '''Test the shared status list usage''' test_statuses = {"dnd" : ['I am not available now', 'I am busy with real work', 'I have a life, you know...', 'I am actually playing Duke Nukem', 'It is important to me'], "available" : ['I am twiddling my thumbs', 'Please chat me up', 'I am here for you', 'Message me already!']} max_statuses = int(stream.max_statuses) q.expect_many(EventPattern('stream-iq', query_ns=ns.GOOGLE_SHARED_STATUS, iq_type='get'), EventPattern('stream-iq', query_ns=ns.GOOGLE_SHARED_STATUS, iq_type='set'), EventPattern('stream-presence')) for show, statuses in test_statuses.items(): shared_show, _ = _show_to_shared_status_show(show) expected_list = stream.shared_status_lists[shared_show] for status in statuses: _test_local_status(q, conn, stream, status, show) expected_list = [status] + expected_list[:max_statuses - 1] assertEquals(expected_list, stream.shared_status_lists[shared_show])
def contact_online(q, conn, stream, contact, identities, disco=True, dataforms={}, initial=True, show=None): (caps, client, types) = build_stuff(identities) handle = conn.get_contact_handle_sync(contact) # make contact come online presence_and_disco(q, conn, stream, contact, disco, client, caps, features, identities, dataforms=dataforms, initial=initial, show=show) if initial: event = q.expect('dbus-signal', signal='ClientTypesUpdated') assertEquals([handle, types], event.args)
def test_privacy_list_push_conflict(q, bus, conn, stream): test_invisible_on_connect(q, bus, conn, stream) set_id = stream.send_privacy_list_push_iq("invisible") _, req_list = q.expect_many( EventPattern('stream-iq', iq_type='result', predicate=lambda event: \ event.stanza['id'] == set_id), EventPattern('stream-iq', query_ns=ns.PRIVACY, iq_type="get")) stream.send_privacy_list(req_list.stanza, [elem('item', type='jid', value='*****@*****.**', action='allow', order='1')(elem('presence-out')), elem('item', action='deny', order='2')(elem('presence-out'))]) create_list = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set') created = xpath.queryForNodes('//list', create_list.stanza)[0] assertEquals(created["name"], 'invisible-gabble') acknowledge_iq(stream, create_list.stanza) set_active = q.expect('stream-iq', query_ns=ns.PRIVACY, iq_type='set') active = xpath.queryForNodes('//active', set_active.query)[0] assertEquals('invisible-gabble', active['name']) acknowledge_iq(stream, set_active.stanza)
def test_channel_reference_identity_with_extra_multiple(q, bus, conn, stream): props = connect_and_get_tls_properties (q, bus, conn) reference_identities = props["ReferenceIdentities"] assertSameSets(reference_identities, [ "example.org", "hypnotoad.example.org", "localhost", "other.local" ]) assertEquals(props["Hostname"], "example.org")
def make_call(expected_recipient): jp = JingleProtocol031() jt = JingleTest2(jp, conn, q, stream, 'test@localhost', 'dummy') conn.Requests.CreateChannel({ cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_STREAMED_MEDIA, cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT, cs.TARGET_ID: cat, cs.INITIAL_AUDIO: True, }) e = q.expect('dbus-signal', signal='NewSessionHandler') session = make_channel_proxy(conn, e.args[0], 'Media.SessionHandler') session.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')) assertEquals(expected_recipient, e.to)
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 handle_muc_owner_set_iq(stream, stanza, fields): form = parse_form(stanza) # Check that Gabble echoed back the fields it didn't understand (or want to # change) with their previous values. expected_form = get_default_form() expected_form.update(fields) assertEquals(expected_form, form) acknowledge_iq(stream, stanza)
def check_contact_caps (caps, channel_type, expected_media_caps): [media_caps] = [ c for c in caps if c[0][cs.CHANNEL_TYPE] == channel_type ] assertEquals (expected_media_caps, media_caps[1])
def test(q, bus, conn, stream): jid = '*****@*****.**' iq = elem_iq(stream, 'get', from_=jid)(elem(ns.DISCO_INFO, 'query')) stream.send(iq) event = q.expect('stream-iq', iq_type='result', to='*****@*****.**') assertEquals(iq['id'], event.stanza['id'])