File: polkitd.py

package info (click to toggle)
python-dbusmock 0.11.4-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 556 kB
  • ctags: 639
  • sloc: python: 4,442; sh: 5; makefile: 4
file content (63 lines) | stat: -rw-r--r-- 2,089 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'''polkitd mock template

This creates the expected methods and properties of the main
org.freedesktop.PolicyKit1 object. By default, all actions are rejected.  You
can call AllowUnknown() and SetAllowed() on the mock D-BUS interface to control
which actions are allowed.
'''

# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option) any
# later version.  See http://www.gnu.org/copyleft/lgpl.html for the full text
# of the license.

__author__ = 'Martin Pitt'
__email__ = 'martin.pitt@ubuntu.com'
__copyright__ = '(c) 2013 Canonical Ltd.'
__license__ = 'LGPL 3+'

import dbus

from dbusmock import MOCK_IFACE

BUS_NAME = 'org.freedesktop.PolicyKit1'
MAIN_OBJ = '/org/freedesktop/PolicyKit1/Authority'
MAIN_IFACE = 'org.freedesktop.PolicyKit1.Authority'
SYSTEM_BUS = True


def load(mock, parameters):
    mock.AddMethod(MAIN_IFACE,
                   'CheckAuthorization',
                   '(sa{sv})sa{ss}us',
                   '(bba{ss})',
                   '''ret = (args[1] in self.allowed or self.allow_unknown, False, {'test': 'test'})''')

    mock.AddProperties(MAIN_IFACE,
                       dbus.Dictionary({
                           'BackendName': 'local',
                           'BackendVersion': '0.8.15',
                           'BackendFeatures': dbus.UInt32(1, variant_level=1),
                       }, signature='sv'))

    # default state
    mock.allow_unknown = False
    mock.allowed = []


@dbus.service.method(MOCK_IFACE, in_signature='b', out_signature='')
def AllowUnknown(self, default):
    '''Control whether unknown actions are allowed

    This controls the return value of CheckAuthorization for actions which were
    not explicitly allowed by SetAllowed().
    '''
    self.allow_unknown = default


@dbus.service.method(MOCK_IFACE, in_signature='as', out_signature='')
def SetAllowed(self, actions):
    '''Set allowed actions'''

    self.allowed = actions