~jseutter/landscape-client/invalid-integer

« back to all changes in this revision

Viewing changes to landscape/ui/model/configuration/tests/test_mechanism.py

Merged ui-permissions-and-panel [r=therve,free.ekanayaka][f=911665]

The following changes have been made:
  - Split Configuration model into a DBus service mechanism and a proxy for the client.
  - Split Registration model in to a DBus service mechanism and a proxy for the client (with asynchronous registration).
  - Create PolicyKit policies for configuration and registration and cause these to be checked by the relevant DBus service mechanism when it receives dbus calls (effectively trigger a challenge for a password and only allow admin users to continue).
   - Create DBus service and conf files for the two service mechanisms (Allowing them to be run by the System bus on demand)
   - Create an application desktop file causing the landscape-client-settings-ui program to be launchable from gnome-control-center
   - Create the icon preferences-management-service.svg to represent this activity in gnome-control-center.
   - Create setupui.py - a distutils script for the settings-ui components.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import dbus
 
2
 
 
3
from landscape.configuration import LandscapeSetupConfiguration
 
4
from landscape.tests.helpers import LandscapeTest
 
5
from landscape.ui.model.configuration.mechanism import (
 
6
    ConfigurationMechanism, INTERFACE_NAME)
 
7
 
 
8
 
 
9
class MechanismTest(LandscapeTest):
 
10
    """
 
11
    Test that we can use mechanism calls successfully from within a secure
 
12
    context (the easiest to achieve is in-process calls.
 
13
    """
 
14
 
 
15
    def setUp(self):
 
16
        super(MechanismTest, self).setUp()
 
17
        config = "[client]"
 
18
        config += "data_path = /var/lib/landscape/client\n"
 
19
        config += "http_proxy = http://proxy.localdomain:3192\n"
 
20
        config += "tags = a_tag\n"
 
21
        config += "url = https://landscape.canonical.com/message-system\n"
 
22
        config += "account_name = foo\n"
 
23
        config += "registration_password = boink\n"
 
24
        config += "computer_title = baz\n"
 
25
        config += "https_proxy = https://proxy.localdomain:6192\n"
 
26
        config += "ping_url = http://landscape.canonical.com/ping\n"
 
27
        self.config_filename = self.makeFile(config)
 
28
 
 
29
        class MyLandscapeSetupConfiguration(LandscapeSetupConfiguration):
 
30
            default_config_filenames = [self.config_filename]
 
31
 
 
32
        self.config = MyLandscapeSetupConfiguration()
 
33
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 
34
        bus = dbus.SessionBus()
 
35
        bus_name = dbus.service.BusName(INTERFACE_NAME, bus)
 
36
        self.mechanism = ConfigurationMechanism(self.config, bus_name)
 
37
        self.config.load(["-c", self.config_filename])
 
38
 
 
39
    def tearDown(self):
 
40
        self.mechanism.remove_from_connection()
 
41
        super(MechanismTest, self).tearDown()
 
42
 
 
43
    def test_is_local_call(self):
 
44
        """
 
45
        Test simple mechanism for checking if a call is local does the right
 
46
        thing.  Anything passed to this function that is not L{None} will
 
47
        result in is returning False - this in turn means that bypassing
 
48
        security will not happen, which is the right thing in failure cases
 
49
        too.
 
50
        """
 
51
        self.assertTrue(self.mechanism._is_local_call(None, None))
 
52
        self.assertFalse(self.mechanism._is_local_call(True, True))
 
53
 
 
54
    def test_get_account_name(self):
 
55
        """
 
56
        Test we can get account name from the mechanism.
 
57
        """
 
58
        self.assertEqual("foo", self.mechanism.get("account_name"))
 
59
 
 
60
    def test_set_account_name(self):
 
61
        """
 
62
        Test we can set the account name via the mechanism.
 
63
        """
 
64
        self.mechanism.set("account_name", "bar")
 
65
        self.assertEqual("bar", self.mechanism.get("account_name"))
 
66
 
 
67
    def test_get_data_path(self):
 
68
        """
 
69
        Test we can get the data path from the mechanism.
 
70
        """
 
71
        self.assertEqual("/var/lib/landscape/client/",
 
72
                         self.mechanism.get("data_path"))
 
73
 
 
74
    def set_data_path(self):
 
75
        """
 
76
        Test we can set the data path via the mechanism.
 
77
        """
 
78
        self.mechanism.set("data_path", "bar")
 
79
        self.assertEqual("bar", self.mechanism.get("data_path"))
 
80
 
 
81
    def test_get_http_proxy(self):
 
82
        """
 
83
        Test that we can get the HTTP proxy from the mechanism.
 
84
        """
 
85
        self.assertEqual("http://proxy.localdomain:3192",
 
86
                         self.mechanism.get("http_proxy"))
 
87
 
 
88
    def test_set_http_proxy(self):
 
89
        """
 
90
        Test that we can set the HTTP proxy via the mechanism.
 
91
        """
 
92
        self.mechanism.set("http_proxy", "bar")
 
93
        self.assertEqual("bar", self.mechanism.get("http_proxy"))
 
94
 
 
95
    def test_get_tags(self):
 
96
        """
 
97
        Test that we can get Tags from the mechanism.
 
98
        """
 
99
        self.assertEquals("a_tag", self.mechanism.get("tags"))
 
100
 
 
101
    def test_set_tags(self):
 
102
        """
 
103
        Test that we can set Tags via the mechanism.
 
104
        """
 
105
        self.mechanism.set("tags", "bar")
 
106
        self.assertEquals("bar", self.mechanism.get("tags"))
 
107
 
 
108
    def test_get_url(self):
 
109
        """
 
110
        Test that we can get URL from the mechanism.
 
111
        """
 
112
        self.assertEquals("https://landscape.canonical.com/message-system",
 
113
                          self.mechanism.get("url"))
 
114
 
 
115
    def test_set_url(self):
 
116
        """
 
117
        Test that we can set the URL via the mechanisms.
 
118
        """
 
119
        self.mechanism.set("url", "bar")
 
120
        self.assertEquals(self.mechanism.get("url"), "bar")
 
121
 
 
122
    def test_get_ping_url(self):
 
123
        """
 
124
        Test that we can get the Ping URL from the mechanism.
 
125
        """
 
126
        self.assertEquals("http://landscape.canonical.com/ping",
 
127
                          self.mechanism.get("ping_url"))
 
128
 
 
129
    def test_set_ping_url(self):
 
130
        """
 
131
        Test that we can set the Ping URL via the mechanism.
 
132
        """
 
133
        self.mechanism.set("ping_url", "bar")
 
134
        self.assertEquals("bar", self.mechanism.get("ping_url"))
 
135
 
 
136
    def test_get_registration_password(self):
 
137
        """
 
138
        Test that we can get the registration password from the mechanism.
 
139
        """
 
140
        self.assertEquals("boink", self.mechanism.get("registration_password"))
 
141
 
 
142
    def test_set_registration_password(self):
 
143
        """
 
144
        Test that we can set the registration password via the mechanism.
 
145
        """
 
146
        self.mechanism.set("registration_password", "bar")
 
147
        self.assertEquals("bar", self.mechanism.get("registration_password"))
 
148
 
 
149
    def test_get_computer_title(self):
 
150
        """
 
151
        Test that we can get the computer title from the mechanism.
 
152
        """
 
153
        self.assertEquals("baz", self.mechanism.get("computer_title"))
 
154
 
 
155
    def test_set_computer_title(self):
 
156
        """
 
157
        Test that we can set the computer title via the mechanism.
 
158
        """
 
159
        self.mechanism.set("computer_title", "bar")
 
160
        self.assertEquals("bar", self.mechanism.get("computer_title"))
 
161
 
 
162
    def test_get_https_proxy(self):
 
163
        """
 
164
        Test that we can get the HTTPS Proxy from the mechanism.
 
165
        """
 
166
        self.assertEqual("https://proxy.localdomain:6192",
 
167
                         self.mechanism.get("https_proxy"))
 
168
 
 
169
    def test_set_https_proxy(self):
 
170
        """
 
171
        Test that we can set the HTTPS Proxy via the mechanism.
 
172
        """
 
173
        self.mechanism.set("https_proxy", "bar")
 
174
        self.assertEqual("bar", self.mechanism.get("https_proxy"))