Explorar el Código

AMBARI-12593. Enable Kerberos: Config values should be trimmed v2 (alexantonenko)

Alex Antonenko hace 10 años
padre
commit
10409b3d8a

+ 1 - 0
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',

+ 7 - 1
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);

+ 3 - 0
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,

+ 3 - 1
ambari-web/app/models/configs/objects/service_config_property.js

@@ -422,7 +422,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'))) {
@@ -431,7 +433,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;
             }

+ 4 - 5
ambari-web/app/utils/config.js

@@ -1194,13 +1194,12 @@ 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;
+  trimProperty: function (property) {
+    var displayType = Em.get(property, 'displayType');
+    var value = Em.get(property, 'value');
+    var name = Em.get(property, 'name');
     var rez;
     switch (displayType) {
       case 'directories':

+ 86 - 0
ambari-web/test/controllers/main/admin/kerberos/step2_controller_test.js

@@ -0,0 +1,86 @@
+/**
+ * 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');
+var setups = require('test/init_model_test');
+
+describe('App.KerberosWizardStep2Controller', function() {
+
+  describe('#createKerberosSiteObj', function() {
+    var controller;
+
+    beforeEach(function() {
+      setups.setupStackVersion(this, 'HDP-2.3');
+      controller = App.KerberosWizardStep2Controller.create({});
+      sinon.stub(controller, 'tweakKdcTypeValue', Em.K);
+      sinon.stub(controller, 'tweakManualKdcProperties', Em.K);
+    });
+
+    after(function() {
+      setups.restoreStackVersion(this);
+      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, filename: 'some-site.xml'});
+      }
+    };
+
+    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() {
+        sinon.stub(App.StackService, 'find').returns([Em.Object.create({serviceName: 'KERBEROS'})]);
+        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');
+        App.StackService.find.restore();
+        Em.keys(test.e).forEach(function(propertyName) {
+          expect(result.properties[propertyName]).to.be.eql(test.e[propertyName]);
+        });
+      });
+    });
+  });
+});