summaryrefslogtreecommitdiffstats
path: root/ipatests/test_xmlrpc/test_selinuxusermap_plugin.py
blob: c987a0c530713c0d83c2827e57124fb77aecc339 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
# Authors:
#   Rob Crittenden <rcritten@redhat.com>
#
# Copyright (C) 2011  Red Hat
# see file 'COPYING' for use and warranty information
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
Test the `ipalib/plugins/selinuxusermap.py` module.
"""

from ipalib import api, errors
from ipatests.test_xmlrpc import objectclasses
from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid
from ipapython.dn import DN
from ipatests.util import Fuzzy
from ipatests.test_xmlrpc.test_user_plugin import get_user_result

rule1 = u'selinuxrule1'
selinuxuser1 = u'guest_u:s0'
selinuxuser2 = u'xguest_u:s0'

user1 = u'tuser1'
group1 = u'testgroup1'
host1 = u'testhost1.%s' % api.env.domain
hostdn1 = DN(('fqdn', host1), ('cn', 'computers'), ('cn', 'accounts'),
             api.env.basedn)
hbacrule1 = u'testhbacrule1'
hbacrule2 = u'testhbacrule12'

# Note (?i) at the beginning of the regexp is the ingnore case flag
fuzzy_selinuxusermapdn = Fuzzy(
    '(?i)ipauniqueid=[0-9a-f]{8}-[0-9a-f]{4}'
    '-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12},%s,%s'
    % (api.env.container_selinux, api.env.basedn)
)
fuzzy_hbacruledn = Fuzzy(
    '(?i)ipauniqueid=[0-9a-f]{8}-[0-9a-f]{4}'
    '-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12},%s,%s'
    % (api.env.container_hbac, api.env.basedn)
)

allow_all_rule_dn = api.Command['hbacrule_show'](u'allow_all')['result']['dn']


class test_selinuxusermap(Declarative):
    cleanup_commands = [
        ('selinuxusermap_del', [rule1], {}),
        ('group_del', [group1], {}),
        ('user_del', [user1], {}),
        ('host_del', [host1], {}),
        ('hbacrule_del', [hbacrule1], {}),
        ('hbacrule_del', [hbacrule2], {}),
    ]

    tests = [

        dict(
            desc='Try to retrieve non-existent %r' % rule1,
            command=('selinuxusermap_show', [rule1], {}),
            expected=errors.NotFound(
                reason=u'%s: SELinux User Map rule not found' % rule1),
        ),


        dict(
            desc='Try to update non-existent %r' % rule1,
            command=('selinuxusermap_mod', [rule1], dict(description=u'Foo')),
            expected=errors.NotFound(
                reason=u'%s: SELinux User Map rule not found' % rule1),
        ),


        dict(
            desc='Try to delete non-existent %r' % rule1,
            command=('selinuxusermap_del', [rule1], {}),
            expected=errors.NotFound(
                reason=u'%s: SELinux User Map rule not found' % rule1),
        ),


        dict(
            desc='Create rule %r' % rule1,
            command=(
                'selinuxusermap_add', [rule1],
                    dict(ipaselinuxuser=selinuxuser1)
            ),
            expected=dict(
                value=rule1,
                summary=u'Added SELinux User Map "%s"' % rule1,
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser1],
                    objectclass=objectclasses.selinuxusermap,
                    ipauniqueid=[fuzzy_uuid],
                    ipaenabledflag=[u'TRUE'],
                    dn=fuzzy_selinuxusermapdn,
                ),
            ),
        ),


        dict(
            desc='Try to create duplicate %r' % rule1,
            command=(
                'selinuxusermap_add', [rule1],
                    dict(ipaselinuxuser=selinuxuser1)
            ),
            expected=errors.DuplicateEntry(message=u'SELinux User Map rule ' +
                u'with name "%s" already exists' % rule1),
        ),


        dict(
            desc='Retrieve rule %r' % rule1,
            command=('selinuxusermap_show', [rule1], {}),
            expected=dict(
                value=rule1,
                summary=None,
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser1],
                    ipaenabledflag=[u'TRUE'],
                    dn=fuzzy_selinuxusermapdn,
                ),
            ),
        ),


        dict(
            desc='Update rule %r' % rule1,
            command=(
                'selinuxusermap_mod', [rule1],
                    dict(ipaselinuxuser=selinuxuser2)
            ),
            expected=dict(
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser2],
                    ipaenabledflag=[u'TRUE'],
                ),
                summary=u'Modified SELinux User Map "%s"' % rule1,
                value=rule1,
            ),
        ),


        dict(
            desc='Retrieve %r to verify update' % rule1,
            command=('selinuxusermap_show', [rule1], {}),
            expected=dict(
                value=rule1,
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser2],
                    ipaenabledflag=[u'TRUE'],
                    dn=fuzzy_selinuxusermapdn,
                ),
                summary=None,
            ),
        ),


        dict(
            desc='Search for rule %r' % rule1,
            command=('selinuxusermap_find', [], dict(cn=rule1)),
            expected=dict(
                count=1,
                truncated=False,
                result=[
                    dict(
                        cn=[rule1],
                        ipaselinuxuser=[selinuxuser2],
                        ipaenabledflag=[u'TRUE'],
                        dn=fuzzy_selinuxusermapdn,
                    ),
                ],
                summary=u'1 SELinux User Map matched',
            ),
        ),


        ###############
        # Create additional entries needed for testing
        dict(
            desc='Create %r' % user1,
            command=(
                'user_add', [], dict(givenname=u'Test', sn=u'User1')
            ),
            expected=dict(
                value=user1,
                summary=u'Added user "%s"' % user1,
                result=get_user_result(user1, u'Test', u'User1', 'add'),
            ),
        ),

        dict(
            desc='Create group %r' % group1,
            command=(
                'group_add', [group1], dict(description=u'Test desc 1')
            ),
            expected=dict(
                value=group1,
                summary=u'Added group "%s"' % group1,
                result=dict(
                    cn=[group1],
                    description=[u'Test desc 1'],
                    gidnumber=[fuzzy_digits],
                    objectclass=objectclasses.group + [u'posixgroup'],
                    ipauniqueid=[fuzzy_uuid],
                    dn=DN(('cn', group1), ('cn', 'groups'), ('cn', 'accounts'),
                          api.env.basedn),
                ),
            ),
        ),


        dict(
            desc='Add member %r to %r' % (user1, group1),
            command=(
                'group_add_member', [group1], dict(user=user1)
            ),
            expected=dict(
                completed=1,
                failed=dict(
                    member=dict(
                        group=tuple(),
                        user=tuple(),
                    ),
                ),
                result={
                        'dn': DN(('cn', group1), ('cn', 'groups'),
                            ('cn', 'accounts'), api.env.basedn),
                        'member_user': (user1,),
                        'gidnumber': [fuzzy_digits],
                        'cn': [group1],
                        'description': [u'Test desc 1'],
                },
            ),
        ),


        dict(
            desc='Create host %r' % host1,
            command=('host_add', [host1],
                dict(
                    description=u'Test host 1',
                    l=u'Undisclosed location 1',
                    force=True,
                ),
            ),
            expected=dict(
                value=host1,
                summary=u'Added host "%s"' % host1,
                result=dict(
                    dn=hostdn1,
                    fqdn=[host1],
                    description=[u'Test host 1'],
                    l=[u'Undisclosed location 1'],
                    krbprincipalname=[u'host/%s@%s' % (host1, api.env.realm)],
                    objectclass=objectclasses.host,
                    ipauniqueid=[fuzzy_uuid],
                    managedby_host=[host1],
                    has_keytab=False,
                    has_password=False,
                ),
            ),
        ),


        dict(
            desc='Create HBAC rule %r' % hbacrule1,
            command=(
                'hbacrule_add', [hbacrule1], {}
            ),
            expected=dict(
                value=hbacrule1,
                summary=u'Added HBAC rule "%s"' % hbacrule1,
                result=dict(
                    cn=[hbacrule1],
                    objectclass=objectclasses.hbacrule,
                    ipauniqueid=[fuzzy_uuid],
                    accessruletype=[u'allow'],
                    ipaenabledflag=[u'TRUE'],
                    dn=fuzzy_hbacruledn,
                ),
            ),
        ),


        dict(
            desc='Create HBAC rule %r' % hbacrule2,
            command=(
                'hbacrule_add', [hbacrule2], {}
            ),
            expected=dict(
                value=hbacrule2,
                summary=u'Added HBAC rule "%s"' % hbacrule2,
                result=dict(
                    cn=[hbacrule2],
                    objectclass=objectclasses.hbacrule,
                    ipauniqueid=[fuzzy_uuid],
                    accessruletype=[u'allow'],
                    ipaenabledflag=[u'TRUE'],
                    dn=fuzzy_hbacruledn,
                ),
            ),
        ),


        ###############
        # Fill out rule with members and/or pointers to HBAC rules
        dict(
            desc='Add user to %r' % rule1,
            command=('selinuxusermap_add_user', [rule1], dict(user=user1)),
            expected=dict(
                failed=dict(memberuser=dict(group=[], user=[])),
                completed=1,
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser2],
                    ipaenabledflag=[u'TRUE'],
                    memberuser_user=[user1],
                    dn=fuzzy_selinuxusermapdn,
                ),
            )
        ),


        dict(
            desc='Add non-existent user to %r' % rule1,
            command=('selinuxusermap_add_user', [rule1],
                dict(user=u'notfound')),
            expected=dict(
                failed=dict(
                    memberuser=dict(group=[],
                                    user=[(u'notfound', u'no such entry')])
                        ),
                completed=0,
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser2],
                    ipaenabledflag=[u'TRUE'],
                    memberuser_user=[user1],
                    dn=fuzzy_selinuxusermapdn,
                ),
            )
        ),


        dict(
            desc='Remove user from %r' % rule1,
            command=('selinuxusermap_remove_user', [rule1], dict(user=user1)),
            expected=dict(
                failed=dict(memberuser=dict(group=[], user=[])),
                completed=1,
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser2],
                    ipaenabledflag=[u'TRUE'],
                    dn=fuzzy_selinuxusermapdn,
                ),
            )
        ),


        dict(
            desc='Remove non-existent user to %r' % rule1,
            command=('selinuxusermap_remove_user', [rule1],
                dict(user=u'notfound')),
            expected=dict(
                failed=dict(
                    memberuser=dict(group=[],
                        user=[(u'notfound', u'This entry is not a member')]
                            )
                        ),
                completed=0,
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser2],
                    ipaenabledflag=[u'TRUE'],
                    dn=fuzzy_selinuxusermapdn,
                ),
            )
        ),


        dict(
            desc='Add group to %r' % rule1,
            command=('selinuxusermap_add_user', [rule1], dict(group=group1)),
            expected=dict(
                failed=dict(memberuser=dict(group=[], user=[])),
                completed=1,
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser2],
                    ipaenabledflag=[u'TRUE'],
                    memberuser_group=[group1],
                    dn=fuzzy_selinuxusermapdn,
                ),
            )
        ),


        dict(
            desc='Add host to %r' % rule1,
            command=('selinuxusermap_add_host', [rule1], dict(host=host1)),
            expected=dict(
                failed=dict(memberhost=dict(hostgroup=[], host=[])),
                completed=1,
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser2],
                    ipaenabledflag=[u'TRUE'],
                    memberhost_host=[host1],
                    memberuser_group=[group1],
                    dn=fuzzy_selinuxusermapdn,
                ),
            )
        ),


        ###############
        # Test enabling and disabling
        dict(
            desc='Disable %r' % rule1,
            command=('selinuxusermap_disable', [rule1], {}),
            expected=dict(
                result=True,
                value=rule1,
                summary=u'Disabled SELinux User Map "%s"' % rule1,
            )
        ),


        dict(
            desc='Disable %r again' % rule1,
            command=('selinuxusermap_disable', [rule1], {}),
            expected=errors.AlreadyInactive(),
        ),


        dict(
            desc='Enable %r' % rule1,
            command=('selinuxusermap_enable', [rule1], {}),
            expected=dict(
                result=True,
                value=rule1,
                summary=u'Enabled SELinux User Map "%s"' % rule1,
            )
        ),


        dict(
            desc='Re-enable %r again' % rule1,
            command=('selinuxusermap_enable', [rule1], {}),
            expected=errors.AlreadyActive(),
        ),


        # Point to an HBAC Rule
        dict(
            desc='Add an HBAC rule to %r that has other members' % rule1,
            command=(
                'selinuxusermap_mod', [rule1], dict(seealso=hbacrule1)
            ),
            expected=errors.MutuallyExclusiveError(
                reason=u'HBAC rule and local members cannot both be set'),
        ),


        dict(
            desc='Remove host from %r' % rule1,
            command=('selinuxusermap_remove_host', [rule1], dict(host=host1)),
            expected=dict(
                failed=dict(memberhost=dict(hostgroup=[], host=[])),
                completed=1,
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser2],
                    ipaenabledflag=[u'TRUE'],
                    memberuser_group=[group1],
                    dn=fuzzy_selinuxusermapdn,
                ),
            )
        ),


        dict(
            desc='Remove group from %r' % rule1,
            command=('selinuxusermap_remove_user', [rule1],
                dict(group=group1)),
            expected=dict(
                failed=dict(memberuser=dict(group=[], user=[])),
                completed=1,
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser2],
                    ipaenabledflag=[u'TRUE'],
                    dn=fuzzy_selinuxusermapdn,
                ),
            )
        ),


        dict(
            desc='Add non-existent HBAC rule to %r' % rule1,
            command=(
                'selinuxusermap_mod', [rule1], dict(seealso=u'notfound')
            ),
            expected=errors.NotFound(
                reason=u'HBAC rule notfound not found'),
        ),


        dict(
            desc='Add an HBAC rule to %r' % rule1,
            command=(
                'selinuxusermap_mod', [rule1], dict(seealso=hbacrule1)
            ),
            expected=dict(
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser2],
                    ipaenabledflag=[u'TRUE'],
                    seealso=hbacrule1,
                ),
                summary=u'Modified SELinux User Map "%s"' % rule1,
                value=rule1,
            ),
        ),


        dict(
            desc='Add user to %r that has HBAC' % rule1,
            command=('selinuxusermap_add_user', [rule1], dict(user=user1)),
            expected=errors.MutuallyExclusiveError(
                reason=u'HBAC rule and local members cannot both be set'),
        ),


        dict(
            desc='Add host to %r that has HBAC' % rule1,
            command=('selinuxusermap_add_host', [rule1], dict(host=host1)),
            expected=errors.MutuallyExclusiveError(
                reason=u'HBAC rule and local members cannot both be set'),
        ),


        dict(
            desc='Try to delete HBAC rule pointed to by %r' % rule1,
            command=('hbacrule_del', [hbacrule1], {}),
            expected=errors.DependentEntry(key=hbacrule1,
                label=u'SELinux User Map', dependent=rule1)
        ),


        # This tests selinuxusermap-find --hbacrule=<foo> returns an
        # exact match
        dict(
            desc='Try to delete similarly named HBAC rule %r' % hbacrule2,
            command=('hbacrule_del', [hbacrule2], {}),
            expected=dict(
                result=dict(failed=[]),
                value=[hbacrule2],
                summary=u'Deleted HBAC rule "%s"' % hbacrule2,
            )
        ),


        # Test clean up
        dict(
            desc='Delete %r' % rule1,
            command=('selinuxusermap_del', [rule1], {}),
            expected=dict(
                result=dict(failed=[]),
                value=[rule1],
                summary=u'Deleted SELinux User Map "%s"' % rule1,
            )
        ),


        dict(
            desc='Try to delete non-existent %r' % rule1,
            command=('selinuxusermap_del', [rule1], {}),
            expected=errors.NotFound(
                reason=u'%s: SELinux User Map rule not found' % rule1),
        ),


        # Some negative tests
        dict(
            desc='Create rule with unknown user %r' % rule1,
            command=(
                'selinuxusermap_add', [rule1],
                    dict(ipaselinuxuser=u'notfound:s0:c0')
            ),
            expected=errors.NotFound(reason=u'SELinux user notfound:s0:c0 ' +
                u'not found in ordering list (in config)'),
        ),


        dict(
            desc='Create rule with invalid user bad+user',
            command=(
                'selinuxusermap_add', [rule1], dict(ipaselinuxuser=u'bad+user')
            ),
            expected=errors.ValidationError(name='selinuxuser',
                error=u'Invalid SELinux user name, only a-Z and _ are allowed'
                ),
        ),


        dict(
            desc='Create rule with invalid MCS xguest_u:s999',
            command=(
                'selinuxusermap_add', [rule1],
                     dict(ipaselinuxuser=u'xguest_u:s999')
            ),
            expected=errors.ValidationError(name='selinuxuser',
                error=u'Invalid MLS value, must match s[0-15](-s[0-15])'),
        ),


        dict(
            desc='Create rule with invalid MLS xguest_u:s0:p88',
            command=(
                'selinuxusermap_add', [rule1],
                    dict(ipaselinuxuser=u'xguest_u:s0:p88')
            ),
            expected=errors.ValidationError(name='selinuxuser',
                error=u'Invalid MCS value, must match c[0-1023].c[0-1023] ' +
                    u'and/or c[0-1023]-c[0-c0123]'),
        ),


        dict(
            desc='Create rule with invalid MLS xguest_u:s0:c0.c1028',
            command=(
                'selinuxusermap_add', [rule1],
                    dict(ipaselinuxuser=u'xguest_u:s0-s0:c0.c1028')
            ),
            expected=errors.ValidationError(name='selinuxuser',
                error=u'Invalid MCS value, must match c[0-1023].c[0-1023] ' +
                    u'and/or c[0-1023]-c[0-c0123]'),
        ),


        dict(
            desc='Create rule with invalid user via setattr',
            command=(
                'selinuxusermap_mod', [rule1],
                    dict(setattr=u'ipaselinuxuser=deny')
            ),
            expected=errors.ValidationError(name='ipaselinuxuser',
                error=u'Invalid MLS value, must match s[0-15](-s[0-15])'),
        ),

        dict(
            desc='Create rule with both --hbacrule and --usercat set',
            command=(
                'selinuxusermap_add', [rule1],
                    dict(ipaselinuxuser=selinuxuser1,
                         seealso=hbacrule1,
                         usercategory=u'all')
            ),
            expected=errors.MutuallyExclusiveError(
                reason=u'HBAC rule and local members cannot both be set'),
        ),

        dict(
            desc='Create rule with both --hbacrule and --hostcat set',
            command=(
                'selinuxusermap_add', [rule1],
                    dict(ipaselinuxuser=selinuxuser1,
                         seealso=hbacrule1,
                         hostcategory=u'all')
            ),
            expected=errors.MutuallyExclusiveError(
                reason=u'HBAC rule and local members cannot both be set'),
        ),

        dict(
            desc='Create rule with both --hbacrule '
                 'and --usercat set via setattr',
            command=(
                'selinuxusermap_add', [rule1],
                    dict(ipaselinuxuser=selinuxuser1,
                         seealso=hbacrule1,
                         setattr=u'usercategory=all')
            ),
            expected=errors.MutuallyExclusiveError(
                reason=u'HBAC rule and local members cannot both be set'),
        ),

        dict(
            desc='Create rule with both --hbacrule '
                 'and --hostcat set via setattr',
            command=(
                'selinuxusermap_add', [rule1],
                    dict(ipaselinuxuser=selinuxuser1,
                         seealso=hbacrule1,
                         setattr=u'hostcategory=all')
            ),
            expected=errors.MutuallyExclusiveError(
                reason=u'HBAC rule and local members cannot both be set'),
        ),

        dict(
            desc='Create rule %r with --hbacrule' % rule1,
            command=(
                'selinuxusermap_add', [rule1],
                dict(ipaselinuxuser=selinuxuser1, seealso=hbacrule1)
            ),
            expected=dict(
                value=rule1,
                summary=u'Added SELinux User Map "%s"' % rule1,
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser1],
                    objectclass=objectclasses.selinuxusermap,
                    ipauniqueid=[fuzzy_uuid],
                    ipaenabledflag=[u'TRUE'],
                    dn=fuzzy_selinuxusermapdn,
                    seealso=hbacrule1
                ),
            ),
        ),

        dict(
            desc='Add an --usercat to %r that has HBAC set' % rule1,
            command=(
                'selinuxusermap_mod', [rule1], dict(usercategory=u'all')
            ),
            expected=errors.MutuallyExclusiveError(
                reason=u'HBAC rule and local members cannot both be set'),
        ),

        dict(
            desc='Add an --hostcat to %r that has HBAC set' % rule1,
            command=(
                'selinuxusermap_mod', [rule1], dict(hostcategory=u'all')
            ),
            expected=errors.MutuallyExclusiveError(
                reason=u'HBAC rule and local members cannot both be set'),
        ),

        dict(
            desc='Add an usercat via setattr to %r that has HBAC set' % rule1,
            command=(
                'selinuxusermap_mod', [rule1],
                dict(setattr=u'usercategory=all')
            ),
            expected=errors.MutuallyExclusiveError(
                reason=u'HBAC rule and local members cannot both be set'),
        ),

        dict(
            desc='Add an hostcat via setattr to %r that has HBAC set' % rule1,
            command=(
                'selinuxusermap_mod', [rule1],
                dict(setattr=u'hostcategory=all')
            ),
            expected=errors.MutuallyExclusiveError(
                reason=u'HBAC rule and local members cannot both be set'),
        ),

        dict(
            desc='Delete %r' % rule1,
            command=('selinuxusermap_del', [rule1], {}),
            expected=dict(
                result=dict(failed=[]),
                value=[rule1],
                summary=u'Deleted SELinux User Map "%s"' % rule1,
            )
        ),

        dict(
            desc='Create rule %r with usercat and hostcat set' % rule1,
            command=(
                'selinuxusermap_add', [rule1],
                    dict(ipaselinuxuser=selinuxuser1,
                         usercategory=u'all',
                         hostcategory=u'all')
            ),
            expected=dict(
                value=rule1,
                summary=u'Added SELinux User Map "%s"' % rule1,
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser1],
                    objectclass=objectclasses.selinuxusermap,
                    ipauniqueid=[fuzzy_uuid],
                    ipaenabledflag=[u'TRUE'],
                    dn=fuzzy_selinuxusermapdn,
                    usercategory=[u'all'],
                    hostcategory=[u'all']
                ),
            ),
        ),

        dict(
            desc='Add HBAC rule to %r that has usercat and hostcat' % rule1,
            command=(
                'selinuxusermap_mod', [rule1], dict(seealso=hbacrule1)
            ),
            expected=errors.MutuallyExclusiveError(
                reason=u'HBAC rule and local members cannot both be set'),
        ),

        dict(
            desc='Delete %r' % rule1,
            command=('selinuxusermap_del', [rule1], {}),
            expected=dict(
                result=dict(failed=[]),
                value=[rule1],
                summary=u'Deleted SELinux User Map "%s"' % rule1,
            )
        ),

        dict(
            desc='Create rule %r' % rule1,
            command=(
                'selinuxusermap_add', [rule1],
                dict(ipaselinuxuser=selinuxuser1)
            ),
            expected=dict(
                value=rule1,
                summary=u'Added SELinux User Map "%s"' % rule1,
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser1],
                    objectclass=objectclasses.selinuxusermap,
                    ipauniqueid=[fuzzy_uuid],
                    ipaenabledflag=[u'TRUE'],
                    dn=fuzzy_selinuxusermapdn,
                ),
            ),
        ),

        dict(
            desc='Add HBAC rule, hostcat and usercat to %r' % rule1,
            command=(
                'selinuxusermap_mod', [rule1],
                    dict(seealso=hbacrule1,
                         usercategory=u'all',
                         hostcategory=u'all')
            ),
            expected=errors.MutuallyExclusiveError(
                reason=u'HBAC rule and local members cannot both be set'),
        ),

        dict(
            desc='Delete %r' % rule1,
            command=('selinuxusermap_del', [rule1], {}),
            expected=dict(
                result=dict(failed=[]),
                value=[rule1],
                summary=u'Deleted SELinux User Map "%s"' % rule1,
            )
        ),

       dict(
            desc='Create rule %r with '
                 '--setattr=seealso=<allow_all rule DN>' % rule1,
            command=(
                'selinuxusermap_add',
                [rule1],
                dict(ipaselinuxuser=selinuxuser1,
                     setattr=u'seealso=%s' % allow_all_rule_dn)
            ),
            expected=dict(
                value=rule1,
                summary=u'Added SELinux User Map "%s"' % rule1,
                result=dict(
                    cn=[rule1],
                    ipaselinuxuser=[selinuxuser1],
                    objectclass=objectclasses.selinuxusermap,
                    ipauniqueid=[fuzzy_uuid],
                    ipaenabledflag=[u'TRUE'],
                    dn=fuzzy_selinuxusermapdn,
                    seealso=u'allow_all',
                ),
            ),
        ),

        dict(
            desc='Delete %r' % rule1,
            command=('selinuxusermap_del', [rule1], {}),
            expected=dict(
                result=dict(failed=[]),
                value=[rule1],
                summary=u'Deleted SELinux User Map "%s"' % rule1,
            )
        ),
    ]