1
# Copyright (C) 2009 Nokia Corporation
2
# Copyright (C) 2009 Collabora Ltd.
4
# This library is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU Lesser General Public
6
# License as published by the Free Software Foundation; either
7
# version 2.1 of the License, or (at your option) any later version.
9
# This library is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public
15
# License along with this library; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
"""Regression test for plugins rejecting an incoming channel immediately.
26
from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \
28
from mctest import exec_test, SimulatedConnection, SimulatedClient, \
29
create_fakecm_account, enable_fakecm_account, SimulatedChannel, \
31
import constants as cs
34
params = dbus.Dictionary({"account": "someguy@example.com",
35
"password": "secrecy"}, signature='sv')
36
cm_name_ref, account = create_fakecm_account(q, bus, mc, params)
37
conn = enable_fakecm_account(q, bus, mc, account, params)
39
text_fixed_properties = dbus.Dictionary({
40
cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT,
41
cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_TEXT,
44
# Throughout this entire test, we should never be asked to approve or
47
EventPattern('dbus-method-call', method='AddDispatchOperation'),
48
EventPattern('dbus-method-call', method='HandleChannels'),
50
q.forbid_events(forbidden)
52
# Two clients want to observe, approve and handle channels
53
empathy = SimulatedClient(q, bus, 'Empathy',
54
observe=[text_fixed_properties], approve=[text_fixed_properties],
55
handle=[text_fixed_properties], bypass_approval=False)
56
kopete = SimulatedClient(q, bus, 'Kopete',
57
observe=[text_fixed_properties], approve=[text_fixed_properties],
58
handle=[text_fixed_properties], bypass_approval=False)
60
# wait for MC to download the properties
61
expect_client_setup(q, [empathy, kopete])
63
# subscribe to the OperationList interface (MC assumes that until this
64
# property has been retrieved once, nobody cares)
66
cd = bus.get_object(cs.CD, cs.CD_PATH)
67
cd_props = dbus.Interface(cd, cs.PROPERTIES_IFACE)
68
assert cd_props.Get(cs.CD_IFACE_OP_LIST, 'DispatchOperations') == []
70
# This ID is special-cased by the mcp-plugin plugin, which rejects
71
# channels to or from it by destroying them, without waiting for observers
73
target = 'rick.astley@example.net'
74
channel_properties = dbus.Dictionary(text_fixed_properties,
76
channel_properties[cs.CHANNEL + '.TargetID'] = target
77
channel_properties[cs.CHANNEL + '.TargetHandle'] = \
78
conn.ensure_handle(cs.HT_CONTACT, target)
79
channel_properties[cs.CHANNEL + '.InitiatorID'] = target
80
channel_properties[cs.CHANNEL + '.InitiatorHandle'] = \
81
conn.ensure_handle(cs.HT_CONTACT, target)
82
channel_properties[cs.CHANNEL + '.Requested'] = False
83
channel_properties[cs.CHANNEL + '.Interfaces'] = \
84
dbus.Array([cs.CHANNEL_IFACE_DESTROYABLE, cs.CHANNEL_IFACE_GROUP,
87
chan = SimulatedChannel(conn, channel_properties, group=True)
90
# A channel dispatch operation is created
92
e = q.expect('dbus-signal',
94
interface=cs.CD_IFACE_OP_LIST,
95
signal='NewDispatchOperation')
98
cdo_properties = e.args[1]
100
assert cdo_properties[cs.CDO + '.Account'] == account.object_path
101
assert cdo_properties[cs.CDO + '.Connection'] == conn.object_path
102
assert cs.CDO + '.Interfaces' in cdo_properties
104
handlers = cdo_properties[cs.CDO + '.PossibleHandlers'][:]
106
assert handlers == [cs.tp_name_prefix + '.Client.Empathy',
107
cs.tp_name_prefix + '.Client.Kopete'], handlers
109
# The plugin realises we've been rickrolled, and responds. It calls Destroy
110
# even though neither Empathy nor Kopete has returned from ObserveChannels
112
destruction, e, k = q.expect_many(
113
EventPattern('dbus-method-call',
114
path=chan.object_path,
115
interface=cs.CHANNEL_IFACE_DESTROYABLE, method='Destroy',
116
args=[], handled=False),
117
EventPattern('dbus-method-call',
118
path=empathy.object_path,
119
interface=cs.OBSERVER, method='ObserveChannels',
121
EventPattern('dbus-method-call',
122
path=kopete.object_path,
123
interface=cs.OBSERVER, method='ObserveChannels',
126
# treat the destruction like Close
127
chan.Close(destruction)
129
# Both Observers indicate that they are ready to proceed (somewhat late)
130
q.dbus_return(k.message, signature='')
131
q.dbus_return(e.message, signature='')
133
# When the Observers have returned, the CDO finishes
135
EventPattern('dbus-signal', path=cdo_path,
136
interface=cs.CDO, signal='Finished'),
137
EventPattern('dbus-signal', path=cs.CD_PATH,
138
interface=cs.CD_IFACE_OP_LIST,
139
signal='DispatchOperationFinished',
143
# This ID is also special-cased
144
target = 'mc.hammer@example.net'
145
channel_properties = dbus.Dictionary(text_fixed_properties,
147
channel_properties[cs.CHANNEL + '.TargetID'] = target
148
channel_properties[cs.CHANNEL + '.TargetHandle'] = \
149
conn.ensure_handle(cs.HT_CONTACT, target)
150
channel_properties[cs.CHANNEL + '.InitiatorID'] = target
151
channel_properties[cs.CHANNEL + '.InitiatorHandle'] = \
152
conn.ensure_handle(cs.HT_CONTACT, target)
153
channel_properties[cs.CHANNEL + '.Requested'] = False
154
channel_properties[cs.CHANNEL + '.Interfaces'] = \
155
dbus.Array([cs.CHANNEL_IFACE_DESTROYABLE, cs.CHANNEL_IFACE_GROUP,
158
chan = SimulatedChannel(conn, channel_properties, group=True)
161
# A channel dispatch operation is created
163
e = q.expect('dbus-signal',
165
interface=cs.CD_IFACE_OP_LIST,
166
signal='NewDispatchOperation')
169
cdo_properties = e.args[1]
171
assert cdo_properties[cs.CDO + '.Account'] == account.object_path
172
assert cdo_properties[cs.CDO + '.Connection'] == conn.object_path
173
assert cs.CDO + '.Interfaces' in cdo_properties
175
handlers = cdo_properties[cs.CDO + '.PossibleHandlers'][:]
177
assert handlers == [cs.tp_name_prefix + '.Client.Empathy',
178
cs.tp_name_prefix + '.Client.Kopete'], handlers
180
# The plugin realises it's MC Hammer, and responds, but its response waits
181
# for the observers to return
182
e, k = q.expect_many(
183
EventPattern('dbus-method-call',
184
path=empathy.object_path,
185
interface=cs.OBSERVER, method='ObserveChannels',
187
EventPattern('dbus-method-call',
188
path=kopete.object_path,
189
interface=cs.OBSERVER, method='ObserveChannels',
193
sync_dbus(bus, q, account)
195
# Both Observers indicate that they are ready to proceed
196
q.dbus_return(k.message, signature='')
197
q.dbus_return(e.message, signature='')
199
_, _, e = q.expect_many(
200
EventPattern('dbus-signal', path=cdo_path,
201
interface=cs.CDO, signal='Finished'),
202
EventPattern('dbus-signal', path=cs.CD_PATH,
203
interface=cs.CD_IFACE_OP_LIST,
204
signal='DispatchOperationFinished',
206
EventPattern('dbus-method-call',
207
path=chan.object_path,
208
interface=cs.CHANNEL_IFACE_GROUP,
209
method='RemoveMembersWithReason', args=[[conn.self_handle],
210
"Can't touch this", cs.GROUP_REASON_PERMISSION_DENIED],
213
q.dbus_return(e.message, signature='')
216
if __name__ == '__main__':