summaryrefslogtreecommitdiffstats
path: root/install/ui/test/aci_tests.js
blob: c51107da45c04bee4de6b29bd452bce93a9b7d93 (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
/*  Authors:
 *    Adam Young <ayoung@redhat.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; version 2 only
 *
 * 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */


var target_container;
var target_widget;
var target_facet;
var entity = IPA.entity({ name: 'bogus' });
var group_entity = IPA.entity({ name: 'group' });

module('aci', {
        setup: function() {
            IPA.ajax_options.async = false;
            IPA.init({
                url: 'data',
                on_error: function(xhr, text_status, error_thrown) {
                    ok(false, "ipa_init() failed: "+error_thrown);
                }
            });

           target_facet = IPA.details_facet({
                entity: entity,
                fields: [
                    {
                        type: 'select',
                        name: 'target',
                        widget: 'target.target',
                        enabled: false
                    },
                    {
                        name: 'filter',
                        widget: 'target.filter',
                        enabled: false
                    },
                    {
                        type: 'entity_select',
                        name: 'memberof',
                        widget: 'target.memberof',
                        enabled: false
                    },
                    {
                        name: 'subtree',
                        widget: 'target.subtree',
                        enabled: false
                    },
                    {
                        type: 'entity_select',
                        name: 'targetgroup',
                        widget: 'target.targetgroup',
                        enabled: false
                    },
                    {
                        type: 'select',
                        name: 'type',
                        widget: 'target.type',
                        enabled: false
                    },
                    {
                        name: 'attrs',
                        widget: 'target.attrs',
                        enabled: false
                    },
                    {
                        name: 'attrs_multi',
                        param: 'attrs',
                        type: 'multivalued',
                        widget: 'target.attrs_multi',
                        enabled: false
                    }
                ],
                widgets: [
                    {
                        type: 'permission_target',
                        container_factory: IPA.details_table_section,
                        group_entity: group_entity,
                        name: 'target',
                        label: 'Target',
                        show_target: false
                    }
                ],
                policies: [
                    IPA.permission_target_policy('target')
                ]
            });

            target_container = $('<div id="target"/>').appendTo(document.body);
            target_widget = target_facet.widgets.get_widget('target');
            target_widget.create(target_container);
        },
        teardown: function() {
                target_container.remove();
        }}
);


test("IPA.attributes_widget.", function() {

    var aciattrs = IPA.metadata.objects['user'].aciattrs;

    var container = $('<span/>', {
        name: 'attrs'
    });

    var widget = IPA.attributes_widget({
        name: 'attrs',
        object_type: 'user',
        entity:entity
    });

    widget.create(container);

    var table = $('table', container);

    ok(
        table,
        'Widget contains table');

    var tr = $('tbody tr', table);

    same(
        tr.length, aciattrs.length,
        'Widget contains all user ACI attributes');

    var record = {
        'attrs': [
            "unmatched",
            "cn",
            "description"
        ]
    };

    same(
        widget.save(), [],
        'Widget has no initial values');

    widget.update(record.attrs);

    tr = $('tbody tr', table);

    same(
        tr.length, aciattrs.length+1,
        'Widget contains all user ACI attributes plus 1 unmatched attribute');

    same(
        widget.save(), record.attrs.sort(),
        'All loaded values are saved and sorted');
});

test("IPA.rights_widget.", function() {

    var container = $('<span/>', {
        name: 'permissions'
    });

    var widget = IPA.rights_widget({
        name: 'permissions',
        entity:entity
    });

    widget.create(container);

    var inputs = $('input', container);

    same(
        inputs.length, widget.rights.length,
        'Widget displays all permissions');
});

var get_visible_rows = function(section) {
    var keys = section.rows.keys;

    var visible = [];

    for (var i=0; i<keys.length; i++) {
        var key = keys[i];
        var row = section.rows.get(key);
        var row_visible = row.css('display') !== 'none';
        if(row_visible) {
            visible.push(key);
        }
    }

    return visible;
};

test("Testing aci grouptarget.", function() {
    var data = {};
    data.result = {};
    data.result.result = {
        targetgroup: 'ipausers'
    };

    target_facet.load(data);

    same(target_widget.target, 'targetgroup' , 'group control selected');


    same(get_visible_rows(target_widget), ['targetgroup', 'attrs'],
        'group select row visible');

    ok ($('option', target_widget.group_select.container).length > 2,
        'group select populated');

});

test("Testing type target.", function() {
    var data = {};
    data.result = {};
    data.result.result = {
        type: 'hostgroup'
    };

    target_facet.load(data);

    same(target_widget.target, 'type', 'type selected');

    $("input[type=checkbox]").attr("checked",true);
    var record = {};
    target_facet.save(record);

    same(record.type[0], data.result.result.type,
         "saved type matches sample data");

    same(get_visible_rows(target_widget), ['memberof', 'type', 'attrs'],
        'type and attrs rows visible');

    ok((record.attrs.length > 10),
       "response length shows some attrs set");
});


test("Testing filter target.", function() {

    var data = {};
    data.result = {};
    data.result.result = {
        filter: 'somevalue'
    };

    target_facet.load(data);

    var record = {};
    target_facet.save(record);

    same(target_widget.target, 'filter', 'filter selected');

    same(get_visible_rows(target_widget), ['filter', 'attrs_multi'], 'filter row visible');

    ok(record.filter[0], data.result.result.filter, 'filter set correctly');
});



test("Testing subtree target.", function() {

    var data = {};
    data.result = {};
    data.result.result = {
        subtree: 'ldap:///cn=*,cn=roles,cn=accounts,dc=example,dc=co'
    };

    target_facet.load(data);
    var record = {};
    target_facet.save(record);

    same(record.subtree[0], data.result.result.subtree, 'subtree set correctly');

    same(get_visible_rows(target_widget), ['memberof', 'subtree'], 'subtree row visible');
});