3
from landscape.configuration import LandscapeSetupConfiguration
4
from landscape.tests.helpers import LandscapeTest
5
from landscape.ui.tests.helpers import (
6
got_gobject_introspection, gobject_skip_message)
7
if got_gobject_introspection:
8
from landscape.ui.model.configuration.mechanism import (
9
ConfigurationMechanism, INTERFACE_NAME)
12
class MechanismTest(LandscapeTest):
14
Test that we can use mechanism calls successfully from within a secure
15
context (the easiest to achieve is in-process calls.
19
super(MechanismTest, self).setUp()
21
config += "data_path = /var/lib/landscape/client\n"
22
config += "http_proxy = http://proxy.localdomain:3192\n"
23
config += "tags = a_tag\n"
24
config += "url = https://landscape.canonical.com/message-system\n"
25
config += "account_name = foo\n"
26
config += "registration_password = boink\n"
27
config += "computer_title = baz\n"
28
config += "https_proxy = https://proxy.localdomain:6192\n"
29
config += "ping_url = http://landscape.canonical.com/ping\n"
30
self.config_filename = self.makeFile(config)
32
class MyLandscapeSetupConfiguration(LandscapeSetupConfiguration):
33
default_config_filenames = [self.config_filename]
35
self.config = MyLandscapeSetupConfiguration()
36
bus_name = dbus.service.BusName(INTERFACE_NAME, MechanismTest.bus)
37
self.mechanism = ConfigurationMechanism(self.config, bus_name)
38
self.config.load(["-c", self.config_filename])
41
self.mechanism.remove_from_connection()
42
super(MechanismTest, self).tearDown()
44
def test_is_local_call(self):
46
Test simple mechanism for checking if a call is local does the right
47
thing. Anything passed to this function that is not L{None} will
48
result in is returning False - this in turn means that bypassing
49
security will not happen, which is the right thing in failure cases
52
self.assertTrue(self.mechanism._is_local_call(None, None))
53
self.assertFalse(self.mechanism._is_local_call(True, True))
55
def test_get_account_name(self):
57
Test we can get account name from the mechanism.
59
self.assertEqual("foo", self.mechanism.get("account_name"))
61
def test_set_account_name(self):
63
Test we can set the account name via the mechanism.
65
self.mechanism.set("account_name", "bar")
66
self.assertEqual("bar", self.mechanism.get("account_name"))
68
def test_set_account_name_unicode(self):
70
Non-ascii characters are replaced before passing to underlying config.
72
self.mechanism.set("account_name", u"unicode\u00a3unicode")
73
self.assertEqual("unicode?unicode", self.mechanism.get("account_name"))
75
def test_no_unicode_to_underlying_config(self):
77
Non-ascii characters are replaced before passing to underlying config.
79
class FakeConfig(object):
81
self.account_name = None
83
fake_config = FakeConfig()
84
self.mechanism._config = fake_config
85
self.mechanism.set("account_name", u"unicode\u00a3unicode")
86
self.assertEqual("unicode?unicode", fake_config.account_name)
88
def test_get_data_path(self):
90
Test we can get the data path from the mechanism.
92
self.assertEqual("/var/lib/landscape/client/",
93
self.mechanism.get("data_path"))
95
def set_data_path(self):
97
Test we can set the data path via the mechanism.
99
self.mechanism.set("data_path", "bar")
100
self.assertEqual("bar", self.mechanism.get("data_path"))
102
def test_get_http_proxy(self):
104
Test that we can get the HTTP proxy from the mechanism.
106
self.assertEqual("http://proxy.localdomain:3192",
107
self.mechanism.get("http_proxy"))
109
def test_set_http_proxy(self):
111
Test that we can set the HTTP proxy via the mechanism.
113
self.mechanism.set("http_proxy", "bar")
114
self.assertEqual("bar", self.mechanism.get("http_proxy"))
116
def test_get_tags(self):
118
Test that we can get Tags from the mechanism.
120
self.assertEqual("a_tag", self.mechanism.get("tags"))
122
def test_set_tags(self):
124
Test that we can set Tags via the mechanism.
126
self.mechanism.set("tags", "bar")
127
self.assertEqual("bar", self.mechanism.get("tags"))
129
def test_get_url(self):
131
Test that we can get URL from the mechanism.
133
self.assertEqual("https://landscape.canonical.com/message-system",
134
self.mechanism.get("url"))
136
def test_set_url(self):
138
Test that we can set the URL via the mechanisms.
140
self.mechanism.set("url", "bar")
141
self.assertEqual(self.mechanism.get("url"), "bar")
143
def test_get_ping_url(self):
145
Test that we can get the Ping URL from the mechanism.
147
self.assertEqual("http://landscape.canonical.com/ping",
148
self.mechanism.get("ping_url"))
150
def test_set_ping_url(self):
152
Test that we can set the Ping URL via the mechanism.
154
self.mechanism.set("ping_url", "bar")
155
self.assertEqual("bar", self.mechanism.get("ping_url"))
157
def test_get_registration_password(self):
159
Test that we can get the registration password from the mechanism.
161
self.assertEqual("boink", self.mechanism.get("registration_password"))
163
def test_set_registration_password(self):
165
Test that we can set the registration password via the mechanism.
167
self.mechanism.set("registration_password", "bar")
168
self.assertEqual("bar", self.mechanism.get("registration_password"))
170
def test_get_computer_title(self):
172
Test that we can get the computer title from the mechanism.
174
self.assertEqual("baz", self.mechanism.get("computer_title"))
176
def test_set_computer_title(self):
178
Test that we can set the computer title via the mechanism.
180
self.mechanism.set("computer_title", "bar")
181
self.assertEqual("bar", self.mechanism.get("computer_title"))
183
def test_get_https_proxy(self):
185
Test that we can get the HTTPS Proxy from the mechanism.
187
self.assertEqual("https://proxy.localdomain:6192",
188
self.mechanism.get("https_proxy"))
190
def test_set_https_proxy(self):
192
Test that we can set the HTTPS Proxy via the mechanism.
194
self.mechanism.set("https_proxy", "bar")
195
self.assertEqual("bar", self.mechanism.get("https_proxy"))
199
Test that we cause the mechanism to exit.
201
self.assertRaises(SystemExit, self.mechanism.exit)
203
if not got_gobject_introspection:
204
skip = gobject_skip_message
206
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
208
bus = dbus.SessionBus(private=True)
209
except dbus.exceptions.DBusException:
210
skip = "Cannot create private DBus session without X11"