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 dispatching a requested Text channel, with a plugin that
21
delays dispatching and asks for permission.
27
from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \
29
from mctest import exec_test, SimulatedConnection, SimulatedClient, \
30
create_fakecm_account, enable_fakecm_account, SimulatedChannel, \
32
import constants as cs
34
text_fixed_properties = dbus.Dictionary({
35
cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT,
36
cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_TEXT,
39
def request_channel_expect_query(q, bus, account, conn, client):
40
# This target is special-cased in test-plugin.c
41
target = 'policy@example.com'
42
request_properties = dbus.Dictionary(text_fixed_properties,
44
request_properties[cs.CHANNEL + '.TargetID'] = target
46
cd = bus.get_object(cs.CD, cs.CD_PATH)
48
user_action_time = dbus.Int64(1238582606)
50
call_async(q, cd, 'CreateChannel',
51
account.object_path, request_properties, user_action_time,
52
client.bus_name, dbus_interface=cs.CD)
53
ret = q.expect('dbus-return', method='CreateChannel')
54
request_path = ret.value[0]
56
cr = bus.get_object(cs.AM, request_path)
57
cr.Proceed(dbus_interface=cs.CR)
59
cm_request_call = q.expect('dbus-method-call',
60
interface=cs.CONN_IFACE_REQUESTS, method='CreateChannel',
61
path=conn.object_path, args=[request_properties], handled=False)
63
# A channel is returned eventually
65
channel_properties = dbus.Dictionary(text_fixed_properties,
67
channel_properties[cs.CHANNEL + '.TargetID'] = target
68
channel_properties[cs.CHANNEL + '.TargetHandle'] = \
69
conn.ensure_handle(cs.HT_CONTACT, target)
70
channel_properties[cs.CHANNEL + '.InitiatorID'] = conn.self_ident
71
channel_properties[cs.CHANNEL + '.InitiatorHandle'] = conn.self_handle
72
channel_properties[cs.CHANNEL + '.Requested'] = True
73
channel_properties[cs.CHANNEL + '.Interfaces'] = \
74
dbus.Array([cs.CHANNEL_IFACE_GROUP,
77
chan = SimulatedChannel(conn, channel_properties, group=True)
78
q.dbus_return(cm_request_call.message,
79
chan.object_path, chan.immutable, signature='oa{sv}')
82
# What does the policy service think?
83
e = q.expect('dbus-method-call', path='/com/example/Policy',
84
interface='com.example.Policy', method='RequestPermission')
86
# Think about it for a bit
87
sync_dbus(bus, q, account)
89
# Let the test code decide how to reply
93
params = dbus.Dictionary({"account": "someguy@example.com",
94
"password": "secrecy"}, signature='sv')
95
cm_name_ref, account = create_fakecm_account(q, bus, mc, params)
96
conn = enable_fakecm_account(q, bus, mc, account, params)
98
policy_bus_name_ref = dbus.service.BusName('com.example.Policy', bus)
100
# Two clients want to observe, approve and handle channels
101
empathy = SimulatedClient(q, bus, 'Empathy',
102
observe=[text_fixed_properties], approve=[text_fixed_properties],
103
handle=[text_fixed_properties], bypass_approval=False)
104
kopete = SimulatedClient(q, bus, 'Kopete',
105
observe=[text_fixed_properties], approve=[text_fixed_properties],
106
handle=[text_fixed_properties], bypass_approval=False)
108
# wait for MC to download the properties
109
expect_client_setup(q, [empathy, kopete])
111
# subscribe to the OperationList interface (MC assumes that until this
112
# property has been retrieved once, nobody cares)
114
cd = bus.get_object(cs.CD, cs.CD_PATH)
115
cd_props = dbus.Interface(cd, cs.PROPERTIES_IFACE)
116
assert cd_props.Get(cs.CD_IFACE_OP_LIST, 'DispatchOperations') == []
118
e, chan, cr = request_channel_expect_query(q, bus, account, conn, empathy)
121
q.dbus_raise(e.message, 'com.example.Errors.No', 'Denied!')
123
# The plugin responds
124
e = q.expect('dbus-method-call',
125
path=chan.object_path,
126
interface=cs.CHANNEL_IFACE_GROUP,
127
# this error message is from the plugin
128
method='RemoveMembersWithReason', args=[[conn.self_handle],
129
"Computer says no", cs.GROUP_REASON_PERMISSION_DENIED],
131
q.dbus_return(e.message, signature='')
135
e, chan, cr = request_channel_expect_query(q, bus, account, conn, kopete)
138
q.dbus_return(e.message, signature='')
140
e, k = q.expect_many(
141
EventPattern('dbus-method-call',
142
path=empathy.object_path,
143
interface=cs.OBSERVER, method='ObserveChannels',
145
EventPattern('dbus-method-call',
146
path=kopete.object_path,
147
interface=cs.OBSERVER, method='ObserveChannels',
150
q.dbus_return(k.message, signature='')
151
q.dbus_return(e.message, signature='')
153
for _ in ('Kopete', 'Empathy'):
154
e = q.expect('dbus-method-call',
155
interface=cs.HANDLER, method='HandleChannels', handled=False)
156
q.dbus_raise(e.message, cs.INVALID_ARGUMENT, 'Never mind')
159
EventPattern('dbus-signal', path=cr.object_path,
160
interface=cs.CR, signal='Failed'),
161
EventPattern('dbus-method-call', path=chan.object_path,
162
interface=cs.CHANNEL, method='Close', handled=True),
165
if __name__ == '__main__':