summaryrefslogtreecommitdiffstats
path: root/tests/test_xmlrpc/test_sudocmd_plugin.py
blob: 2a5dcb0af47c5f7bdbc8ec58845c9991bab3992f (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
# Authors:
#   Jr Aquino <jr.aquino@citrixonline.com>
#
# Copyright (C) 2010  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/sudocmd.py` module.
"""

from ipalib import api, errors
from tests.test_xmlrpc.xmlrpc_test import Declarative, fuzzy_uuid
from tests.test_xmlrpc import objectclasses


sudocmd1 = u'/usr/bin/sudotestcmd1'


class test_sudocmd(Declarative):

    cleanup_commands = [
        ('sudocmd_del', [sudocmd1], {}),
    ]

    tests = [

        dict(
            desc='Try to retrieve non-existent %r' % sudocmd1,
            command=('sudocmd_show', [sudocmd1], {}),
            expected=errors.NotFound(reason='no such entry'),
        ),


        dict(
            desc='Try to update non-existent %r' % sudocmd1,
            command=('sudocmd_mod', [sudocmd1], dict(description=u'Nope')),
            expected=errors.NotFound(reason='no such entry'),
        ),


        dict(
            desc='Try to delete non-existent %r' % sudocmd1,
            command=('sudocmd_del', [sudocmd1], {}),
            expected=errors.NotFound(reason='no such entry'),
        ),


        dict(
            desc='Create %r' % sudocmd1,
            command=('sudocmd_add', [sudocmd1],
                dict(
                    description=u'Test sudo command 1',
                ),
            ),
            expected=dict(
                value=sudocmd1,
                summary=u'Added sudo command "%s"' % sudocmd1,
                result=dict(
                    dn=u'sudocmd=%s,cn=sudocmds,cn=sudo,%s' % (sudocmd1,
                        api.env.basedn),
                    sudocmd=[sudocmd1],
                    description=[u'Test sudo command 1'],
                    objectclass=objectclasses.sudocmd,
                    ipauniqueid=[fuzzy_uuid],
                ),
            ),
        ),


        dict(
            desc='Try to create duplicate %r' % sudocmd1,
            command=('sudocmd_add', [sudocmd1],
                dict(
                    description=u'Test sudo command 1',
                ),
            ),
            expected=errors.DuplicateEntry(),
        ),


        dict(
            desc='Retrieve %r' % sudocmd1,
            command=('sudocmd_show', [sudocmd1], {}),
            expected=dict(
                value=sudocmd1,
                summary=None,
                result=dict(
                    dn=u'sudocmd=%s,cn=sudocmds,cn=sudo,%s' % (sudocmd1,
                        api.env.basedn),
                    sudocmd=[sudocmd1],
                    description=[u'Test sudo command 1'],
                ),
            ),
        ),


        dict(
            desc='Search for %r' % sudocmd1,
            command=('sudocmd_find', [sudocmd1], {}),
            expected=dict(
                count=1,
                truncated=False,
                summary=u'1 sudo command matched',
                result=[
                    dict(
                        dn=u'sudocmd=%s,cn=sudocmds,cn=sudo,%s' % (sudocmd1,
                            api.env.basedn),
                        sudocmd=[sudocmd1],
                        description=[u'Test sudo command 1'],
                    ),
                ],
            ),
        ),


        dict(
            desc='Update %r' % sudocmd1,
            command=('sudocmd_mod', [sudocmd1], dict(
                description=u'Updated sudo command 1')),
            expected=dict(
                value=sudocmd1,
                summary=u'Modified sudo command "%s"' % sudocmd1,
                result=dict(
                    sudocmd=[sudocmd1],
                    description=[u'Updated sudo command 1'],
                ),
            ),
        ),


        dict(
            desc='Retrieve %r to verify update' % sudocmd1,
            command=('sudocmd_show', [sudocmd1], {}),
            expected=dict(
                value=sudocmd1,
                summary=None,
                result=dict(
                    dn=u'sudocmd=%s,cn=sudocmds,cn=sudo,%s' % (sudocmd1,
                        api.env.basedn),
                    sudocmd=[sudocmd1],
                    description=[u'Updated sudo command 1'],
                ),
            ),
        ),


        dict(
            desc='Delete %r' % sudocmd1,
            command=('sudocmd_del', [sudocmd1], {}),
            expected=dict(
                value=sudocmd1,
                summary=u'Deleted sudo command "%s"' % sudocmd1,
                result=dict(failed=u''),
            ),
        ),


        dict(
            desc='Try to retrieve non-existent %r' % sudocmd1,
            command=('sudocmd_show', [sudocmd1], {}),
            expected=errors.NotFound(reason='no such entry'),
        ),


        dict(
            desc='Try to update non-existent %r' % sudocmd1,
            command=('sudocmd_mod', [sudocmd1], dict(description=u'Nope')),
            expected=errors.NotFound(reason='no such entry'),
        ),


        dict(
            desc='Try to delete non-existent %r' % sudocmd1,
            command=('sudocmd_del', [sudocmd1], {}),
            expected=errors.NotFound(reason='no such entry'),
        ),
    ]