summaryrefslogtreecommitdiffstats
path: root/install/ui/test/aci_tests.js
blob: acb4e7dabb7c19b136f161424307bed97b5334d2 (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
/*  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_section;
var entity = {name:'bogus'};

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

           target_container = $('<div id="target"/>').appendTo(document.body);
           target_section = IPA.target_section({
               name: 'target',
               label: 'Target',
               entity:entity
           });
           target_section.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.load(record);

    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'
    );
});

test("Testing aci grouptarget.", function() {
    var sample_data_filter_only = {"targetgroup":"ipausers"};
    target_section.load(sample_data_filter_only);

    var selected = $(target_section.type_select+":selected");

    same(selected.val(), 'targetgroup' , 'group control selected');
    ok ($('option', selected.group_select).length > 2,
        'group select populated');

});

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

    target_section.load(sample_data_filter_only);
    var selected = $(target_section.type_select+":selected");
    same(selected.val(), 'type', 'type selected');

    $("input[type=checkbox]").attr("checked",true);
    var response_record = {};
    target_section.save(response_record);
    same(response_record.type, sample_data_filter_only.type,
         "saved type matches sample data");
    ok((response_record.attrs.length > 10),
       "response length shows some attrs set");

});


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

    var sample_data_filter_only = {"filter":"somevalue"};

    target_section.load(sample_data_filter_only);

    var selected = $(target_section.type_select+":selected");
    same(selected.val(), 'filter', 'filter selected');
});



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

    var sample_data = {
        subtree:"ldap:///cn=*,cn=roles,cn=accounts,dc=example,dc=co"};

    target_section.load(sample_data);
    var record = {};
    target_section.save(record);
    same(record.subtree, sample_data.subtree, 'subtree set correctly');
});