~ubuntu-branches/ubuntu/utopic/freeipa/utopic

« back to all changes in this revision

Viewing changes to ipatests/test_xmlrpc/test_netgroup_plugin.py

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2013-09-03 17:13:27 UTC
  • Revision ID: package-import@ubuntu.com-20130903171327-s3f56x6vxz0o1jq5
Tags: upstream-3.3.4
ImportĀ upstreamĀ versionĀ 3.3.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Authors:
 
2
#   Rob Crittenden <rcritten@redhat.com>
 
3
#   Pavel Zuna <pzuna@redhat.com>
 
4
#
 
5
# Copyright (C) 2009  Red Hat
 
6
# see file 'COPYING' for use and warranty information
 
7
#
 
8
# This program is free software; you can redistribute it and/or modify
 
9
# it under the terms of the GNU General Public License as published by
 
10
# the Free Software Foundation, either version 3 of the License, or
 
11
# (at your option) any later version.
 
12
#
 
13
# This program is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License
 
19
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
"""
 
21
Test the `ipalib/plugins/netgroup.py` module.
 
22
"""
 
23
 
 
24
import nose
 
25
import krbV
 
26
from ipalib import api
 
27
from ipalib import errors
 
28
from ipaserver.plugins.ldap2 import ldap2
 
29
from xmlrpc_test import (Declarative, fuzzy_digits, fuzzy_uuid,
 
30
                         fuzzy_netgroupdn, add_sid, add_oc)
 
31
from ipatests.test_xmlrpc import objectclasses
 
32
from ipapython.dn import DN
 
33
 
 
34
# Global so we can save the value between tests
 
35
netgroup_dn = None
 
36
 
 
37
# See if our LDAP server is up and we can talk to it over GSSAPI
 
38
ccache = krbV.default_context().default_ccache().name
 
39
 
 
40
netgroup1 = u'netgroup1'
 
41
netgroup2 = u'netgroup2'
 
42
netgroup_single = u'a'
 
43
 
 
44
host1 = u'ipatesthost.%s' % api.env.domain
 
45
host_dn1 = DN(('fqdn',host1),('cn','computers'),('cn','accounts'),
 
46
              api.env.basedn)
 
47
 
 
48
unknown_host = u'unknown'
 
49
 
 
50
unknown_host2 = u'unknown2'
 
51
 
 
52
hostgroup1 = u'hg1'
 
53
hostgroup_dn1 = DN(('cn',hostgroup1),('cn','hostgroups'),('cn','accounts'),
 
54
                   api.env.basedn)
 
55
 
 
56
user1 = u'jexample'
 
57
 
 
58
# user2 is a member of testgroup
 
59
user2 = u'pexample'
 
60
 
 
61
group1 = u'testgroup'
 
62
 
 
63
invalidnetgroup1=u'+badnetgroup'
 
64
invalidnisdomain1=u'domain1,domain2'
 
65
invalidnisdomain2=u'+invalidnisdomain'
 
66
invalidhost=u'+invalid&host'
 
67
 
 
68
class test_netgroup(Declarative):
 
69
    """
 
70
    Test the `netgroup` plugin.
 
71
    """
 
72
 
 
73
    cleanup_commands = [
 
74
        ('netgroup_del', [netgroup1], {}),
 
75
        ('netgroup_del', [netgroup2], {}),
 
76
        ('host_del', [host1], {}),
 
77
        ('hostgroup_del', [hostgroup1], {}),
 
78
        ('user_del', [user1], {}),
 
79
        ('user_del', [user2], {}),
 
80
        ('group_del', [group1], {}),
 
81
    ]
 
82
 
 
83
    tests=[
 
84
 
 
85
        dict(
 
86
            desc='Try to retrieve non-existent %r' % netgroup1,
 
87
            command=('netgroup_show', [netgroup1], {}),
 
88
            expected=errors.NotFound(
 
89
                reason=u'%s: netgroup not found' % netgroup1),
 
90
        ),
 
91
 
 
92
 
 
93
        dict(
 
94
            desc='Try to update non-existent %r' % netgroup1,
 
95
            command=('netgroup_mod', [netgroup1],
 
96
                dict(description=u'Updated hostgroup 1')
 
97
            ),
 
98
            expected=errors.NotFound(
 
99
                reason=u'%s: netgroup not found' % netgroup1),
 
100
        ),
 
101
 
 
102
 
 
103
        dict(
 
104
            desc='Try to delete non-existent %r' % netgroup1,
 
105
            command=('netgroup_del', [netgroup1], {}),
 
106
            expected=errors.NotFound(
 
107
                reason=u'%s: netgroup not found' % netgroup1),
 
108
        ),
 
109
 
 
110
 
 
111
        dict(
 
112
            desc='Test an invalid netgroup name %r' % invalidnetgroup1,
 
113
            command=('netgroup_add', [invalidnetgroup1], dict(description=u'Test')),
 
114
            expected=errors.ValidationError(name='name',
 
115
                error=u'may only include letters, numbers, _, -, and .'),
 
116
        ),
 
117
 
 
118
 
 
119
        dict(
 
120
            desc='Test an invalid nisdomain1 name %r' % invalidnisdomain1,
 
121
            command=('netgroup_add', [netgroup1],
 
122
                dict(description=u'Test',nisdomainname=invalidnisdomain1)),
 
123
            expected=errors.ValidationError(name='nisdomain',
 
124
                error='may only include letters, numbers, _, -, and .'),
 
125
        ),
 
126
 
 
127
 
 
128
        dict(
 
129
            desc='Test an invalid nisdomain2 name %r' % invalidnisdomain2,
 
130
            command=('netgroup_add', [netgroup1],
 
131
                dict(description=u'Test',nisdomainname=invalidnisdomain2)),
 
132
            expected=errors.ValidationError(name='nisdomain',
 
133
                error='may only include letters, numbers, _, -, and .'),
 
134
        ),
 
135
 
 
136
 
 
137
        dict(
 
138
            desc='Create %r' % netgroup1,
 
139
            command=('netgroup_add', [netgroup1],
 
140
                dict(description=u'Test netgroup 1')
 
141
            ),
 
142
            expected=dict(
 
143
                value=netgroup1,
 
144
                summary=u'Added netgroup "%s"' % netgroup1,
 
145
                result=dict(
 
146
                    dn=fuzzy_netgroupdn,
 
147
                    cn=[netgroup1],
 
148
                    objectclass=objectclasses.netgroup,
 
149
                    description=[u'Test netgroup 1'],
 
150
                    nisdomainname=['%s' % api.env.domain],
 
151
                    ipauniqueid=[fuzzy_uuid],
 
152
                ),
 
153
            ),
 
154
        ),
 
155
 
 
156
 
 
157
        dict(
 
158
            desc='Create %r' % netgroup2,
 
159
            command=('netgroup_add', [netgroup2],
 
160
                dict(description=u'Test netgroup 2')
 
161
            ),
 
162
            expected=dict(
 
163
                value=netgroup2,
 
164
                summary=u'Added netgroup "%s"' % netgroup2,
 
165
                result=dict(
 
166
                    dn=fuzzy_netgroupdn,
 
167
                    cn=[netgroup2],
 
168
                    objectclass=objectclasses.netgroup,
 
169
                    description=[u'Test netgroup 2'],
 
170
                    nisdomainname=['%s' % api.env.domain],
 
171
                    ipauniqueid=[fuzzy_uuid],
 
172
                ),
 
173
            ),
 
174
        ),
 
175
 
 
176
 
 
177
        dict(
 
178
            desc='Create netgroup with name containing only one letter: %r' % netgroup_single,
 
179
            command=('netgroup_add', [netgroup_single],
 
180
                dict(description=u'Test netgroup_single')
 
181
            ),
 
182
            expected=dict(
 
183
                value=netgroup_single,
 
184
                summary=u'Added netgroup "%s"' % netgroup_single,
 
185
                result=dict(
 
186
                    dn=fuzzy_netgroupdn,
 
187
                    cn=[netgroup_single],
 
188
                    objectclass=objectclasses.netgroup,
 
189
                    description=[u'Test netgroup_single'],
 
190
                    nisdomainname=['%s' % api.env.domain],
 
191
                    ipauniqueid=[fuzzy_uuid],
 
192
                ),
 
193
            ),
 
194
        ),
 
195
 
 
196
 
 
197
        dict(
 
198
            desc='Delete %r' % netgroup_single,
 
199
            command=('netgroup_del', [netgroup_single], {}),
 
200
            expected=dict(
 
201
                value=netgroup_single,
 
202
                summary=u'Deleted netgroup "%s"' % netgroup_single,
 
203
                result=dict(failed=u''),
 
204
            ),
 
205
        ),
 
206
 
 
207
 
 
208
        dict(
 
209
            desc='Try to create duplicate %r' % netgroup1,
 
210
            command=('netgroup_add', [netgroup1],
 
211
                dict(description=u'Test netgroup 1')
 
212
            ),
 
213
            expected=errors.DuplicateEntry(
 
214
                message=u'netgroup with name "%s" already exists' % netgroup1),
 
215
        ),
 
216
 
 
217
 
 
218
        dict(
 
219
            desc='Create host %r' % host1,
 
220
            command=('host_add', [host1],
 
221
                dict(
 
222
                    description=u'Test host 1',
 
223
                    l=u'Undisclosed location 1',
 
224
                    force=True,
 
225
                ),
 
226
            ),
 
227
            expected=dict(
 
228
                value=host1,
 
229
                summary=u'Added host "%s"' % host1,
 
230
                result=dict(
 
231
                    dn=host_dn1,
 
232
                    fqdn=[host1],
 
233
                    description=[u'Test host 1'],
 
234
                    l=[u'Undisclosed location 1'],
 
235
                    krbprincipalname=[u'host/%s@%s' % (host1, api.env.realm)],
 
236
                    objectclass=objectclasses.host,
 
237
                    ipauniqueid=[fuzzy_uuid],
 
238
                    managedby_host=[host1],
 
239
                    has_keytab=False,
 
240
                    has_password=False,
 
241
                ),
 
242
            ),
 
243
        ),
 
244
 
 
245
 
 
246
        dict(
 
247
            desc='Create %r' % hostgroup1,
 
248
            command=('hostgroup_add', [hostgroup1],
 
249
                dict(description=u'Test hostgroup 1')
 
250
            ),
 
251
            expected=dict(
 
252
                value=hostgroup1,
 
253
                summary=u'Added hostgroup "%s"' % hostgroup1,
 
254
                result=dict(
 
255
                    dn=hostgroup_dn1,
 
256
                    cn=[hostgroup1],
 
257
                    objectclass=objectclasses.hostgroup,
 
258
                    description=[u'Test hostgroup 1'],
 
259
                    mepmanagedentry=[DN(('cn',hostgroup1),('cn','ng'),('cn','alt'),
 
260
                                        api.env.basedn)],
 
261
                    ipauniqueid=[fuzzy_uuid],
 
262
                ),
 
263
            ),
 
264
        ),
 
265
 
 
266
 
 
267
        dict(
 
268
            desc='Create %r' % user1,
 
269
            command=(
 
270
                'user_add', [user1], dict(givenname=u'Test', sn=u'User1')
 
271
            ),
 
272
            expected=dict(
 
273
                value=user1,
 
274
                summary=u'Added user "%s"' % user1,
 
275
                result=add_sid(dict(
 
276
                    gecos=[u'Test User1'],
 
277
                    givenname=[u'Test'],
 
278
                    homedirectory=[u'/home/%s' % user1],
 
279
                    krbprincipalname=[u'%s@%s' % (user1, api.env.realm)],
 
280
                    loginshell=[u'/bin/sh'],
 
281
                    objectclass=add_oc(objectclasses.user, u'ipantuserattrs'),
 
282
                    sn=[u'User1'],
 
283
                    uid=[user1],
 
284
                    uidnumber=[fuzzy_digits],
 
285
                    gidnumber=[fuzzy_digits],
 
286
                    mail=[u'%s@%s' % (user1, api.env.domain)],
 
287
                    displayname=[u'Test User1'],
 
288
                    cn=[u'Test User1'],
 
289
                    initials=[u'TU'],
 
290
                    ipauniqueid=[fuzzy_uuid],
 
291
                    mepmanagedentry=[DN(('cn',user1),('cn','groups'),('cn','accounts'),
 
292
                                        api.env.basedn)],
 
293
                    memberof_group=[u'ipausers'],
 
294
                    has_keytab=False,
 
295
                    has_password=False,
 
296
                    dn=DN(('uid',user1),('cn','users'),('cn','accounts'),
 
297
                          api.env.basedn),
 
298
                )),
 
299
            ),
 
300
        ),
 
301
 
 
302
        dict(
 
303
            desc='Create %r' % user2,
 
304
            command=(
 
305
                'user_add', [user2], dict(givenname=u'Test', sn=u'User2')
 
306
            ),
 
307
            expected=dict(
 
308
                value=user2,
 
309
                summary=u'Added user "%s"' % user2,
 
310
                result=add_sid(dict(
 
311
                    gecos=[u'Test User2'],
 
312
                    givenname=[u'Test'],
 
313
                    homedirectory=[u'/home/%s' % user2],
 
314
                    krbprincipalname=[u'%s@%s' % (user2, api.env.realm)],
 
315
                    loginshell=[u'/bin/sh'],
 
316
                    objectclass=add_oc(objectclasses.user, u'ipantuserattrs'),
 
317
                    sn=[u'User2'],
 
318
                    uid=[user2],
 
319
                    uidnumber=[fuzzy_digits],
 
320
                    gidnumber=[fuzzy_digits],
 
321
                    mail=[u'%s@%s' % (user2, api.env.domain)],
 
322
                    displayname=[u'Test User2'],
 
323
                    cn=[u'Test User2'],
 
324
                    initials=[u'TU'],
 
325
                    ipauniqueid=[fuzzy_uuid],
 
326
                    mepmanagedentry=[DN(('cn',user2),('cn','groups'),('cn','accounts'),
 
327
                                        api.env.basedn)],
 
328
                    memberof_group=[u'ipausers'],
 
329
                    has_keytab=False,
 
330
                    has_password=False,
 
331
                    dn=DN(('uid',user2),('cn','users'),('cn','accounts'),
 
332
                          api.env.basedn),
 
333
                )),
 
334
            ),
 
335
        ),
 
336
 
 
337
 
 
338
        dict(
 
339
            desc='Create %r' % group1,
 
340
            command=(
 
341
                'group_add', [group1], dict(description=u'Test desc 1')
 
342
            ),
 
343
            expected=dict(
 
344
                value=group1,
 
345
                summary=u'Added group "%s"' % group1,
 
346
                result=dict(
 
347
                    cn=[group1],
 
348
                    description=[u'Test desc 1'],
 
349
                    gidnumber=[fuzzy_digits],
 
350
                    objectclass=objectclasses.group + [u'posixgroup'],
 
351
                    ipauniqueid=[fuzzy_uuid],
 
352
                    dn=DN(('cn',group1),('cn','groups'),('cn','accounts'),
 
353
                          api.env.basedn),
 
354
                ),
 
355
            ),
 
356
        ),
 
357
 
 
358
 
 
359
        dict(
 
360
            desc='Add user %r to group %r' % (user2, group1),
 
361
            command=(
 
362
                'group_add_member', [group1], dict(user=user2)
 
363
            ),
 
364
            expected=dict(
 
365
                completed=1,
 
366
                failed=dict(
 
367
                    member=dict(
 
368
                        group=tuple(),
 
369
                        user=tuple(),
 
370
                    ),
 
371
                ),
 
372
                result={
 
373
                        'dn': DN(('cn',group1),('cn','groups'),('cn','accounts'),
 
374
                                 api.env.basedn),
 
375
                        'member_user': (user2,),
 
376
                        'gidnumber': [fuzzy_digits],
 
377
                        'cn': [group1],
 
378
                        'description': [u'Test desc 1'],
 
379
                },
 
380
            ),
 
381
        ),
 
382
 
 
383
 
 
384
        dict(
 
385
            desc='Add invalid host %r to netgroup %r' % (invalidhost, netgroup1),
 
386
            command=('netgroup_add_member', [netgroup1], dict(host=invalidhost)),
 
387
            expected=errors.ValidationError(name='host',
 
388
             error='only letters, numbers, _, and - are allowed. ' +
 
389
                    u'DNS label may not start or end with -'),
 
390
        ),
 
391
 
 
392
 
 
393
        dict(
 
394
            desc='Add host %r to netgroup %r' % (host1, netgroup1),
 
395
            command=(
 
396
                'netgroup_add_member', [netgroup1], dict(host=host1)
 
397
            ),
 
398
            expected=dict(
 
399
                completed=1,
 
400
                failed=dict(
 
401
                    member=dict(
 
402
                        netgroup=tuple(),
 
403
                    ),
 
404
                    memberuser=dict(
 
405
                        group=tuple(),
 
406
                        user=tuple(),
 
407
                    ),
 
408
                    memberhost=dict(
 
409
                        hostgroup=tuple(),
 
410
                        host=tuple(),
 
411
                    ),
 
412
                ),
 
413
                result={
 
414
                        'dn': fuzzy_netgroupdn,
 
415
                        'memberhost_host': (host1,),
 
416
                        'cn': [netgroup1],
 
417
                        'description': [u'Test netgroup 1'],
 
418
                        'nisdomainname': [u'%s' % api.env.domain],
 
419
                },
 
420
            ),
 
421
        ),
 
422
 
 
423
 
 
424
        dict(
 
425
            desc='Add hostgroup %r to netgroup %r' % (hostgroup1, netgroup1),
 
426
            command=(
 
427
                'netgroup_add_member', [netgroup1], dict(hostgroup=hostgroup1)
 
428
            ),
 
429
            expected=dict(
 
430
                completed=1,
 
431
                failed=dict(
 
432
                    member=dict(
 
433
                        netgroup=tuple(),
 
434
                    ),
 
435
                    memberuser=dict(
 
436
                        group=tuple(),
 
437
                        user=tuple(),
 
438
                    ),
 
439
                    memberhost=dict(
 
440
                        hostgroup=tuple(),
 
441
                        host=tuple(),
 
442
                    ),
 
443
                ),
 
444
                result={
 
445
                        'dn': fuzzy_netgroupdn,
 
446
                        'memberhost_host': (host1,),
 
447
                        'memberhost_hostgroup': (hostgroup1,),
 
448
                        'cn': [netgroup1],
 
449
                        'description': [u'Test netgroup 1'],
 
450
                        'nisdomainname': [u'%s' % api.env.domain],
 
451
                },
 
452
            ),
 
453
        ),
 
454
 
 
455
 
 
456
        dict(
 
457
            desc='Search for netgroups using no_user',
 
458
            command=('netgroup_find', [], dict(no_user=user1)),
 
459
            expected=dict(
 
460
                count=2,
 
461
                truncated=False,
 
462
                summary=u'2 netgroups matched',
 
463
                result=[
 
464
                    {
 
465
                        'dn': fuzzy_netgroupdn,
 
466
                        'memberhost_host': (host1,),
 
467
                        'memberhost_hostgroup': (hostgroup1,),
 
468
                        'cn': [netgroup1],
 
469
                        'description': [u'Test netgroup 1'],
 
470
                        'nisdomainname': [u'%s' % api.env.domain],
 
471
                    },
 
472
                    {
 
473
                        'dn': fuzzy_netgroupdn,
 
474
                        'cn': [netgroup2],
 
475
                        'description': [u'Test netgroup 2'],
 
476
                        'nisdomainname': [u'%s' % api.env.domain],
 
477
                    },
 
478
                ],
 
479
            ),
 
480
        ),
 
481
 
 
482
        dict(
 
483
            desc="Check %r doesn't match when searching for %s" % (netgroup1, user1),
 
484
            command=('netgroup_find', [], dict(user=user1)),
 
485
            expected=dict(
 
486
                count=0,
 
487
                truncated=False,
 
488
                summary=u'0 netgroups matched',
 
489
                result=[],
 
490
            ),
 
491
        ),
 
492
 
 
493
        dict(
 
494
            desc='Add user %r to netgroup %r' % (user1, netgroup1),
 
495
            command=(
 
496
                'netgroup_add_member', [netgroup1], dict(user=user1)
 
497
            ),
 
498
            expected=dict(
 
499
                completed=1,
 
500
                failed=dict(
 
501
                    member=dict(
 
502
                        netgroup=tuple(),
 
503
                    ),
 
504
                    memberuser=dict(
 
505
                        group=tuple(),
 
506
                        user=tuple(),
 
507
                    ),
 
508
                    memberhost=dict(
 
509
                        hostgroup=tuple(),
 
510
                        host=tuple(),
 
511
                    ),
 
512
                ),
 
513
                result={
 
514
                        'dn': fuzzy_netgroupdn,
 
515
                        'memberhost_host': (host1,),
 
516
                        'memberhost_hostgroup': (hostgroup1,),
 
517
                        'memberuser_user': (user1,),
 
518
                        'cn': [netgroup1],
 
519
                        'description': [u'Test netgroup 1'],
 
520
                        'nisdomainname': [u'%s' % api.env.domain],
 
521
                },
 
522
            ),
 
523
        ),
 
524
 
 
525
        dict(
 
526
            desc="Check %r doesn't match when searching for no %s" % (netgroup1, user1),
 
527
            command=('netgroup_find', [], dict(no_user=user1)),
 
528
            expected=dict(
 
529
                count=1,
 
530
                truncated=False,
 
531
                summary=u'1 netgroup matched',
 
532
                result=[
 
533
                    {
 
534
                        'dn': fuzzy_netgroupdn,
 
535
                        'cn': [netgroup2],
 
536
                        'description': [u'Test netgroup 2'],
 
537
                        'nisdomainname': [u'%s' % api.env.domain],
 
538
                    },
 
539
                ],
 
540
            ),
 
541
        ),
 
542
 
 
543
        dict(
 
544
            desc='Add group %r to netgroup %r' % (group1, netgroup1),
 
545
            command=(
 
546
                'netgroup_add_member', [netgroup1], dict(group=group1)
 
547
            ),
 
548
            expected=dict(
 
549
                completed=1,
 
550
                failed=dict(
 
551
                    member=dict(
 
552
                        netgroup=tuple(),
 
553
                    ),
 
554
                    memberuser=dict(
 
555
                        group=tuple(),
 
556
                        user=tuple(),
 
557
                    ),
 
558
                    memberhost=dict(
 
559
                        hostgroup=tuple(),
 
560
                        host=tuple(),
 
561
                    ),
 
562
                ),
 
563
                result={
 
564
                        'dn': fuzzy_netgroupdn,
 
565
                        'memberhost_host': (host1,),
 
566
                        'memberhost_hostgroup': (hostgroup1,),
 
567
                        'memberuser_user': (user1,),
 
568
                        'memberuser_group': (group1,),
 
569
                        'cn': [netgroup1],
 
570
                        'description': [u'Test netgroup 1'],
 
571
                        'nisdomainname': [u'%s' % api.env.domain],
 
572
                },
 
573
            ),
 
574
        ),
 
575
 
 
576
 
 
577
        dict(
 
578
            desc='Add netgroup %r to netgroup %r' % (netgroup2, netgroup1),
 
579
            command=(
 
580
                'netgroup_add_member', [netgroup1], dict(netgroup=netgroup2)
 
581
            ),
 
582
            expected=dict(
 
583
                completed=1,
 
584
                failed=dict(
 
585
                    member=dict(
 
586
                        netgroup=tuple(),
 
587
                    ),
 
588
                    memberuser=dict(
 
589
                        group=tuple(),
 
590
                        user=tuple(),
 
591
                    ),
 
592
                    memberhost=dict(
 
593
                        hostgroup=tuple(),
 
594
                        host=tuple(),
 
595
                    ),
 
596
                ),
 
597
                result={
 
598
                        'dn': fuzzy_netgroupdn,
 
599
                        'memberhost_host': (host1,),
 
600
                        'memberhost_hostgroup': (hostgroup1,),
 
601
                        'memberuser_user': (user1,),
 
602
                        'memberuser_group': (group1,),
 
603
                        'member_netgroup': (netgroup2,),
 
604
                        'cn': [netgroup1],
 
605
                        'description': [u'Test netgroup 1'],
 
606
                        'nisdomainname': [u'%s' % api.env.domain],
 
607
                },
 
608
            ),
 
609
        ),
 
610
 
 
611
 
 
612
        dict(
 
613
            desc='Add non-existent netgroup to netgroup %r' % (netgroup1),
 
614
            command=(
 
615
                'netgroup_add_member', [netgroup1], dict(netgroup=u'notfound')
 
616
            ),
 
617
            expected=dict(
 
618
                completed=0,
 
619
                failed=dict(
 
620
                    member=dict(
 
621
                        netgroup=[(u'notfound', u'no such entry')],
 
622
                    ),
 
623
                    memberuser=dict(
 
624
                        group=tuple(),
 
625
                        user=tuple(),
 
626
                    ),
 
627
                    memberhost=dict(
 
628
                        hostgroup=tuple(),
 
629
                        host=tuple(),
 
630
                    ),
 
631
                ),
 
632
                result={
 
633
                        'dn': fuzzy_netgroupdn,
 
634
                        'memberhost_host': (host1,),
 
635
                        'memberhost_hostgroup': (hostgroup1,),
 
636
                        'memberuser_user': (user1,),
 
637
                        'memberuser_group': (group1,),
 
638
                        'member_netgroup': (netgroup2,),
 
639
                        'cn': [netgroup1],
 
640
                        'description': [u'Test netgroup 1'],
 
641
                        'nisdomainname': [u'%s' % api.env.domain],
 
642
                },
 
643
            ),
 
644
        ),
 
645
 
 
646
 
 
647
        dict(
 
648
            desc='Add duplicate user %r to netgroup %r' % (user1, netgroup1),
 
649
            command=(
 
650
                'netgroup_add_member', [netgroup1], dict(user=user1)
 
651
            ),
 
652
            expected=dict(
 
653
                completed=0,
 
654
                failed=dict(
 
655
                    member=dict(
 
656
                        netgroup=tuple(),
 
657
                    ),
 
658
                    memberuser=dict(
 
659
                        group=tuple(),
 
660
                        user=[('%s' % user1, u'This entry is already a member')],
 
661
                    ),
 
662
                    memberhost=dict(
 
663
                        hostgroup=tuple(),
 
664
                        host=tuple(),
 
665
                    ),
 
666
                ),
 
667
                result={
 
668
                        'dn': fuzzy_netgroupdn,
 
669
                        'memberhost_host': (host1,),
 
670
                        'memberhost_hostgroup': (hostgroup1,),
 
671
                        'memberuser_user': (user1,),
 
672
                        'memberuser_group': (group1,),
 
673
                        'member_netgroup': (netgroup2,),
 
674
                        'cn': [netgroup1],
 
675
                        'description': [u'Test netgroup 1'],
 
676
                        'nisdomainname': [u'%s' % api.env.domain],
 
677
                },
 
678
            ),
 
679
        ),
 
680
 
 
681
        dict(
 
682
            desc='Add duplicate group %r to netgroup %r' % (group1, netgroup1),
 
683
            command=(
 
684
                'netgroup_add_member', [netgroup1], dict(group=group1)
 
685
            ),
 
686
            expected=dict(
 
687
                completed=0,
 
688
                failed=dict(
 
689
                    member=dict(
 
690
                        netgroup=tuple(),
 
691
                    ),
 
692
                    memberuser=dict(
 
693
                        group=[('%s' % group1, u'This entry is already a member')],
 
694
                        user=tuple(),
 
695
                    ),
 
696
                    memberhost=dict(
 
697
                        hostgroup=tuple(),
 
698
                        host=tuple(),
 
699
                    ),
 
700
                ),
 
701
                result={
 
702
                        'dn': fuzzy_netgroupdn,
 
703
                        'memberhost_host': (host1,),
 
704
                        'memberhost_hostgroup': (hostgroup1,),
 
705
                        'memberuser_user': (user1,),
 
706
                        'memberuser_group': (group1,),
 
707
                        'member_netgroup': (netgroup2,),
 
708
                        'cn': [netgroup1],
 
709
                        'description': [u'Test netgroup 1'],
 
710
                        'nisdomainname': [u'%s' % api.env.domain],
 
711
                },
 
712
            ),
 
713
        ),
 
714
 
 
715
 
 
716
        dict(
 
717
            desc='Add duplicate host %r to netgroup %r' % (host1, netgroup1),
 
718
            command=(
 
719
                'netgroup_add_member', [netgroup1], dict(host=host1)
 
720
            ),
 
721
            expected=dict(
 
722
                completed=0,
 
723
                failed=dict(
 
724
                    member=dict(
 
725
                        netgroup=tuple(),
 
726
                    ),
 
727
                    memberuser=dict(
 
728
                        group=tuple(),
 
729
                        user=tuple(),
 
730
                    ),
 
731
                    memberhost=dict(
 
732
                        hostgroup=tuple(),
 
733
                        host=[('%s' % host1, u'This entry is already a member')],
 
734
                    ),
 
735
                ),
 
736
                result={
 
737
                        'dn': fuzzy_netgroupdn,
 
738
                        'memberhost_host': (host1,),
 
739
                        'memberhost_hostgroup': (hostgroup1,),
 
740
                        'memberuser_user': (user1,),
 
741
                        'memberuser_group': (group1,),
 
742
                        'member_netgroup': (netgroup2,),
 
743
                        'cn': [netgroup1],
 
744
                        'description': [u'Test netgroup 1'],
 
745
                        'nisdomainname': [u'%s' % api.env.domain],
 
746
                },
 
747
            ),
 
748
        ),
 
749
 
 
750
 
 
751
        dict(
 
752
            desc='Add duplicate hostgroup %r to netgroup %r' % (hostgroup1, netgroup1),
 
753
            command=(
 
754
                'netgroup_add_member', [netgroup1], dict(hostgroup=hostgroup1)
 
755
            ),
 
756
            expected=dict(
 
757
                completed=0,
 
758
                failed=dict(
 
759
                    member=dict(
 
760
                        netgroup=tuple(),
 
761
                    ),
 
762
                    memberuser=dict(
 
763
                        group=tuple(),
 
764
                        user=tuple(),
 
765
                    ),
 
766
                    memberhost=dict(
 
767
                        hostgroup=[('%s' % hostgroup1, u'This entry is already a member')],
 
768
                        host=tuple(),
 
769
                    ),
 
770
                ),
 
771
                result={
 
772
                        'dn': fuzzy_netgroupdn,
 
773
                        'memberhost_host': (host1,),
 
774
                        'memberhost_hostgroup': (hostgroup1,),
 
775
                        'memberuser_user': (user1,),
 
776
                        'memberuser_group': (group1,),
 
777
                        'member_netgroup': (netgroup2,),
 
778
                        'cn': [netgroup1],
 
779
                        'description': [u'Test netgroup 1'],
 
780
                        'nisdomainname': [u'%s' % api.env.domain],
 
781
                },
 
782
            ),
 
783
        ),
 
784
 
 
785
 
 
786
        dict(
 
787
            desc='Add unknown host %r to netgroup %r' % (unknown_host, netgroup1),
 
788
            command=(
 
789
                'netgroup_add_member', [netgroup1], dict(host=unknown_host)
 
790
            ),
 
791
            expected=dict(
 
792
                completed=1,
 
793
                failed=dict(
 
794
                    member=dict(
 
795
                        netgroup=tuple(),
 
796
                    ),
 
797
                    memberuser=dict(
 
798
                        group=tuple(),
 
799
                        user=tuple(),
 
800
                    ),
 
801
                    memberhost=dict(
 
802
                        hostgroup=tuple(),
 
803
                        host=tuple(),
 
804
                    ),
 
805
                ),
 
806
                result={
 
807
                        'dn': fuzzy_netgroupdn,
 
808
                        'memberhost_host': (host1,),
 
809
                        'memberhost_hostgroup': (hostgroup1,),
 
810
                        'memberuser_user': (user1,),
 
811
                        'memberuser_group': (group1,),
 
812
                        'member_netgroup': (netgroup2,),
 
813
                        'cn': [netgroup1],
 
814
                        'description': [u'Test netgroup 1'],
 
815
                        'nisdomainname': [u'%s' % api.env.domain],
 
816
                        'externalhost': [unknown_host],
 
817
                },
 
818
            ),
 
819
        ),
 
820
 
 
821
        dict(
 
822
            desc='Add invalid host %r to netgroup %r using setattr' %
 
823
                (invalidhost, netgroup1),
 
824
            command=(
 
825
                'netgroup_mod', [netgroup1],
 
826
                dict(setattr='externalhost=%s' % invalidhost)
 
827
            ),
 
828
            expected=errors.ValidationError(name='externalhost',
 
829
                error='only letters, numbers, _, and - are allowed. ' +
 
830
                    'DNS label may not start or end with -'),
 
831
        ),
 
832
 
 
833
        dict(
 
834
            desc='Add unknown host %r to netgroup %r using addattr' %
 
835
                (unknown_host2, netgroup1),
 
836
            command=(
 
837
                'netgroup_mod', [netgroup1],
 
838
                dict(addattr='externalhost=%s' % unknown_host2)
 
839
            ),
 
840
            expected=dict(
 
841
                value=u'netgroup1',
 
842
                summary=u'Modified netgroup "netgroup1"',
 
843
                result={
 
844
                        'memberhost_host': (host1,),
 
845
                        'memberhost_hostgroup': (hostgroup1,),
 
846
                        'memberuser_user': (user1,),
 
847
                        'memberuser_group': (group1,),
 
848
                        'member_netgroup': (netgroup2,),
 
849
                        'cn': [netgroup1],
 
850
                        'description': [u'Test netgroup 1'],
 
851
                        'nisdomainname': [u'%s' % api.env.domain],
 
852
                        'externalhost': [unknown_host, unknown_host2],
 
853
                },
 
854
            )
 
855
        ),
 
856
 
 
857
        dict(
 
858
            desc='Remove unknown host %r from netgroup %r using delattr' %
 
859
                (unknown_host2, netgroup1),
 
860
            command=(
 
861
                'netgroup_mod', [netgroup1],
 
862
                dict(delattr='externalhost=%s' % unknown_host2)
 
863
            ),
 
864
            expected=dict(
 
865
                value=u'netgroup1',
 
866
                summary=u'Modified netgroup "netgroup1"',
 
867
                result={
 
868
                        'memberhost_host': (host1,),
 
869
                        'memberhost_hostgroup': (hostgroup1,),
 
870
                        'memberuser_user': (user1,),
 
871
                        'memberuser_group': (group1,),
 
872
                        'member_netgroup': (netgroup2,),
 
873
                        'cn': [netgroup1],
 
874
                        'description': [u'Test netgroup 1'],
 
875
                        'nisdomainname': [u'%s' % api.env.domain],
 
876
                        'externalhost': [unknown_host],
 
877
                },
 
878
            )
 
879
        ),
 
880
 
 
881
        dict(
 
882
            desc='Retrieve %r' % netgroup1,
 
883
            command=('netgroup_show', [netgroup1], {}),
 
884
            expected=dict(
 
885
                value=netgroup1,
 
886
                summary=None,
 
887
                result={
 
888
                        'dn': fuzzy_netgroupdn,
 
889
                        'memberhost_host': (host1,),
 
890
                        'memberhost_hostgroup': (hostgroup1,),
 
891
                        'memberuser_user': (user1,),
 
892
                        'memberuser_group': (group1,),
 
893
                        'member_netgroup': (netgroup2,),
 
894
                        'cn': [netgroup1],
 
895
                        'description': [u'Test netgroup 1'],
 
896
                        'nisdomainname': [u'%s' % api.env.domain],
 
897
                        'externalhost': [unknown_host],
 
898
                },
 
899
            ),
 
900
        ),
 
901
 
 
902
        dict(
 
903
            desc='Search for %r' % netgroup1,
 
904
            command=('netgroup_find', [], dict(cn=netgroup1)),
 
905
            expected=dict(
 
906
                count=1,
 
907
                truncated=False,
 
908
                summary=u'1 netgroup matched',
 
909
                result=[
 
910
                    {
 
911
                        'dn': fuzzy_netgroupdn,
 
912
                        'memberhost_host': (host1,),
 
913
                        'memberhost_hostgroup': (hostgroup1,),
 
914
                        'memberuser_user': (user1,),
 
915
                        'memberuser_group': (group1,),
 
916
                        'member_netgroup': (netgroup2,),
 
917
                        'cn': [netgroup1],
 
918
                        'description': [u'Test netgroup 1'],
 
919
                        'nisdomainname': [u'%s' % api.env.domain],
 
920
                        'externalhost': [unknown_host],
 
921
                    },
 
922
                ],
 
923
            ),
 
924
        ),
 
925
 
 
926
        dict(
 
927
            desc='Search for %r using user' % netgroup1,
 
928
            command=('netgroup_find', [], dict(user=user1)),
 
929
            expected=dict(
 
930
                count=1,
 
931
                truncated=False,
 
932
                summary=u'1 netgroup matched',
 
933
                result=[
 
934
                    {
 
935
                        'dn': fuzzy_netgroupdn,
 
936
                        'memberhost_host': (host1,),
 
937
                        'memberhost_hostgroup': (hostgroup1,),
 
938
                        'memberuser_user': (user1,),
 
939
                        'memberuser_group': (group1,),
 
940
                        'member_netgroup': (netgroup2,),
 
941
                        'cn': [netgroup1],
 
942
                        'description': [u'Test netgroup 1'],
 
943
                        'nisdomainname': [u'%s' % api.env.domain],
 
944
                        'externalhost': [unknown_host],
 
945
                    },
 
946
                ],
 
947
            ),
 
948
        ),
 
949
 
 
950
        dict(
 
951
            desc='Search for all netgroups using empty member user',
 
952
            command=('netgroup_find', [], dict(user=None)),
 
953
            expected=dict(
 
954
                count=2,
 
955
                truncated=False,
 
956
                summary=u'2 netgroups matched',
 
957
                result=[
 
958
                    {
 
959
                        'dn': fuzzy_netgroupdn,
 
960
                        'memberhost_host': (host1,),
 
961
                        'memberhost_hostgroup': (hostgroup1,),
 
962
                        'memberuser_user': (user1,),
 
963
                        'memberuser_group': (group1,),
 
964
                        'member_netgroup': (netgroup2,),
 
965
                        'cn': [netgroup1],
 
966
                        'description': [u'Test netgroup 1'],
 
967
                        'nisdomainname': [u'%s' % api.env.domain],
 
968
                        'externalhost': [unknown_host],
 
969
                    },
 
970
                    {
 
971
                        'dn': fuzzy_netgroupdn,
 
972
                        'memberof_netgroup': (netgroup1,),
 
973
                        'cn': [netgroup2],
 
974
                        'description': [u'Test netgroup 2'],
 
975
                        'nisdomainname': [u'%s' % api.env.domain],
 
976
                    },
 
977
                ],
 
978
            ),
 
979
        ),
 
980
 
 
981
        dict(
 
982
            desc='Update %r' % netgroup1,
 
983
            command=('netgroup_mod', [netgroup1],
 
984
                dict(description=u'Updated netgroup 1')
 
985
            ),
 
986
            expected=dict(
 
987
                value=netgroup1,
 
988
                summary=u'Modified netgroup "%s"' % netgroup1,
 
989
                result={
 
990
                        'memberhost_host': (host1,),
 
991
                        'memberhost_hostgroup': (hostgroup1,),
 
992
                        'memberuser_user': (user1,),
 
993
                        'memberuser_group': (group1,),
 
994
                        'member_netgroup': (netgroup2,),
 
995
                        'cn': [netgroup1],
 
996
                        'description': [u'Updated netgroup 1'],
 
997
                        'nisdomainname': [u'%s' % api.env.domain],
 
998
                        'externalhost': [unknown_host],
 
999
                },
 
1000
            ),
 
1001
        ),
 
1002
 
 
1003
 
 
1004
        dict(
 
1005
            desc='Remove host %r from netgroup %r' % (host1, netgroup1),
 
1006
            command=(
 
1007
                'netgroup_remove_member', [netgroup1], dict(host=host1)
 
1008
            ),
 
1009
            expected=dict(
 
1010
                completed=1,
 
1011
                failed=dict(
 
1012
                    member=dict(
 
1013
                        netgroup=tuple(),
 
1014
                    ),
 
1015
                    memberuser=dict(
 
1016
                        group=tuple(),
 
1017
                        user=tuple(),
 
1018
                    ),
 
1019
                    memberhost=dict(
 
1020
                        hostgroup=tuple(),
 
1021
                        host=tuple(),
 
1022
                    ),
 
1023
                ),
 
1024
                result={
 
1025
                        'dn': fuzzy_netgroupdn,
 
1026
                        'memberhost_hostgroup': (hostgroup1,),
 
1027
                        'memberuser_user': (user1,),
 
1028
                        'memberuser_group': (group1,),
 
1029
                        'member_netgroup': (netgroup2,),
 
1030
                        'cn': [netgroup1],
 
1031
                        'description': [u'Updated netgroup 1'],
 
1032
                        'nisdomainname': [u'%s' % api.env.domain],
 
1033
                        'externalhost': [unknown_host],
 
1034
                },
 
1035
            ),
 
1036
        ),
 
1037
 
 
1038
 
 
1039
        dict(
 
1040
            desc='Remove hostgroup %r from netgroup %r' % (hostgroup1, netgroup1),
 
1041
            command=(
 
1042
                'netgroup_remove_member', [netgroup1], dict(hostgroup=hostgroup1)
 
1043
            ),
 
1044
            expected=dict(
 
1045
                completed=1,
 
1046
                failed=dict(
 
1047
                    member=dict(
 
1048
                        netgroup=tuple(),
 
1049
                    ),
 
1050
                    memberuser=dict(
 
1051
                        group=tuple(),
 
1052
                        user=tuple(),
 
1053
                    ),
 
1054
                    memberhost=dict(
 
1055
                        hostgroup=tuple(),
 
1056
                        host=tuple(),
 
1057
                    ),
 
1058
                ),
 
1059
                result={
 
1060
                        'dn': fuzzy_netgroupdn,
 
1061
                        'memberuser_user': (user1,),
 
1062
                        'memberuser_group': (group1,),
 
1063
                        'member_netgroup': (netgroup2,),
 
1064
                        'cn': [netgroup1],
 
1065
                        'description': [u'Updated netgroup 1'],
 
1066
                        'nisdomainname': [u'%s' % api.env.domain],
 
1067
                        'externalhost': [unknown_host],
 
1068
                },
 
1069
            ),
 
1070
        ),
 
1071
 
 
1072
 
 
1073
        dict(
 
1074
            desc='Remove user %r from netgroup %r' % (user1, netgroup1),
 
1075
            command=(
 
1076
                'netgroup_remove_member', [netgroup1], dict(user=user1)
 
1077
            ),
 
1078
            expected=dict(
 
1079
                completed=1,
 
1080
                failed=dict(
 
1081
                    member=dict(
 
1082
                        netgroup=tuple(),
 
1083
                    ),
 
1084
                    memberuser=dict(
 
1085
                        group=tuple(),
 
1086
                        user=tuple(),
 
1087
                    ),
 
1088
                    memberhost=dict(
 
1089
                        hostgroup=tuple(),
 
1090
                        host=tuple(),
 
1091
                    ),
 
1092
                ),
 
1093
                result={
 
1094
                        'dn': fuzzy_netgroupdn,
 
1095
                        'memberuser_group': (group1,),
 
1096
                        'member_netgroup': (netgroup2,),
 
1097
                        'cn': [netgroup1],
 
1098
                        'description': [u'Updated netgroup 1'],
 
1099
                        'nisdomainname': [u'%s' % api.env.domain],
 
1100
                        'externalhost': [unknown_host],
 
1101
                },
 
1102
            ),
 
1103
        ),
 
1104
 
 
1105
 
 
1106
        dict(
 
1107
            desc='Remove group %r from netgroup %r' % (group1, netgroup1),
 
1108
            command=(
 
1109
                'netgroup_remove_member', [netgroup1], dict(group=group1)
 
1110
            ),
 
1111
            expected=dict(
 
1112
                completed=1,
 
1113
                failed=dict(
 
1114
                    member=dict(
 
1115
                        netgroup=tuple(),
 
1116
                    ),
 
1117
                    memberuser=dict(
 
1118
                        group=tuple(),
 
1119
                        user=tuple(),
 
1120
                    ),
 
1121
                    memberhost=dict(
 
1122
                        hostgroup=tuple(),
 
1123
                        host=tuple(),
 
1124
                    ),
 
1125
                ),
 
1126
                result={
 
1127
                        'dn': fuzzy_netgroupdn,
 
1128
                        'member_netgroup': (netgroup2,),
 
1129
                        'cn': [netgroup1],
 
1130
                        'description': [u'Updated netgroup 1'],
 
1131
                        'nisdomainname': [u'%s' % api.env.domain],
 
1132
                        'externalhost': [unknown_host],
 
1133
                },
 
1134
            ),
 
1135
        ),
 
1136
 
 
1137
 
 
1138
        dict(
 
1139
            desc='Remove netgroup %r from netgroup %r' % (netgroup2, netgroup1),
 
1140
            command=(
 
1141
                'netgroup_remove_member', [netgroup1], dict(netgroup=netgroup2)
 
1142
            ),
 
1143
            expected=dict(
 
1144
                completed=1,
 
1145
                failed=dict(
 
1146
                    member=dict(
 
1147
                        netgroup=tuple(),
 
1148
                    ),
 
1149
                    memberuser=dict(
 
1150
                        group=tuple(),
 
1151
                        user=tuple(),
 
1152
                    ),
 
1153
                    memberhost=dict(
 
1154
                        hostgroup=tuple(),
 
1155
                        host=tuple(),
 
1156
                    ),
 
1157
                ),
 
1158
                result={
 
1159
                        'dn': fuzzy_netgroupdn,
 
1160
                        'cn': [netgroup1],
 
1161
                        'description': [u'Updated netgroup 1'],
 
1162
                        'nisdomainname': [u'%s' % api.env.domain],
 
1163
                        'externalhost': [unknown_host],
 
1164
                },
 
1165
            ),
 
1166
        ),
 
1167
 
 
1168
 
 
1169
        dict(
 
1170
            desc='Remove host %r from netgroup %r again' % (host1, netgroup1),
 
1171
            command=(
 
1172
                'netgroup_remove_member', [netgroup1], dict(host=host1)
 
1173
            ),
 
1174
            expected=dict(
 
1175
                completed=0,
 
1176
                failed=dict(
 
1177
                    member=dict(
 
1178
                        netgroup=tuple(),
 
1179
                    ),
 
1180
                    memberuser=dict(
 
1181
                        group=tuple(),
 
1182
                        user=tuple(),
 
1183
                    ),
 
1184
                    memberhost=dict(
 
1185
                        hostgroup=tuple(),
 
1186
                        host=[('%s' % host1, u'This entry is not a member')]
 
1187
                    ),
 
1188
                ),
 
1189
                result={
 
1190
                        'dn': fuzzy_netgroupdn,
 
1191
                        'cn': [netgroup1],
 
1192
                        'description': [u'Updated netgroup 1'],
 
1193
                        'nisdomainname': [u'%s' % api.env.domain],
 
1194
                        'externalhost': [unknown_host],
 
1195
                },
 
1196
            ),
 
1197
        ),
 
1198
 
 
1199
 
 
1200
        dict(
 
1201
            desc='Remove hostgroup %r from netgroup %r again' % (hostgroup1, netgroup1),
 
1202
            command=(
 
1203
                'netgroup_remove_member', [netgroup1], dict(hostgroup=hostgroup1)
 
1204
            ),
 
1205
            expected=dict(
 
1206
                completed=0,
 
1207
                failed=dict(
 
1208
                    member=dict(
 
1209
                        netgroup=tuple(),
 
1210
                    ),
 
1211
                    memberuser=dict(
 
1212
                        group=tuple(),
 
1213
                        user=tuple(),
 
1214
                    ),
 
1215
                    memberhost=dict(
 
1216
                        hostgroup=[('%s' % hostgroup1, u'This entry is not a member')],
 
1217
                        host=tuple(),
 
1218
                    ),
 
1219
                ),
 
1220
                result={
 
1221
                        'dn': fuzzy_netgroupdn,
 
1222
                        'cn': [netgroup1],
 
1223
                        'description': [u'Updated netgroup 1'],
 
1224
                        'nisdomainname': [u'%s' % api.env.domain],
 
1225
                        'externalhost': [unknown_host],
 
1226
                },
 
1227
            ),
 
1228
        ),
 
1229
 
 
1230
 
 
1231
        dict(
 
1232
            desc='Remove user %r from netgroup %r again' % (user1, netgroup1),
 
1233
            command=(
 
1234
                'netgroup_remove_member', [netgroup1], dict(user=user1)
 
1235
            ),
 
1236
            expected=dict(
 
1237
                completed=0,
 
1238
                failed=dict(
 
1239
                    member=dict(
 
1240
                        netgroup=tuple(),
 
1241
                    ),
 
1242
                    memberuser=dict(
 
1243
                        group=tuple(),
 
1244
                        user=[('%s' % user1, u'This entry is not a member')],
 
1245
                    ),
 
1246
                    memberhost=dict(
 
1247
                        hostgroup=tuple(),
 
1248
                        host=tuple(),
 
1249
                    ),
 
1250
                ),
 
1251
                result={
 
1252
                        'dn': fuzzy_netgroupdn,
 
1253
                        'cn': [netgroup1],
 
1254
                        'description': [u'Updated netgroup 1'],
 
1255
                        'nisdomainname': [u'%s' % api.env.domain],
 
1256
                        'externalhost': [unknown_host],
 
1257
                },
 
1258
            ),
 
1259
        ),
 
1260
 
 
1261
 
 
1262
        dict(
 
1263
            desc='Remove group %r from netgroup %r again' % (group1, netgroup1),
 
1264
            command=(
 
1265
                'netgroup_remove_member', [netgroup1], dict(group=group1)
 
1266
            ),
 
1267
            expected=dict(
 
1268
                completed=0,
 
1269
                failed=dict(
 
1270
                    member=dict(
 
1271
                        netgroup=tuple(),
 
1272
                    ),
 
1273
                    memberuser=dict(
 
1274
                        group= [('%s' % group1, u'This entry is not a member')],
 
1275
                        user=tuple(),
 
1276
                    ),
 
1277
                    memberhost=dict(
 
1278
                        hostgroup=tuple(),
 
1279
                        host=tuple(),
 
1280
                    ),
 
1281
                ),
 
1282
                result={
 
1283
                        'dn': fuzzy_netgroupdn,
 
1284
                        'cn': [netgroup1],
 
1285
                        'description': [u'Updated netgroup 1'],
 
1286
                        'nisdomainname': [u'%s' % api.env.domain],
 
1287
                        'externalhost': [unknown_host],
 
1288
                },
 
1289
            ),
 
1290
        ),
 
1291
 
 
1292
 
 
1293
        dict(
 
1294
            desc='Remove netgroup %r from netgroup %r again' % (netgroup2, netgroup1),
 
1295
            command=(
 
1296
                'netgroup_remove_member', [netgroup1], dict(netgroup=netgroup2)
 
1297
            ),
 
1298
            expected=dict(
 
1299
                completed=0,
 
1300
                failed=dict(
 
1301
                    member=dict(
 
1302
                        netgroup=[('%s' % netgroup2, u'This entry is not a member')],
 
1303
                    ),
 
1304
                    memberuser=dict(
 
1305
                        group=tuple(),
 
1306
                        user=tuple(),
 
1307
                    ),
 
1308
                    memberhost=dict(
 
1309
                        hostgroup=tuple(),
 
1310
                        host=tuple(),
 
1311
                    ),
 
1312
                ),
 
1313
                result={
 
1314
                        'dn': fuzzy_netgroupdn,
 
1315
                        'cn': [netgroup1],
 
1316
                        'description': [u'Updated netgroup 1'],
 
1317
                        'nisdomainname': [u'%s' % api.env.domain],
 
1318
                        'externalhost': [unknown_host],
 
1319
                },
 
1320
            ),
 
1321
        ),
 
1322
 
 
1323
 
 
1324
        dict(
 
1325
            desc='Delete %r' % netgroup1,
 
1326
            command=('netgroup_del', [netgroup1], {}),
 
1327
            expected=dict(
 
1328
                value=netgroup1,
 
1329
                summary=u'Deleted netgroup "%s"' % netgroup1,
 
1330
                result=dict(failed=u''),
 
1331
            ),
 
1332
        ),
 
1333
 
 
1334
    ]
 
1335
 
 
1336
# No way to convert this test just yet.
 
1337
 
 
1338
#    def test_6b_netgroup_show(self):
 
1339
#        """
 
1340
#        Confirm the underlying triples
 
1341
#        """
 
1342
#        # Do an LDAP query to the compat area and verify that the entry
 
1343
#        # is correct
 
1344
#        conn = ldap2(shared_instance=False, ldap_uri=api.env.ldap_uri, base_dn=api.env.basedn)
 
1345
#        conn.connect(ccache=ccache)
 
1346
#        try:
 
1347
#            entries = conn.find_entries('cn=%s' % self.ng_cn,
 
1348
#                      base_dn='cn=ng,cn=compat,%s' % api.env.basedn)
 
1349
#        except errors.NotFound:
 
1350
#            raise nose.SkipTest('compat and nis are not enabled, skipping test')
 
1351
#        finally:
 
1352
#            conn.disconnect()
 
1353
#        triples = entries[0][0][1]['nisnetgrouptriple']
 
1354
#
 
1355
#        # This may not prove to be reliable since order is not guaranteed
 
1356
#        # and even which user gets into which triple can be random.
 
1357
#        assert '(nosuchhost,jexample,example.com)' in triples
 
1358
#        assert '(ipatesthost.%s,pexample,example.com)' % api.env.domain in triples