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)
9
class MechanismTest(LandscapeTest):
11
Test that we can use mechanism calls successfully from within a secure
12
context (the easiest to achieve is in-process calls.
16
super(MechanismTest, self).setUp()
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)
29
class MyLandscapeSetupConfiguration(LandscapeSetupConfiguration):
30
default_config_filenames = [self.config_filename]
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])
40
self.mechanism.remove_from_connection()
41
super(MechanismTest, self).tearDown()
43
def test_is_local_call(self):
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
51
self.assertTrue(self.mechanism._is_local_call(None, None))
52
self.assertFalse(self.mechanism._is_local_call(True, True))
54
def test_get_account_name(self):
56
Test we can get account name from the mechanism.
58
self.assertEqual("foo", self.mechanism.get("account_name"))
60
def test_set_account_name(self):
62
Test we can set the account name via the mechanism.
64
self.mechanism.set("account_name", "bar")
65
self.assertEqual("bar", self.mechanism.get("account_name"))
67
def test_get_data_path(self):
69
Test we can get the data path from the mechanism.
71
self.assertEqual("/var/lib/landscape/client/",
72
self.mechanism.get("data_path"))
74
def set_data_path(self):
76
Test we can set the data path via the mechanism.
78
self.mechanism.set("data_path", "bar")
79
self.assertEqual("bar", self.mechanism.get("data_path"))
81
def test_get_http_proxy(self):
83
Test that we can get the HTTP proxy from the mechanism.
85
self.assertEqual("http://proxy.localdomain:3192",
86
self.mechanism.get("http_proxy"))
88
def test_set_http_proxy(self):
90
Test that we can set the HTTP proxy via the mechanism.
92
self.mechanism.set("http_proxy", "bar")
93
self.assertEqual("bar", self.mechanism.get("http_proxy"))
95
def test_get_tags(self):
97
Test that we can get Tags from the mechanism.
99
self.assertEquals("a_tag", self.mechanism.get("tags"))
101
def test_set_tags(self):
103
Test that we can set Tags via the mechanism.
105
self.mechanism.set("tags", "bar")
106
self.assertEquals("bar", self.mechanism.get("tags"))
108
def test_get_url(self):
110
Test that we can get URL from the mechanism.
112
self.assertEquals("https://landscape.canonical.com/message-system",
113
self.mechanism.get("url"))
115
def test_set_url(self):
117
Test that we can set the URL via the mechanisms.
119
self.mechanism.set("url", "bar")
120
self.assertEquals(self.mechanism.get("url"), "bar")
122
def test_get_ping_url(self):
124
Test that we can get the Ping URL from the mechanism.
126
self.assertEquals("http://landscape.canonical.com/ping",
127
self.mechanism.get("ping_url"))
129
def test_set_ping_url(self):
131
Test that we can set the Ping URL via the mechanism.
133
self.mechanism.set("ping_url", "bar")
134
self.assertEquals("bar", self.mechanism.get("ping_url"))
136
def test_get_registration_password(self):
138
Test that we can get the registration password from the mechanism.
140
self.assertEquals("boink", self.mechanism.get("registration_password"))
142
def test_set_registration_password(self):
144
Test that we can set the registration password via the mechanism.
146
self.mechanism.set("registration_password", "bar")
147
self.assertEquals("bar", self.mechanism.get("registration_password"))
149
def test_get_computer_title(self):
151
Test that we can get the computer title from the mechanism.
153
self.assertEquals("baz", self.mechanism.get("computer_title"))
155
def test_set_computer_title(self):
157
Test that we can set the computer title via the mechanism.
159
self.mechanism.set("computer_title", "bar")
160
self.assertEquals("bar", self.mechanism.get("computer_title"))
162
def test_get_https_proxy(self):
164
Test that we can get the HTTPS Proxy from the mechanism.
166
self.assertEqual("https://proxy.localdomain:6192",
167
self.mechanism.get("https_proxy"))
169
def test_set_https_proxy(self):
171
Test that we can set the HTTPS Proxy via the mechanism.
173
self.mechanism.set("https_proxy", "bar")
174
self.assertEqual("bar", self.mechanism.get("https_proxy"))