Repository: ambari Updated Branches: refs/heads/trunk a1e0caedd -> 178db9fc9
AMBARI-12593. Enable Kerberos: Config values should be trimmed (alexantonenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/178db9fc Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/178db9fc Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/178db9fc Branch: refs/heads/trunk Commit: 178db9fc96d76231ef6449132fc8b1bda3c01999 Parents: 4728e31 Author: Alex Antonenko <[email protected]> Authored: Thu Jul 30 18:18:40 2015 +0300 Committer: Alex Antonenko <[email protected]> Committed: Thu Jul 30 18:31:46 2015 +0300 ---------------------------------------------------------------------- ambari-web/app/assets/test/tests.js | 1 + .../main/admin/kerberos/step2_controller.js | 8 +- ambari-web/app/data/HDP2/site_properties.js | 3 + .../configs/objects/service_config_property.js | 4 +- ambari-web/app/utils/config.js | 11 ++- .../admin/kerberos/step2_controller_test.js | 83 ++++++++++++++++++++ 6 files changed, 102 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/178db9fc/ambari-web/app/assets/test/tests.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js index 45f6df9..5e5f472 100644 --- a/ambari-web/app/assets/test/tests.js +++ b/ambari-web/app/assets/test/tests.js @@ -51,6 +51,7 @@ var files = ['test/init_model_test', 'test/controllers/main/alerts/manage_alert_notifications_controller_test', 'test/controllers/main/admin/kerberos_test', 'test/controllers/main/admin/kerberos/kerberos_wizard_controler_test', + 'test/controllers/main/admin/kerberos/step2_controller_test', 'test/controllers/main/admin/kerberos/step3_controller_test', 'test/controllers/main/admin/kerberos/step4_controller_test', 'test/controllers/main/admin/kerberos/step6_controller_test', http://git-wip-us.apache.org/repos/asf/ambari/blob/178db9fc/ambari-web/app/controllers/main/admin/kerberos/step2_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/admin/kerberos/step2_controller.js b/ambari-web/app/controllers/main/admin/kerberos/step2_controller.js index 8972949..30098c9 100644 --- a/ambari-web/app/controllers/main/admin/kerberos/step2_controller.js +++ b/ambari-web/app/controllers/main/admin/kerberos/step2_controller.js @@ -211,10 +211,16 @@ App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend({ var properties = {}; var content = this.get('stepConfigs')[0].get('configs'); var configs = content.filterProperty('filename', site + '.xml'); + // properties that should be formated as hosts + var hostProperties = ['kdc_host', 'realm']; configs.forEach(function (_configProperty) { // do not pass any globals whose name ends with _host or _hosts if (_configProperty.isRequiredByAgent !== false) { - properties[_configProperty.name] = _configProperty.value; + if (hostProperties.contains(_configProperty.name)) { + properties[_configProperty.name] = App.config.trimProperty({displayType: 'host', value: _configProperty.value}); + } else { + properties[_configProperty.name] = App.config.trimProperty(_configProperty); + } } }, this); this.tweakKdcTypeValue(properties); http://git-wip-us.apache.org/repos/asf/ambari/blob/178db9fc/ambari-web/app/data/HDP2/site_properties.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/data/HDP2/site_properties.js b/ambari-web/app/data/HDP2/site_properties.js index 44833b2..16182b1 100644 --- a/ambari-web/app/data/HDP2/site_properties.js +++ b/ambari-web/app/data/HDP2/site_properties.js @@ -2237,6 +2237,7 @@ var hdp2properties = [ "id": "puppet var", "name": "realm", "displayName": "Realm name", + "displayType": "host", "isOverridable": false, "isVisible": true, "isRequiredByAgent": true, @@ -2250,6 +2251,7 @@ var hdp2properties = [ "id": "puppet var", "name": "ldap_url", "displayName": "LDAP url", + "displayType": "host", "isOverridable": false, "isVisible": false, "serviceName": "KERBEROS", @@ -2453,6 +2455,7 @@ var hdp2properties = [ "id": "puppet var", "name": "admin_server_host", "displayName": "Kadmin host", + "displayType": "host", "isOverridable": false, "isVisible": true, "isRequiredByAgent": true, http://git-wip-us.apache.org/repos/asf/ambari/blob/178db9fc/ambari-web/app/models/configs/objects/service_config_property.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/models/configs/objects/service_config_property.js b/ambari-web/app/models/configs/objects/service_config_property.js index b259f56..239f520 100644 --- a/ambari-web/app/models/configs/objects/service_config_property.js +++ b/ambari-web/app/models/configs/objects/service_config_property.js @@ -428,7 +428,9 @@ App.ServiceConfigProperty = Em.Object.extend({ isError = true; } break; + case 'supportTextConnection': case 'host': + var connectionProperties = ['kdc_host']; var hiveOozieHostNames = ['hive_hostname','hive_existing_mysql_host','hive_existing_oracle_host','hive_ambari_host', 'oozie_hostname','oozie_existing_mysql_host','oozie_existing_oracle_host','oozie_ambari_host']; if(hiveOozieHostNames.contains(this.get('name'))) { @@ -437,7 +439,7 @@ App.ServiceConfigProperty = Em.Object.extend({ isError = true; } } else { - if (validator.isNotTrimmed(value)) { + if ((validator.isNotTrimmed(value) && connectionProperties.contains(this.get('name')) || validator.isNotTrimmed(value))) { this.set('errorMessage', Em.I18n.t('host.trimspacesValidation')); isError = true; } http://git-wip-us.apache.org/repos/asf/ambari/blob/178db9fc/ambari-web/app/utils/config.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/config.js b/ambari-web/app/utils/config.js index fd6e5c8..1cdd8a6 100644 --- a/ambari-web/app/utils/config.js +++ b/ambari-web/app/utils/config.js @@ -1194,14 +1194,13 @@ App.config = Em.Object.create({ * for directory or directories displayType format string for further using. * for password and values with spaces only do nothing. * @param {Object} property - * @param {Boolean} isEmberObject * @returns {*} */ - trimProperty: function (property, isEmberObject) { - var displayType = (isEmberObject) ? property.get('displayType') : property.displayType; - var value = (isEmberObject) ? property.get('value') : property.value; - var name = (isEmberObject) ? property.get('name') : property.name; - var rez; + trimProperty: function (property) { + var displayType = Em.get(property, 'displayType'), + value = Em.get(property, 'value'), + name = Em.get(property, 'name'), + rez; switch (displayType) { case 'directories': case 'directory': http://git-wip-us.apache.org/repos/asf/ambari/blob/178db9fc/ambari-web/test/controllers/main/admin/kerberos/step2_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/admin/kerberos/step2_controller_test.js b/ambari-web/test/controllers/main/admin/kerberos/step2_controller_test.js new file mode 100644 index 0000000..d8fa472 --- /dev/null +++ b/ambari-web/test/controllers/main/admin/kerberos/step2_controller_test.js @@ -0,0 +1,83 @@ +/** + * 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. + */ + +var App = require('app'); + +describe('App.KerberosWizardStep2Controller', function() { + + describe('#createKerberosSiteObj', function() { + var controller; + + beforeEach(function() { + sinon.stub(App, 'get').withArgs('stackVersion').returns('HDP-2.3'); + controller = App.KerberosWizardStep2Controller.create({}); + sinon.stub(controller, 'tweakKdcTypeValue', Em.K); + sinon.stub(controller, 'tweakManualKdcProperties', Em.K); + }); + + after(function() { + App.get.restore(); + controller.tweakKdcTypeValue.restore(); + controller.tweakManualKdcProperties.restore(); + }); + + var _createProperty = function(name, value) { + var preDefProp = App.config.get('preDefinedSiteProperties').findProperty('name', name); + if (preDefProp) { + return App.ServiceConfigProperty.create( + $.extend(true, {}, preDefProp, { + value: value, filename: 'some-site.xml', + isRequiredByAgent: preDefProp.isRequiredByAgent == undefined ? true : preDefProp.isRequiredByAgent + })); + } else { + return App.ServiceConfigProperty.create({name: name, value: value, isRequiredByAgent: true}); + } + }; + + var tests = [ + { + stepConfigs: [ + ['realm', ' SPACES '], + ['admin_server_host', ' space_left'], + ['kdc_host', ' space_left_and_right '], + ['ldap_url', 'space_right '] + ], + e: { + realm: 'SPACES', + admin_server_host: 'space_left', + kdc_host: 'space_left_and_right', + ldap_url: 'space_right' + } + } + ]; + + tests.forEach(function(test) { + it('Should trim values for properties ' + Em.keys(test.e).join(','), function() { + controller.set('stepConfigs', [ + App.ServiceConfig.create({ + configs: test.stepConfigs.map(function(item) { return _createProperty(item[0], item[1]); }) + }) + ]); + var result = controller.createKerberosSiteObj('some-site', 'random-tag'); + Em.keys(test.e).forEach(function(propertyName) { + expect(result.properties[propertyName]).to.be.eql(test.e[propertyName]); + }); + }); + }); + }); +});
