You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ak...@apache.org on 2016/06/14 16:48:09 UTC
ambari git commit: AMBARI-17222. Unable to assign roles for both user
and group with the same name (akovalenko)
Repository: ambari
Updated Branches:
refs/heads/trunk e2d564cda -> 03260b60a
AMBARI-17222. Unable to assign roles for both user and group with the same name (akovalenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/03260b60
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/03260b60
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/03260b60
Branch: refs/heads/trunk
Commit: 03260b60a9ea8ada5d4a2ebf826208ea47edcbae
Parents: e2d564c
Author: Aleksandr Kovalenko <ak...@hortonworks.com>
Authored: Tue Jun 14 16:53:06 2016 +0300
Committer: Aleksandr Kovalenko <ak...@hortonworks.com>
Committed: Tue Jun 14 16:53:15 2016 +0300
----------------------------------------------------------------------
.../app/scripts/services/PermissionsSaver.js | 17 +-
.../test/unit/services/PermissionSaver_test.js | 257 +++++++++++++++++++
2 files changed, 268 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/03260b60/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/PermissionsSaver.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/PermissionsSaver.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/PermissionsSaver.js
index bebd668..bc53dad 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/PermissionsSaver.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/services/PermissionsSaver.js
@@ -152,21 +152,26 @@ angular.module('ambariAdminConsole')
}
function passOneRoleCheck(arr) {
- var hash = {};
+ var hashes = {};
for(var i = 0; i < arr.length; i++) {
- var obj = arr[i];
- if (hash[obj.PrivilegeInfo.principal_name] && obj.PrivilegeInfo.principal_name !== "*") {
+ var obj = arr[i],
+ type = obj.PrivilegeInfo.principal_type,
+ name = obj.PrivilegeInfo.principal_name;
+ if (!hashes[type]) {
+ hashes[type] = {};
+ }
+ if (hashes[type][name] && name !== "*") {
return false;
} else {
- hash[obj.PrivilegeInfo.principal_name] = true;
+ hashes[type][name] = true;
}
}
return true;
}
return {
- saveClusterPermissions: function(oldPermissions, newPermissions, params) {
- return savePermissionsFor(Cluster, oldPermissions, newPermissions, params);
+ saveClusterPermissions: function(permissions, params) {
+ return savePermissionsFor(Cluster, permissions, params);
},
saveViewPermissions: function(permissions, params) {
return savePermissionsFor(View, permissions, params);
http://git-wip-us.apache.org/repos/asf/ambari/blob/03260b60/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/PermissionSaver_test.js
----------------------------------------------------------------------
diff --git a/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/PermissionSaver_test.js b/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/PermissionSaver_test.js
new file mode 100644
index 0000000..fa36d98
--- /dev/null
+++ b/ambari-admin/src/main/resources/ui/admin-web/test/unit/services/PermissionSaver_test.js
@@ -0,0 +1,257 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+describe('PermissionSaver Service', function () {
+ var PermissionSaver, $Cluster, $View;
+
+ beforeEach(function () {
+ module('ambariAdminConsole', angular.noop);
+ inject(function (_PermissionSaver_, _Cluster_, _View_) {
+ PermissionSaver = _PermissionSaver_;
+ $Cluster = _Cluster_;
+ $View = _View_;
+ });
+ });
+
+ describe('#saveClusterPermissions', function () {
+
+ var params = {
+ clusterId: 'c0'
+ },
+ cases = [
+ {
+ permissions: {
+ 'CLUSTER.ADMINISTRATOR': {
+ PermissionInfo: {
+ permission_name: 'CLUSTER.ADMINISTRATOR'
+ },
+ USER: ['u0', 'u1', 'g0'],
+ GROUP: ['g0', 'g1', 'u0']
+ },
+ 'CLUSTER.OPERATOR': {
+ PermissionInfo: {
+ permission_name: 'CLUSTER.OPERATOR'
+ },
+ USER: ['g1'],
+ GROUP: ['u1']
+ }
+ },
+ updatePrivilegesCallCount: 1,
+ generatedPermissions: [
+ {
+ PrivilegeInfo: {
+ permission_name: 'CLUSTER.ADMINISTRATOR',
+ principal_name: 'u0',
+ principal_type: 'USER'
+ }
+ },
+ {
+ PrivilegeInfo: {
+ permission_name: 'CLUSTER.ADMINISTRATOR',
+ principal_name: 'u1',
+ principal_type: 'USER'
+ }
+ },
+ {
+ PrivilegeInfo: {
+ permission_name: 'CLUSTER.ADMINISTRATOR',
+ principal_name: 'g0',
+ principal_type: 'USER'
+ }
+ },
+ {
+ PrivilegeInfo: {
+ permission_name: 'CLUSTER.ADMINISTRATOR',
+ principal_name: 'g0',
+ principal_type: 'GROUP'
+ }
+ },
+ {
+ PrivilegeInfo: {
+ permission_name: 'CLUSTER.ADMINISTRATOR',
+ principal_name: 'g1',
+ principal_type: 'GROUP'
+ }
+ },
+ {
+ PrivilegeInfo: {
+ permission_name: 'CLUSTER.ADMINISTRATOR',
+ principal_name: 'u0',
+ principal_type: 'GROUP'
+ }
+ },
+ {
+ PrivilegeInfo: {
+ permission_name: 'CLUSTER.OPERATOR',
+ principal_name: 'g1',
+ principal_type: 'USER'
+ }
+ },
+ {
+ PrivilegeInfo: {
+ permission_name: 'CLUSTER.OPERATOR',
+ principal_name: 'u1',
+ principal_type: 'GROUP'
+ }
+ }
+ ],
+ title: 'valid data'
+ },
+ {
+ permissions: {
+ 'CLUSTER.ADMINISTRATOR': {
+ PermissionInfo: {
+ permission_name: 'CLUSTER.ADMINISTRATOR'
+ },
+ USER: ['u0', 'u1'],
+ GROUP: ['g0', 'g1']
+ },
+ 'CLUSTER.OPERATOR': {
+ PermissionInfo: {
+ permission_name: 'CLUSTER.OPERATOR'
+ },
+ USER: ['u0'],
+ GROUP: ['g2']
+ },
+ 'CLUSTER.USER': {
+ PermissionInfo: {
+ permission_name: 'CLUSTER.USER'
+ },
+ USER: ['u2'],
+ GROUP: ['g0']
+ }
+ },
+ updatePrivilegesCallCount: 0,
+ title: 'invalid data'
+ }
+ ];
+
+ angular.forEach(cases, function (item) {
+
+ describe(item.title, function () {
+
+ beforeEach(function () {
+ spyOn($Cluster, 'updatePrivileges').andCallFake(angular.noop);
+ PermissionSaver.saveClusterPermissions(item.permissions, params);
+ });
+
+ it('updatePrivileges call', function () {
+ expect($Cluster.updatePrivileges.callCount).toEqual(item.updatePrivilegesCallCount);
+ });
+
+ if (item.updatePrivilegesCallCount) {
+ it('updatePrivileges arguments', function () {
+ expect($Cluster.updatePrivileges).toHaveBeenCalledWith(params, item.generatedPermissions);
+ });
+ }
+
+ });
+
+ });
+
+ });
+
+ describe('#saveViewPermissions', function () {
+
+ var params = {
+ instance_name: 'i0',
+ version: '1.0.0',
+ view_name: 'v0'
+ },
+ permissions = {
+ 'VIEW.USER': {
+ 'PermissionInfo': {
+ permission_name: 'VIEW.USER'
+ },
+ 'ALL.CLUSTER.ADMINISTRATOR': true,
+ 'ALL.CLUSTER.OPERATOR': false,
+ 'ALL.SERVICE.OPERATOR': false,
+ 'ALL.SERVICE.ADMINISTRATOR': false,
+ 'ALL.CLUSTER.USER': false,
+ 'USER': ['u0', 'u1', 'g0'],
+ 'GROUP': ['g0', 'g1', 'u0']
+ }
+ },
+ generatedPermissions = [
+ {
+ PrivilegeInfo: {
+ permission_name: 'VIEW.USER',
+ principal_name: 'u0',
+ principal_type: 'USER'
+ }
+ },
+ {
+ PrivilegeInfo: {
+ permission_name: 'VIEW.USER',
+ principal_name: 'u1',
+ principal_type: 'USER'
+ }
+ },
+ {
+ PrivilegeInfo: {
+ permission_name: 'VIEW.USER',
+ principal_name: 'g0',
+ principal_type: 'USER'
+ }
+ },
+ {
+ PrivilegeInfo: {
+ permission_name: 'VIEW.USER',
+ principal_name: 'g0',
+ principal_type: 'GROUP'
+ }
+ },
+ {
+ PrivilegeInfo: {
+ permission_name: 'VIEW.USER',
+ principal_name: 'g1',
+ principal_type: 'GROUP'
+ }
+ },
+ {
+ PrivilegeInfo: {
+ permission_name: 'VIEW.USER',
+ principal_name: 'u0',
+ principal_type: 'GROUP'
+ }
+ },
+ {
+ PrivilegeInfo: {
+ permission_name: 'VIEW.USER',
+ principal_name: '*',
+ principal_type: 'ALL.CLUSTER.ADMINISTRATOR'
+ }
+ }
+ ];
+
+ beforeEach(function () {
+ spyOn($View, 'updatePrivileges').andCallFake(angular.noop);
+ PermissionSaver.saveViewPermissions(permissions, params);
+ });
+
+ it('should update privileges', function () {
+ expect($View.updatePrivileges.callCount).toEqual(1);
+ });
+
+ it('updatePrivileges arguments', function () {
+ expect($View.updatePrivileges).toHaveBeenCalledWith(params, generatedPermissions);
+ });
+
+ });
+
+});