~ahasenack/landscape-client/landscape-client-1.5.5-0ubuntu0.10.04.0

« back to all changes in this revision

Viewing changes to landscape/manager/tests/test_usermanager.py

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2010-06-28 18:07:18 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100628180718-vytyqgbtkiirv5sb
Tags: 1.5.2.1-0ubuntu0.10.04.0
Filter duplicate network interfaces in get_active_interfaces (LP: #597000)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from landscape.lib.dbus_util import get_object
 
1
import os
2
2
 
3
3
from landscape.lib.persist import Persist
4
 
 
5
 
from landscape.manager.manager import SUCCEEDED, FAILED
6
 
from landscape.monitor.monitor import MonitorPluginRegistry
7
 
from landscape.manager.manager import ManagerPluginRegistry
 
4
from landscape.manager.plugin import SUCCEEDED, FAILED
8
5
from landscape.monitor.usermonitor import UserMonitor
9
 
from landscape.manager.usermanager import UserManager, UserManagerDBusObject
 
6
from landscape.manager.usermanager import (
 
7
    UserManager, RemoteUserManagerConnector)
10
8
from landscape.user.tests.helpers import FakeUserProvider, FakeUserManagement
11
 
from landscape.tests.helpers import LandscapeIsolatedTest
 
9
from landscape.tests.helpers import LandscapeTest, ManagerHelper
12
10
from landscape.user.provider import UserManagementError
13
 
from landscape.tests.helpers import RemoteBrokerHelper
14
 
 
15
 
 
16
 
class ManagerServiceTest(LandscapeIsolatedTest):
17
 
 
18
 
    helpers = [RemoteBrokerHelper]
19
 
 
20
 
    def setUp(self):
21
 
        super(ManagerServiceTest, self).setUp()
22
 
 
23
 
    def test_remote_locked_usernames(self):
24
 
 
25
 
        def check_result(result):
26
 
            self.assertEquals(result, ["psmith"])
27
 
 
28
 
        self.shadow_file = self.makeFile("""\
29
 
jdoe:$1$xFlQvTqe$cBtrNEDOIKMy/BuJoUdeG0:13348:0:99999:7:::
30
 
psmith:!:13348:0:99999:7:::
31
 
sbarnes:$1$q7sz09uw$q.A3526M/SHu8vUb.Jo1A/:13349:0:99999:7:::
32
 
""")
33
 
        UserManagerDBusObject(self.broker_service.bus,
34
 
                              shadow_file=self.shadow_file)
35
 
        remote_service = get_object(self.broker_service.bus,
36
 
            UserManagerDBusObject.bus_name, UserManagerDBusObject.object_path)
37
 
 
38
 
        result = remote_service.get_locked_usernames()
39
 
        result.addCallback(check_result)
40
 
        return result
41
 
 
42
 
    def test_remote_empty_shadow_file(self):
43
 
 
44
 
        def check_result(result):
45
 
            self.assertEquals(result, [])
46
 
 
47
 
        self.shadow_file = self.makeFile("\n")
48
 
        UserManagerDBusObject(self.broker_service.bus,
49
 
                              shadow_file=self.shadow_file)
50
 
        remote_service = get_object(self.broker_service.bus,
51
 
            UserManagerDBusObject.bus_name, UserManagerDBusObject.object_path)
52
 
 
53
 
        result = remote_service.get_locked_usernames()
54
 
        result.addCallback(check_result)
55
 
        return result
56
 
 
57
 
class UserGroupTestBase(LandscapeIsolatedTest):
58
 
 
59
 
    helpers = [RemoteBrokerHelper]
 
11
 
 
12
 
 
13
class UserGroupTestBase(LandscapeTest):
 
14
 
 
15
    helpers = [ManagerHelper]
60
16
 
61
17
    def setUp(self):
62
18
        super(UserGroupTestBase, self).setUp()
63
 
        self.persist = Persist()
64
 
        self.monitor = MonitorPluginRegistry(
65
 
            self.remote, self.broker_service.reactor,
66
 
            self.broker_service.config, self.broker_service.bus,
67
 
            self.persist)
68
 
 
69
19
        self.shadow_file = self.makeFile("""\
70
20
jdoe:$1$xFlQvTqe$cBtrNEDOIKMy/BuJoUdeG0:13348:0:99999:7:::
71
21
psmith:!:13348:0:99999:7:::
73
23
""")
74
24
        accepted_types = ["operation-result", "users"]
75
25
        self.broker_service.message_store.set_accepted_types(accepted_types)
76
 
        self.manager = ManagerPluginRegistry(
77
 
            self.remote, self.broker_service.reactor,
78
 
            self.broker_service.config, self.broker_service.bus)
 
26
 
 
27
    def tearDown(self):
 
28
        super(UserGroupTestBase, self).tearDown()
 
29
        for plugin in self.plugins:
 
30
            plugin.stop()
79
31
 
80
32
    def setup_environment(self, users, groups, shadow_file):
81
33
        provider = FakeUserProvider(users=users, groups=groups,
82
34
                                    shadow_file=shadow_file)
83
 
        plugin = UserMonitor(provider=provider)
84
 
        self.monitor.add(plugin)
85
 
        manager = UserManager(management=FakeUserManagement(provider=provider),
86
 
                              shadow_file=shadow_file)
87
 
        self.manager.add(manager)
88
 
        return plugin
 
35
        user_monitor = UserMonitor(provider=provider)
 
36
        management = FakeUserManagement(provider=provider)
 
37
        user_manager = UserManager(management=management,
 
38
                                   shadow_file=shadow_file)
 
39
        self.manager.persist = Persist()
 
40
        user_monitor.register(self.manager)
 
41
        user_manager.register(self.manager)
 
42
        self.plugins = [user_monitor, user_manager]
 
43
        return user_monitor
89
44
 
90
45
 
91
46
class UserOperationsMessagingTest(UserGroupTestBase):
97
52
        with details about the change and an C{operation-result} with
98
53
        details of the outcome of the operation.
99
54
        """
 
55
 
100
56
        def handle_callback(result):
101
57
            messages = self.broker_service.message_store.get_pending_messages()
102
58
            self.assertMessages(messages,
134
90
        containing details of the failure.
135
91
        """
136
92
        self.log_helper.ignore_errors(KeyError)
 
93
 
137
94
        def handle_callback(result):
138
95
            messages = self.broker_service.message_store.get_pending_messages()
139
96
            self.assertMessages(messages,
155
112
        event is received and processed.  In other words, a snapshot
156
113
        should have been taken after the operation was handled.
157
114
        """
 
115
 
158
116
        def handle_callback1(result):
159
117
            message_store = self.broker_service.message_store
160
118
            messages = message_store.get_pending_messages()
186
144
        should first detect changes and then perform the operation.
187
145
        The results should be reported in separate messages.
188
146
        """
 
147
 
189
148
        def handle_callback(result):
190
149
            messages = self.broker_service.message_store.get_pending_messages()
191
150
            self.assertEquals(len(messages), 3)
227
186
        with details about the change and an C{operation-result} with
228
187
        details of the outcome of the operation.
229
188
        """
 
189
 
230
190
        def handle_callback(result):
231
191
            messages = self.broker_service.message_store.get_pending_messages()
232
192
            self.assertEquals(len(messages), 3)
245
205
                                                    "name": "John Doe",
246
206
                                                    "primary-gid": 1001}],
247
207
                                    "timestamp": 0, "type": "users",
248
 
                                  "operation-id": 99},])
 
208
                                  "operation-id": 99}])
249
209
 
250
 
        users = [("jdoe", "x", 1001, 1000, "John Doe,,,,", "/home/bo", "/bin/zsh")]
 
210
        users = [("jdoe", "x", 1001, 1000, "John Doe,,,,",
 
211
                  "/home/bo", "/bin/zsh")]
251
212
        groups = [("users", "x", 1001, [])]
252
213
        self.setup_environment(users, groups, None)
253
214
        result = self.manager.dispatch_message(
259
220
        result.addCallback(handle_callback)
260
221
        return result
261
222
 
262
 
 
263
223
    def test_edit_user_event_in_sync(self):
264
224
        """
265
225
        The client and server should be in sync after a C{edit-user}
266
226
        event is received and processed.  In other words, a snapshot
267
227
        should have been taken after the operation was handled.
268
228
        """
 
229
 
269
230
        def handle_callback1(result):
270
231
            messages = self.broker_service.message_store.get_pending_messages()
271
232
            self.assertTrue(messages)
274
235
            return result
275
236
 
276
237
        def handle_callback2(result, messages):
277
 
            new_messages = self.broker_service.message_store.get_pending_messages()
 
238
            mstore = self.broker_service.message_store
 
239
            new_messages = mstore.get_pending_messages()
278
240
            self.assertEquals(messages, new_messages)
279
241
            return result
280
242
 
281
 
        users = [("jdoe", "x", 1000, 1000, "John Doe,,,,", "/home/bo", "/bin/zsh")]
 
243
        users = [("jdoe", "x", 1000, 1000, "John Doe,,,,",
 
244
                  "/home/bo", "/bin/zsh")]
282
245
        plugin = self.setup_environment(users, [], None)
283
246
        result = self.manager.dispatch_message(
284
247
            {"username": "jdoe", "password": "password", "name": "John Doe",
295
258
        should first detect changes and then perform the operation.
296
259
        The results should be reported in separate messages.
297
260
        """
 
261
 
298
262
        def handle_callback(result):
299
263
            messages = self.broker_service.message_store.get_pending_messages()
300
264
            self.assertEquals(len(messages), 3)
301
265
            self.assertMessages([messages[0], messages[2]],
302
266
                                [{"type": "users",
303
 
                                  "create-group-members": {u"users": [u"jdoe"]},
 
267
                                  "create-group-members": {u"users":
 
268
                                                           [u"jdoe"]},
304
269
                                  "create-groups": [{"gid": 1001,
305
270
                                                     "name": u"users"}],
306
271
                                  "create-users": [{"home-phone": None,
342
307
        and an C{operation-result} with details of the outcome of the
343
308
        operation.
344
309
        """
 
310
 
345
311
        def handle_callback(result):
346
312
            messages = self.broker_service.message_store.get_pending_messages()
347
313
            self.assertEquals(len(messages), 3)
380
346
            self.assertMessages(messages,
381
347
                                [{"type": "operation-result", "status": FAILED,
382
348
                                  "operation-id": 39, "timestamp": 0,
383
 
                                  "result-text": failure_string}
384
 
                                ])
 
349
                                  "result-text": failure_string}])
385
350
 
386
351
        self.setup_environment([], [], None)
387
352
        result = self.manager.dispatch_message(
392
357
        result.addCallback(handle_callback)
393
358
        return result
394
359
 
395
 
 
396
360
    def test_remove_user_event_leave_home(self):
397
361
        """
398
362
        When a C{remove-user} event is received, with the
402
366
        about the change and an C{operation-result} with details of
403
367
        the outcome of the operation.
404
368
        """
 
369
 
405
370
        def handle_callback(result):
406
 
                messages = self.broker_service.message_store.get_pending_messages()
 
371
                messages = (
 
372
                    self.broker_service.message_store.get_pending_messages())
407
373
                self.assertEquals(len(messages), 3)
408
374
                # Ignore the message created by plugin.run.
409
375
                self.assertMessages([messages[2], messages[1]],
414
380
                                      "operation-id": 39, "timestamp": 0,
415
381
                                      "result-text": "remove_user succeeded"}])
416
382
 
417
 
        users = [("jdoe", "x", 1000, 1000, "John Doe,,,,", "/home/bo", "/bin/zsh")]
 
383
        users = [("jdoe", "x", 1000, 1000,
 
384
                  "John Doe,,,,", "/home/bo", "/bin/zsh")]
418
385
        self.setup_environment(users, [], None)
419
386
        result = self.manager.dispatch_message(
420
387
            {"username": "jdoe",
430
397
        event is received and processed.  In other words, a snapshot
431
398
        should have been taken after the operation was handled.
432
399
        """
 
400
 
433
401
        def handle_callback1(result):
434
402
            message_store = self.broker_service.message_store
435
403
            messages = message_store.get_pending_messages()
462
430
        operation.  The results should be reported in separate
463
431
        messages.
464
432
        """
 
433
 
465
434
        def handle_callback(result):
466
435
            messages = self.broker_service.message_store.get_pending_messages()
467
436
            self.assertEquals(len(messages), 3)
498
467
        C{operation-result} with details of the outcome of the
499
468
        operation.
500
469
        """
 
470
 
501
471
        def handle_callback(result):
502
 
           messages = self.broker_service.message_store.get_pending_messages()
503
 
           self.assertEquals(len(messages), 3, messages)
504
 
           # Ignore the message created by plugin.run.
505
 
           self.assertMessages([messages[2], messages[1]],
506
 
                               [{"timestamp": 0, "type": "users", "operation-id": 99,
507
 
                                 "update-users": [{"home-phone": None,
508
 
                                                   "username": "jdoe",
509
 
                                                   "uid": 1000,
510
 
                                                   "enabled": False,
511
 
                                                   "location": None,
512
 
                                                   "work-phone": None,
513
 
                                                   "primary-gid": 1000,
514
 
                                                   "name": u"John Doe"}]},
515
 
                                {"type": "operation-result",
516
 
                                 "status": SUCCEEDED,
517
 
                                 "operation-id": 99, "timestamp": 0,
518
 
                                 "result-text": "lock_user succeeded"}])
 
472
            messages = self.broker_service.message_store.get_pending_messages()
 
473
            self.assertEquals(len(messages), 3, messages)
 
474
            # Ignore the message created by plugin.run.
 
475
            self.assertMessages([messages[2], messages[1]],
 
476
                                [{"timestamp": 0, "type": "users", "operation-id": 99,
 
477
                                  "update-users": [{"home-phone": None,
 
478
                                                    "username": "jdoe",
 
479
                                                    "uid": 1000,
 
480
                                                    "enabled": False,
 
481
                                                    "location": None,
 
482
                                                    "work-phone": None,
 
483
                                                    "primary-gid": 1000,
 
484
                                                    "name": u"John Doe"}]},
 
485
                                 {"type": "operation-result",
 
486
                                  "status": SUCCEEDED,
 
487
                                  "operation-id": 99, "timestamp": 0,
 
488
                                  "result-text": "lock_user succeeded"}])
519
489
 
520
490
        users = [("jdoe", "x", 1000, 1000, "John Doe,,,,", "/home/bo", "/bin/zsh")]
521
491
        self.setup_environment(users, [], self.shadow_file)
533
503
        we expect only a single failure message to be generated.
534
504
        """
535
505
        self.log_helper.ignore_errors(UserManagementError)
 
506
 
536
507
        def handle_callback(result):
537
508
            messages = self.broker_service.message_store.get_pending_messages()
538
509
            self.assertEquals(len(messages), 1)
557
528
        event is received and processed.  In other words, a snapshot
558
529
        should have been taken after the operation was handled.
559
530
        """
 
531
 
560
532
        def handle_callback1(result):
561
533
            message_store = self.broker_service.message_store
562
534
            messages = message_store.get_pending_messages()
627
599
        with details about the change and an C{operation-result} with
628
600
        details of the outcome of the operation.
629
601
        """
 
602
 
630
603
        def handle_callback(result):
631
604
            messages = self.broker_service.message_store.get_pending_messages()
632
605
            self.assertEquals(len(messages), 3)
664
637
        error should be generated.
665
638
        """
666
639
        self.log_helper.ignore_errors(UserManagementError)
 
640
 
667
641
        def handle_callback(result):
668
642
            messages = self.broker_service.message_store.get_pending_messages()
669
643
            self.assertEquals(len(messages), 1)
689
663
        words, a snapshot should have been taken after the operation
690
664
        was handled.
691
665
        """
 
666
 
692
667
        def handle_callback(result):
693
668
            message_store = self.broker_service.message_store
694
669
            messages = message_store.get_pending_messages()
721
696
        operation.  The results should be reported in separate
722
697
        messages.
723
698
        """
 
699
 
724
700
        def handle_callback(result):
725
701
            messages = self.broker_service.message_store.get_pending_messages()
726
702
            self.assertEquals(len(messages), 3)
746
722
 
747
723
        users = [("psmith", "x", 1000, 1000, "Paul Smith,,,,", "/home/psmith",
748
724
                  "/bin/zsh")]
749
 
        plugin = self.setup_environment(users, [], self.shadow_file)
 
725
        self.setup_environment(users, [], self.shadow_file)
750
726
 
751
727
        result = self.manager.dispatch_message(
752
728
            {"username": "psmith",
765
741
        with details about the change and an C{operation-result} with
766
742
        details of the outcome of the operation.
767
743
        """
 
744
 
768
745
        def handle_callback(result):
769
746
            messages = self.broker_service.message_store.get_pending_messages()
770
747
            self.assertEquals(len(messages), 2)
793
770
        event is received and processed.  In other words, a snapshot
794
771
        should have been taken after the operation was handled.
795
772
        """
 
773
 
796
774
        def handle_callback1(result):
797
775
            message_store = self.broker_service.message_store
798
776
            messages = message_store.get_pending_messages()
822
800
        should first detect changes and then perform the operation.
823
801
        The results should be reported in separate messages.
824
802
        """
 
803
 
825
804
        def handle_callback(result):
826
805
            messages = self.broker_service.message_store.get_pending_messages()
827
806
            self.assertEquals(len(messages), 3)
853
832
        and an C{operation-result} with details of the outcome of the
854
833
        operation.
855
834
        """
 
835
 
856
836
        def handle_callback(result):
857
837
            messages = self.broker_service.message_store.get_pending_messages()
858
838
            self.assertEquals(len(messages), 3)
891
871
        event is received and processed.  In other words, a snapshot
892
872
        should have been taken after the operation was handled.
893
873
        """
 
874
 
894
875
        def handle_callback1(result):
895
876
            message_store = self.broker_service.message_store
896
877
            messages = message_store.get_pending_messages()
923
904
        operation.  The results should be reported in separate
924
905
        messages.
925
906
        """
 
907
 
926
908
        def handle_callback1(result):
927
909
            result = self.manager.dispatch_message(
928
910
                {"groupname": "sales", "new-name": "webdev",
943
925
                                  "operation-id": 123,
944
926
                                  "delete-groups": ["sales"],
945
927
                                  "create-groups": [{"gid": 1001,
946
 
                                                     "name": "webdev"}]
947
 
                                                    }])
 
928
                                                     "name": "webdev"}]}])
948
929
 
949
930
 
950
931
        groups = [("sales", "x", 1001, [])]
962
943
        and an C{operation-result} with details of the outcome of the
963
944
        operation.
964
945
        """
 
946
 
965
947
        def handle_callback(result):
966
948
            messages = self.broker_service.message_store.get_pending_messages()
967
949
            self.assertEquals(len(messages), 3)
1000
982
        and an C{operation-result} with details of the outcome of the
1001
983
        operation.
1002
984
        """
 
985
 
1003
986
        def handle_callback(result):
1004
987
            messages = self.broker_service.message_store.get_pending_messages()
1005
988
            self.assertEquals(len(messages), 3)
1011
994
                                  "create-group-members": {"bizdev": ["jdoe"]}},
1012
995
                                 {"type": "operation-result", "timestamp": 0,
1013
996
                                  "status": SUCCEEDED, "operation-id": 123,
1014
 
                                 "result-text": "add_group_member succeeded"}
1015
 
                                ])
 
997
                                 "result-text": "add_group_member succeeded"}])
1016
998
 
1017
999
 
1018
1000
        users = [("jdoe", "x", 1000, 1000, "John Doe,,,,", "/bin/sh",
1034
1016
        words, a snapshot should have been taken after the operation
1035
1017
        was handled.
1036
1018
        """
 
1019
 
1037
1020
        def handle_callback(result):
1038
1021
            message_store = self.broker_service.message_store
1039
1022
            messages = message_store.get_pending_messages()
1067
1050
        operation.  The results should be reported in separate
1068
1051
        messages.
1069
1052
        """
 
1053
 
1070
1054
        def handle_callback(result):
1071
1055
            messages = self.broker_service.message_store.get_pending_messages()
1072
1056
            self.assertEquals(len(messages), 3)
1088
1072
        users = [("jdoe", "x", 1000, 1000, "John Doe,,,,", "/bin/sh",
1089
1073
                  "/home/jdoe")]
1090
1074
        groups = [("bizdev", "x", 1001, [])]
1091
 
        plugin = self.setup_environment(users, groups, None)
 
1075
        self.setup_environment(users, groups, None)
1092
1076
        result = self.manager.dispatch_message(
1093
1077
            {"username": "jdoe",
1094
1078
             "groupname": "bizdev",
1105
1089
        and an C{operation-result} with details of the outcome of the
1106
1090
        operation.
1107
1091
        """
 
1092
 
1108
1093
        def handle_callback(result):
1109
1094
            messages = self.broker_service.message_store.get_pending_messages()
1110
1095
            self.assertEquals(len(messages), 3)
1136
1121
        other words, a snapshot should have been taken after the
1137
1122
        operation was handled.
1138
1123
        """
 
1124
 
1139
1125
        def handle_callback1(result):
1140
 
            message_store = self.broker_service.message_store
1141
1126
            messages = self.broker_service.message_store.get_pending_messages()
1142
1127
            self.assertTrue(messages)
1143
1128
            result = plugin.run()
1168
1153
        operation.  The results should be reported in separate
1169
1154
        messages.
1170
1155
        """
 
1156
 
1171
1157
        def handle_callback(result):
1172
1158
            messages = self.broker_service.message_store.get_pending_messages()
1173
1159
            self.assertEquals(len(messages), 3)
1207
1193
        C{operation-result} with details of the outcome of the
1208
1194
        operation.
1209
1195
        """
 
1196
 
1210
1197
        def handle_callback1(result):
1211
1198
 
1212
1199
            result = self.manager.dispatch_message(
1244
1231
        words, a snapshot should have been taken after the operation
1245
1232
        was handled.
1246
1233
        """
 
1234
 
1247
1235
        def handle_callback1(result):
1248
1236
            message_store = self.broker_service.message_store
1249
1237
            messages = message_store.get_pending_messages()
1274
1262
        operation.  The results should be reported in separate
1275
1263
        messages.
1276
1264
        """
 
1265
 
1277
1266
        def handle_callback1(result):
1278
1267
            result = self.manager.dispatch_message(
1279
1268
                {"groupname": "sales", "operation-id": 123,
1298
1287
        result = plugin.run()
1299
1288
        result.addCallback(handle_callback1)
1300
1289
        return result
 
1290
 
 
1291
 
 
1292
class UserManagerTest(LandscapeTest):
 
1293
 
 
1294
    def setUp(self):
 
1295
        super(UserManagerTest, self).setUp()
 
1296
        self.shadow_file = self.makeFile()
 
1297
        self.user_manager = UserManager(shadow_file=self.shadow_file)
 
1298
 
 
1299
    def test_get_locked_usernames(self):
 
1300
        """
 
1301
        The L{UserManager.get_locked_usernames} method returns only user names
 
1302
        of locked users.
 
1303
        """
 
1304
        fd = open(self.shadow_file, "w")
 
1305
        fd.write("jdoe:$1$xFlQvTqe$cBtrNEDOIKMy/BuJoUdeG0:13348:0:99999:7:::\n"
 
1306
                 "psmith:!:13348:0:99999:7:::\n"
 
1307
                 "yo:$1$q7sz09uw$q.A3526M/SHu8vUb.Jo1A/:13349:0:99999:7:::\n")
 
1308
        fd.close()
 
1309
        self.assertEquals(self.user_manager.get_locked_usernames(), ["psmith"])
 
1310
 
 
1311
    def test_get_locked_usernames_with_empty_shadow_file(self):
 
1312
        """
 
1313
        The L{UserManager.get_locked_usernames} method returns an empty C{list}
 
1314
        if the shadow file is empty.
 
1315
        """
 
1316
        fd = open(self.shadow_file, "w")
 
1317
        fd.write("\n")
 
1318
        fd.close()
 
1319
        self.assertEquals(self.user_manager.get_locked_usernames(), [])
 
1320
 
 
1321
    def test_get_locked_usernames_with_non_existing_shadow_file(self):
 
1322
        """
 
1323
        The L{UserManager.get_locked_usernames} method returns an empty C{list}
 
1324
        if the shadow file can't be read.  An error message is logged as well.
 
1325
        """
 
1326
        self.log_helper.ignore_errors("Error reading shadow file.*")
 
1327
        self.assertFalse(os.path.exists(self.shadow_file))
 
1328
        self.assertEquals(self.user_manager.get_locked_usernames(), [])
 
1329
        self.assertIn("Error reading shadow file. [Errno 2] No such file or "
 
1330
                      "directory", self.logfile.getvalue())
 
1331
 
 
1332
 
 
1333
class RemoteUserManagerTest(LandscapeTest):
 
1334
 
 
1335
    helpers = [ManagerHelper]
 
1336
 
 
1337
    def setUp(self):
 
1338
        super(RemoteUserManagerTest, self).setUp()
 
1339
 
 
1340
        def set_remote(remote):
 
1341
            self.remote_user_manager = remote
 
1342
 
 
1343
        self.shadow_file = self.makeFile()
 
1344
        self.user_manager = UserManager(shadow_file=self.shadow_file)
 
1345
        self.user_manager_connector = RemoteUserManagerConnector(self.reactor,
 
1346
                                                                 self.config)
 
1347
        self.user_manager.register(self.manager)
 
1348
        connected = self.user_manager_connector.connect()
 
1349
        return connected.addCallback(set_remote)
 
1350
 
 
1351
    def tearDown(self):
 
1352
        self.user_manager_connector.disconnect()
 
1353
        self.user_manager.stop()
 
1354
        return super(RemoteUserManagerTest, self).tearDown()
 
1355
 
 
1356
    def test_get_locked_usernames(self):
 
1357
        """
 
1358
        The L{get_locked_usernames} method forwards the request to the
 
1359
        remote L{UserManager} object.
 
1360
        """
 
1361
        self.user_manager.get_locked_usernames = self.mocker.mock()
 
1362
        self.expect(self.user_manager.get_locked_usernames()).result(["fred"])
 
1363
        self.mocker.replay()
 
1364
        result = self.remote_user_manager.get_locked_usernames()
 
1365
        return self.assertSuccess(result, ["fred"])