2010-10-25 18:55:57 -05:00
|
|
|
/* Authors:
|
2010-12-17 12:08:23 -06:00
|
|
|
* Adam Young <ayoung@redhat.com>
|
2010-10-25 18:55:57 -05:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-02-02 10:35:23 -06:00
|
|
|
var target_container;
|
2011-12-01 08:58:49 -06:00
|
|
|
var target_widget;
|
|
|
|
var target_facet;
|
2011-11-07 14:21:45 -06:00
|
|
|
var entity = IPA.entity({ name: 'bogus' });
|
|
|
|
var group_entity = IPA.entity({ name: 'group' });
|
2011-12-01 08:58:49 -06:00
|
|
|
|
|
|
|
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',
|
2012-02-22 05:53:00 -06:00
|
|
|
widget: 'target.target',
|
|
|
|
enabled: false
|
2011-12-01 08:58:49 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'filter',
|
|
|
|
widget: 'target.filter',
|
|
|
|
enabled: false
|
|
|
|
},
|
2012-01-03 03:57:59 -06:00
|
|
|
{
|
|
|
|
type: 'entity_select',
|
|
|
|
name: 'memberof',
|
2012-02-22 05:53:00 -06:00
|
|
|
widget: 'target.memberof',
|
|
|
|
enabled: false
|
2012-01-03 03:57:59 -06:00
|
|
|
},
|
2011-12-01 08:58:49 -06:00
|
|
|
{
|
|
|
|
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
|
2012-02-22 05:53:00 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'attrs_multi',
|
|
|
|
param: 'attrs',
|
|
|
|
type: 'multivalued',
|
|
|
|
widget: 'target.attrs_multi',
|
|
|
|
enabled: false
|
2011-12-01 08:58:49 -06:00
|
|
|
}
|
|
|
|
],
|
|
|
|
widgets: [
|
|
|
|
{
|
|
|
|
type: 'permission_target',
|
|
|
|
container_factory: IPA.details_table_section,
|
2011-11-07 14:21:45 -06:00
|
|
|
group_entity: group_entity,
|
2011-12-01 08:58:49 -06:00
|
|
|
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();
|
|
|
|
}}
|
2010-10-25 18:55:57 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2011-02-02 10:35:23 -06:00
|
|
|
test("IPA.attributes_widget.", function() {
|
|
|
|
|
2011-02-16 12:46:59 -06:00
|
|
|
var aciattrs = IPA.metadata.objects['user'].aciattrs;
|
2011-02-02 10:35:23 -06:00
|
|
|
|
|
|
|
var container = $('<span/>', {
|
|
|
|
name: 'attrs'
|
|
|
|
});
|
|
|
|
|
|
|
|
var widget = IPA.attributes_widget({
|
|
|
|
name: 'attrs',
|
removing setters setup and init
change widget and widget unit tests to hold on to entity, not entity name.
Replacing entity_name with entity.name in most places.
The one exception is columns for table_widget.
Widgets that refer to other entities have to have late resolution of the entity object, due to circular dependencies.
cleanup entity assignment.
removed template and layout,
merged setup into create
adder dialogs adjust height for external
removed init from widget, isection, association, facet, host and service
Make unit tests use factory.
fix functional tests to click find link correctly.
tweak to activation test, but still broken.
moved initialization code to the end
use --all for hbacrule find, so the type shows up now
fixed dns exception code and exception handling for get_entity
replace metadata look up with value from entity.
fixed author lines
removed duplicate columns in managed by facets.
tweak to nav fix in order to initialize tab.
more defensive code
update metadata for true false
one line init for entity_name in widget
move init code to end of constructor functions
moved constants to start of function for adder_dialog
external fields for dialogs initialized at dialog creation
sudo sections: move add fields and columns to widget definition.
The parameter validation in IPA.column ...This is precondition checking. Note that it merely throws an exception if the entity_name is not set. I want this stuff at the top of the function so that it is obvious to people looking to use them what is required. I added a comment to make this clear, but I'd like to keep precondition checking at the top of the function.
decreased the scope of the pkey_name and moved the initiailzation fof columns into the setup_column function for association_tables
return false at the end of click handler
removed blank labels in sudo command section
fix radio buttons for sudo category
fixed table side for adder dialogs with external fields
comments for future direction with add_columns
https://fedorahosted.org/freeipa/ticket/1451
https://fedorahosted.org/freeipa/ticket/1462
https://fedorahosted.org/freeipa/ticket/1493
https://fedorahosted.org/freeipa/ticket/1497
https://fedorahosted.org/freeipa/ticket/1532
https://fedorahosted.org/freeipa/ticket/1534
2011-07-25 11:15:14 -05:00
|
|
|
object_type: 'user',
|
|
|
|
entity:entity
|
2011-02-02 10:35:23 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
widget.create(container);
|
|
|
|
|
|
|
|
var table = $('table', container);
|
|
|
|
|
|
|
|
ok(
|
|
|
|
table,
|
2011-12-01 08:58:49 -06:00
|
|
|
'Widget contains table');
|
2011-02-02 10:35:23 -06:00
|
|
|
|
|
|
|
var tr = $('tbody tr', table);
|
|
|
|
|
|
|
|
same(
|
|
|
|
tr.length, aciattrs.length,
|
2011-12-01 08:58:49 -06:00
|
|
|
'Widget contains all user ACI attributes');
|
2011-02-02 10:35:23 -06:00
|
|
|
|
|
|
|
var record = {
|
|
|
|
'attrs': [
|
|
|
|
"unmatched",
|
|
|
|
"cn",
|
|
|
|
"description"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
same(
|
|
|
|
widget.save(), [],
|
2011-12-01 08:58:49 -06:00
|
|
|
'Widget has no initial values');
|
2011-02-02 10:35:23 -06:00
|
|
|
|
2011-12-01 08:58:49 -06:00
|
|
|
widget.update(record.attrs);
|
2011-02-02 10:35:23 -06:00
|
|
|
|
|
|
|
tr = $('tbody tr', table);
|
|
|
|
|
|
|
|
same(
|
|
|
|
tr.length, aciattrs.length+1,
|
2011-12-01 08:58:49 -06:00
|
|
|
'Widget contains all user ACI attributes plus 1 unmatched attribute');
|
2011-02-02 10:35:23 -06:00
|
|
|
|
|
|
|
same(
|
|
|
|
widget.save(), record.attrs.sort(),
|
2011-12-01 08:58:49 -06:00
|
|
|
'All loaded values are saved and sorted');
|
2011-02-02 10:35:23 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
test("IPA.rights_widget.", function() {
|
|
|
|
|
|
|
|
var container = $('<span/>', {
|
|
|
|
name: 'permissions'
|
|
|
|
});
|
|
|
|
|
|
|
|
var widget = IPA.rights_widget({
|
removing setters setup and init
change widget and widget unit tests to hold on to entity, not entity name.
Replacing entity_name with entity.name in most places.
The one exception is columns for table_widget.
Widgets that refer to other entities have to have late resolution of the entity object, due to circular dependencies.
cleanup entity assignment.
removed template and layout,
merged setup into create
adder dialogs adjust height for external
removed init from widget, isection, association, facet, host and service
Make unit tests use factory.
fix functional tests to click find link correctly.
tweak to activation test, but still broken.
moved initialization code to the end
use --all for hbacrule find, so the type shows up now
fixed dns exception code and exception handling for get_entity
replace metadata look up with value from entity.
fixed author lines
removed duplicate columns in managed by facets.
tweak to nav fix in order to initialize tab.
more defensive code
update metadata for true false
one line init for entity_name in widget
move init code to end of constructor functions
moved constants to start of function for adder_dialog
external fields for dialogs initialized at dialog creation
sudo sections: move add fields and columns to widget definition.
The parameter validation in IPA.column ...This is precondition checking. Note that it merely throws an exception if the entity_name is not set. I want this stuff at the top of the function so that it is obvious to people looking to use them what is required. I added a comment to make this clear, but I'd like to keep precondition checking at the top of the function.
decreased the scope of the pkey_name and moved the initiailzation fof columns into the setup_column function for association_tables
return false at the end of click handler
removed blank labels in sudo command section
fix radio buttons for sudo category
fixed table side for adder dialogs with external fields
comments for future direction with add_columns
https://fedorahosted.org/freeipa/ticket/1451
https://fedorahosted.org/freeipa/ticket/1462
https://fedorahosted.org/freeipa/ticket/1493
https://fedorahosted.org/freeipa/ticket/1497
https://fedorahosted.org/freeipa/ticket/1532
https://fedorahosted.org/freeipa/ticket/1534
2011-07-25 11:15:14 -05:00
|
|
|
name: 'permissions',
|
|
|
|
entity:entity
|
2011-02-02 10:35:23 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
widget.create(container);
|
|
|
|
|
|
|
|
var inputs = $('input', container);
|
|
|
|
|
|
|
|
same(
|
|
|
|
inputs.length, widget.rights.length,
|
2011-12-01 08:58:49 -06:00
|
|
|
'Widget displays all permissions');
|
2011-02-02 10:35:23 -06:00
|
|
|
});
|
|
|
|
|
2011-12-01 08:58:49 -06:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2010-10-25 18:55:57 -05:00
|
|
|
test("Testing aci grouptarget.", function() {
|
2011-11-18 19:47:39 -06:00
|
|
|
var data = {};
|
|
|
|
data.result = {};
|
|
|
|
data.result.result = {
|
|
|
|
targetgroup: 'ipausers'
|
|
|
|
};
|
|
|
|
|
|
|
|
target_facet.load(data);
|
2010-10-25 18:55:57 -05:00
|
|
|
|
2011-12-01 08:58:49 -06:00
|
|
|
same(target_widget.target, 'targetgroup' , 'group control selected');
|
2010-10-25 18:55:57 -05:00
|
|
|
|
2011-12-01 08:58:49 -06:00
|
|
|
|
2012-02-22 05:53:00 -06:00
|
|
|
same(get_visible_rows(target_widget), ['targetgroup', 'attrs'],
|
2011-12-01 08:58:49 -06:00
|
|
|
'group select row visible');
|
|
|
|
|
|
|
|
ok ($('option', target_widget.group_select.container).length > 2,
|
2011-02-07 22:02:43 -06:00
|
|
|
'group select populated');
|
2010-10-25 18:55:57 -05:00
|
|
|
|
2011-02-07 22:02:43 -06:00
|
|
|
});
|
2010-10-25 18:55:57 -05:00
|
|
|
|
2011-02-07 22:02:43 -06:00
|
|
|
test("Testing type target.", function() {
|
2011-11-18 19:47:39 -06:00
|
|
|
var data = {};
|
|
|
|
data.result = {};
|
|
|
|
data.result.result = {
|
|
|
|
type: 'hostgroup'
|
|
|
|
};
|
2011-12-01 08:58:49 -06:00
|
|
|
|
2011-11-18 19:47:39 -06:00
|
|
|
target_facet.load(data);
|
2011-02-07 22:02:43 -06:00
|
|
|
|
2011-12-01 08:58:49 -06:00
|
|
|
same(target_widget.target, 'type', 'type selected');
|
2011-02-07 22:02:43 -06:00
|
|
|
|
|
|
|
$("input[type=checkbox]").attr("checked",true);
|
2011-12-01 08:58:49 -06:00
|
|
|
var record = {};
|
|
|
|
target_facet.save(record);
|
|
|
|
|
2011-11-18 19:47:39 -06:00
|
|
|
same(record.type[0], data.result.result.type,
|
2011-02-07 22:02:43 -06:00
|
|
|
"saved type matches sample data");
|
2010-10-25 18:55:57 -05:00
|
|
|
|
2012-01-03 03:57:59 -06:00
|
|
|
same(get_visible_rows(target_widget), ['memberof', 'type', 'attrs'],
|
2011-12-01 08:58:49 -06:00
|
|
|
'type and attrs rows visible');
|
|
|
|
|
|
|
|
ok((record.attrs.length > 10),
|
|
|
|
"response length shows some attrs set");
|
2010-10-25 18:55:57 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2011-02-07 22:02:43 -06:00
|
|
|
test("Testing filter target.", function() {
|
2010-10-25 18:55:57 -05:00
|
|
|
|
2011-11-18 19:47:39 -06:00
|
|
|
var data = {};
|
|
|
|
data.result = {};
|
|
|
|
data.result.result = {
|
|
|
|
filter: 'somevalue'
|
|
|
|
};
|
2010-10-25 18:55:57 -05:00
|
|
|
|
2011-11-18 19:47:39 -06:00
|
|
|
target_facet.load(data);
|
2011-12-01 08:58:49 -06:00
|
|
|
|
|
|
|
var record = {};
|
|
|
|
target_facet.save(record);
|
2010-10-25 18:55:57 -05:00
|
|
|
|
2011-12-01 08:58:49 -06:00
|
|
|
same(target_widget.target, 'filter', 'filter selected');
|
|
|
|
|
2012-02-22 05:53:00 -06:00
|
|
|
same(get_visible_rows(target_widget), ['filter', 'attrs_multi'], 'filter row visible');
|
2011-12-01 08:58:49 -06:00
|
|
|
|
2011-11-18 19:47:39 -06:00
|
|
|
ok(record.filter[0], data.result.result.filter, 'filter set correctly');
|
2011-02-07 22:02:43 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test("Testing subtree target.", function() {
|
2010-10-25 18:55:57 -05:00
|
|
|
|
2011-11-18 19:47:39 -06:00
|
|
|
var data = {};
|
|
|
|
data.result = {};
|
|
|
|
data.result.result = {
|
|
|
|
subtree: 'ldap:///cn=*,cn=roles,cn=accounts,dc=example,dc=co'
|
|
|
|
};
|
2010-10-25 18:55:57 -05:00
|
|
|
|
2011-11-18 19:47:39 -06:00
|
|
|
target_facet.load(data);
|
2011-02-07 22:02:43 -06:00
|
|
|
var record = {};
|
2011-12-01 08:58:49 -06:00
|
|
|
target_facet.save(record);
|
|
|
|
|
2011-11-18 19:47:39 -06:00
|
|
|
same(record.subtree[0], data.result.result.subtree, 'subtree set correctly');
|
2011-12-01 08:58:49 -06:00
|
|
|
|
2012-04-02 08:22:07 -05:00
|
|
|
same(get_visible_rows(target_widget), ['memberof', 'subtree', 'attrs_multi'], 'subtree row visible');
|
2010-10-25 18:55:57 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|