Repository: ambari Updated Branches: refs/heads/trunk 59a74cfda -> c61933d87
http://git-wip-us.apache.org/repos/asf/ambari/blob/c61933d8/ambari-web/test/controllers/main/admin/security/add/step3_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/admin/security/add/step3_test.js b/ambari-web/test/controllers/main/admin/security/add/step3_test.js deleted file mode 100644 index 8324fda..0000000 --- a/ambari-web/test/controllers/main/admin/security/add/step3_test.js +++ /dev/null @@ -1,560 +0,0 @@ -/** - * 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'); - -require('controllers/main/admin/security/add/step3'); -var stringUtils = require('utils/string_utils'); -var modelSetup = require('test/init_model_test'); - -describe('App.MainAdminSecurityAddStep3Controller', function () { - - var controller = App.MainAdminSecurityAddStep3Controller.create({ - content: {} - }); - - describe('#openInfoInNewTab()', function() { - it('Correct data', function() { - var mock = { - document: { - write: function(){} - }, - focus: function(){} - }; - sinon.stub(window, 'open', function () { - return mock; - }); - sinon.stub(stringUtils, 'arrayToCSV', function () { - return 'CSV_CONTENT'; - }); - sinon.spy(mock.document, 'write'); - sinon.spy(mock, 'focus'); - controller.set('hostComponents', ['comp1']); - - controller.openInfoInNewTab(); - expect(window.open.calledWith('')).to.be.true; - expect(stringUtils.arrayToCSV.calledWith(['comp1'])).to.be.true; - expect(mock.document.write.calledWith('CSV_CONTENT')).to.be.true; - expect(mock.focus.calledOnce).to.be.true; - window.open.restore(); - stringUtils.arrayToCSV.restore(); - }); - }); - - describe('#loadStep()', function() { - - beforeEach(function(){ - sinon.stub(controller, 'getSecurityUsers', function () { - return [{ - name: 'user_group', - value: 'value1' - }]; - }); - }); - afterEach(function(){ - controller.getSecurityUsers.restore(); - }); - - it('No hosts installed', function() { - controller.set('hosts', []); - controller.loadStep(); - expect(controller.get('hostComponents')).to.be.empty; - }); - it('One host installed', function () { - controller.set('hosts', [Em.Object.create({hostName: 'host1'})]); - sinon.stub(controller, 'setMandatoryConfigs', function (result) { - return result.push('setMandatoryConfigs'); - }); - sinon.stub(controller, 'setComponentsConfig', function (result) { - return result.push('setComponentsConfig'); - }); - sinon.stub(controller, 'setHostComponentsSecureValue', function (result) { - return result.push('setHostComponentsSecureValue'); - }); - - controller.loadStep(); - expect(controller.setMandatoryConfigs.calledOnce).to.be.true; - expect(controller.setComponentsConfig.calledOnce).to.be.true; - expect(controller.setHostComponentsSecureValue.calledOnce).to.be.true; - expect(controller.get('hostComponents')).to.eql(["setMandatoryConfigs", "setComponentsConfig", "setHostComponentsSecureValue"]); - - controller.setMandatoryConfigs.restore(); - controller.setComponentsConfig.restore(); - controller.setHostComponentsSecureValue.restore(); - }); - }); - - describe('#buildComponentToOwnerMap()', function() { - beforeEach(function(){ - sinon.stub(controller, 'getSecurityUsers', function () { - return [{ - name: 'storm_user', - value: 'storm' - }]; - }); - }); - afterEach(function(){ - controller.getSecurityUsers.restore(); - }); - - it('componentToUserMap is empty', function() { - sinon.stub(controller, 'get').withArgs('componentToUserMap').returns({}); - expect(controller.buildComponentToOwnerMap([])).to.eql({}); - controller.get.restore(); - }); - it('componentToUserMap has properties', function() { - var securityUsers = [{ - name: 'config1', - value: 'value1' - }]; - sinon.stub(controller, 'get').withArgs('componentToUserMap').returns({'COMP1': 'config1'}); - expect(controller.buildComponentToOwnerMap(securityUsers)).to.eql({'COMP1': 'value1'}); - controller.get.restore(); - }); - }); - - describe('#setComponentsConfig()', function() { - - beforeEach(function(){ - modelSetup.setupStackServiceComponent(); - controller.set('content.serviceConfigProperties', [ - { - serviceName: 'HDFS', - name: 'principal1', - value: '_HOST' - }, - { - serviceName: 'HDFS', - name: 'keytab1', - value: 'value1' - } - ]); - }); - - afterEach(function() { - modelSetup.cleanStackServiceComponent(); - }); - - it('componentToConfigMap is empty', function() { - controller.reopen({ - componentToConfigMap: [] - }); - var result = []; - controller.setComponentsConfig(result, Em.Object.create({hostName: 'c6401',hostComponents: []}), 'hadoopGroupId'); - expect(result).to.be.empty; - }); - it('when component from stack2', function() { - sinon.stub(App, 'get', function () { - return true; - }); - controller.reopen({ - componentToConfigMap: [{ - componentName: 'DATANODE', - principal: 'principal1', - keytab: 'keytab1', - displayName: 'displayName1' - }] - }); - var host = Em.Object.create({ - hostComponents: [{componentName: 'DATANODE'}], - hostName: 'host1' - }); - var result = []; - controller.setComponentsConfig(result, host, 'hadoopGroupId'); - expect(result.length).to.equal(1); - App.get.restore(); - }); - it('Component does not match host-component', function() { - controller.reopen({ - componentToConfigMap: [{ - componentName: 'DATANODE', - principal: 'principal1', - keytab: 'keytab1', - displayName: 'displayName1' - }] - }); - var host = Em.Object.create({ - hostComponents: [{componentName: 'DATANODE1'}], - hostName: 'host1' - }); - var result = []; - controller.setComponentsConfig(result, host, 'hadoopGroupId'); - expect(result).to.be.empty; - }); - it('Component matches host-component', function() { - controller.reopen({ - componentToConfigMap: [{ - componentName: 'DATANODE', - principal: 'principal1', - keytab: 'keytab1', - displayName: 'displayName1' - }] - }); - var host = Em.Object.create({ - hostComponents: [{componentName: 'DATANODE'}], - hostName: 'host1' - }); - var result = []; - controller.setComponentsConfig(result, host, 'hadoopGroupId'); - expect(result.length).to.equal(1); - }); - }); - - describe('#setMandatoryConfigs()', function() { - - beforeEach(function () { - sinon.stub(App.Service, 'find', function () { - return [ - {serviceName: 'SERVICE1'} - ]; - }); - controller.set('content.serviceConfigProperties', [ - { - serviceName: 'GENERAL', - name: 'kerberos_domain', - value: 'realm1' - } - ]); - }); - afterEach(function () { - App.Service.find.restore(); - }); - - it('mandatoryConfigs is empty', function() { - var result = []; - controller.set('mandatoryConfigs', []); - - controller.setMandatoryConfigs(result, [], '', ''); - expect(result).to.be.empty; - }); - it('config has unknown service to check', function() { - var result = []; - controller.set('mandatoryConfigs', [{ - userConfig: 'kerberos_domain', - keytab: 'kerberos_domain', - displayName: '', - checkService: 'HBASE' - }]); - - controller.setMandatoryConfigs(result, [], '', ''); - expect(result).to.be.empty; - }); - it('config should be added', function() { - var result = []; - controller.set('mandatoryConfigs', [{ - userConfig: 'userConfig1', - keytab: 'kerberos_domain', - displayName: '' - }]); - var securityUsers = [{ - name: 'userConfig1', - value: 'value1' - }]; - - controller.setMandatoryConfigs(result, securityUsers, '', ''); - expect(result.length).to.equal(1); - }); - }); - - describe('#setHostComponentsSecureValue()', function() { - - beforeEach(function () { - sinon.stub(controller, 'buildComponentToOwnerMap', Em.K); - sinon.stub(controller, 'changeDisplayName', Em.K); - sinon.stub(controller, 'getSecureProperties', function(){ - return {principal: '', keytab: ''}; - }); - }); - afterEach(function () { - controller.buildComponentToOwnerMap.restore(); - controller.changeDisplayName.restore(); - controller.getSecureProperties.restore(); - }); - - it('host.hostComponents is empty', function() { - var result = []; - var host = Em.Object.create({ - hostComponents: [] - }); - - controller.setHostComponentsSecureValue(result, host); - expect(result).to.be.empty; - }); - it('host-component does not match component to display', function() { - var result = []; - var host = Em.Object.create({ - hostComponents: [Em.Object.create({ - componentName: 'UNKNOWN' - })] - }); - - controller.setHostComponentsSecureValue(result, host); - expect(result).to.be.empty; - }); - it('host-component matches component to display', function() { - var result = []; - var host = Em.Object.create({ - hostComponents: [Em.Object.create({ - componentName: 'DATANODE' - })] - }); - - controller.setHostComponentsSecureValue(result, host, {}, [], ''); - expect(result.length).to.equal(1); - }); - it('addedPrincipalsHost already contain such config', function() { - var result = []; - var host = Em.Object.create({ - hostName: 'host1', - hostComponents: [Em.Object.create({ - componentName: 'DATANODE' - })] - }); - - controller.setHostComponentsSecureValue(result, host, {'host1--': true}, [], ''); - expect(result.length).to.be.empty; - }); - }); - - describe('#setHostComponentsSecureValue()', function () { - - it('DRPC Server principal should point to Nimbus host for HDP-2.2 stack', function () { - sinon.stub(App, 'get').withArgs('isHadoop22Stack').returns(true); - sinon.stub(controller, 'get').withArgs('content.serviceConfigProperties').returns([]); - sinon.stub(controller, 'getNimbusHostName').returns('nimbus_host'); - sinon.stub(controller, 'buildComponentToOwnerMap').returns({'DRPC_SERVER': 'storm'}); - sinon.stub(controller, 'getSecureProperties').returns({ - "keytab": "/etc/security/keytabs/nimbus.service.keytab", - "principal": "nimbus/nimbus_host" - }); - sinon.stub(controller, 'getSecurityUsers', function () { - return [ - { - name: 'storm_user', - value: 'storm' - } - ]; - }); - var host = Em.Object.create({ - hostComponents: [Em.Object.create({ - componentName: 'DRPC_SERVER', - displayName: 'DRPC Server' - })] - }); - - var result = []; - controller.setHostComponentsSecureValue(result, host, {}, [], 'hadoopId'); - expect(result).to.be.not.empty; - expect(controller.getSecureProperties.args[0][2]).to.equal('nimbus_host'); - - var hostComponent = result[0]; - expect(hostComponent.principal).to.equal('nimbus/nimbus_host'); - expect(hostComponent.owner).to.equal('storm'); - - App.get.restore(); - controller.get.restore(); - controller.getNimbusHostName.restore(); - controller.buildComponentToOwnerMap.restore(); - controller.getSecureProperties.restore(); - controller.getSecurityUsers.restore(); - }); - }); - - describe('#getSecureProperties()', function () { - - beforeEach(function () { - sinon.stub(controller, 'getPrincipal', function () { - return 'principal'; - }); - }); - afterEach(function () { - controller.getPrincipal.restore(); - }); - - var testCases = [ - { - title: 'serviceConfigs is empty', - content: { - serviceConfigs: [], - componentName: '' - }, - result: {} - }, - { - title: 'Config has component that does not match component name', - content: { - serviceConfigs: [{ - component: 'comp1' - }], - componentName: 'comp2' - }, - result: {} - }, - { - title: 'Config has components that does not match component name', - content: { - serviceConfigs: [{ - components: ['comp1'] - }], - componentName: 'comp2' - }, - result: {} - }, - { - title: 'Config has component that matches component name', - content: { - serviceConfigs: [{ - name: 'C_principal_name', - component: 'comp1', - value: 'value1' - }], - componentName: 'comp1' - }, - result: { - principal: 'principal' - } - }, - { - title: 'Config has components that matches component name', - content: { - serviceConfigs: [{ - name: 'C_principal_name', - components: ['comp1'], - value: 'value1' - }], - componentName: 'comp1' - }, - result: { - principal: 'principal' - } - }, - { - title: 'Config name without correct postfix', - content: { - serviceConfigs: [{ - name: 'config1', - component: 'comp1', - value: 'value1' - }], - componentName: 'comp1' - }, - result: {} - }, - { - title: 'Config name with "_keytab" postfix', - content: { - serviceConfigs: [{ - name: 'c_keytab', - component: 'comp1', - value: 'value1' - }], - componentName: 'comp1' - }, - result: { - keytab: 'value1' - } - }, - { - title: 'Config name with "_keytab_path" postfix', - content: { - serviceConfigs: [{ - name: 'c_keytab_path', - component: 'comp1', - value: 'value1' - }], - componentName: 'comp1' - }, - result: { - keytab: 'value1' - } - } - ]; - - testCases.forEach(function (test) { - it(test.title, function () { - expect(controller.getSecureProperties(test.content.serviceConfigs, test.content.componentName, '')).to.eql(test.result); - }); - }); - }); - - describe('#getPrincipal()', function () { - - var testCases = [ - { - title: 'Config value missing "_HOST" string, unit is empty', - content: { - config: { - value: 'value1', - unit: '' - }, - hostName: '' - }, - result: 'value1' - }, - { - title: 'Config value missing "_HOST" string, unit is correct', - content: { - config: { - value: 'value1', - unit: 'unit1' - }, - hostName: '' - }, - result: 'value1unit1' - }, - { - title: 'Config value contains "_HOST" string, host name in lowercase', - content: { - config: { - value: '_HOST', - unit: 'unit1' - }, - hostName: 'host1' - }, - result: 'host1unit1' - }, - { - title: 'Config value contains "_HOST" string, host name in uppercase', - content: { - config: { - value: '_HOST', - unit: 'unit1' - }, - hostName: 'HOST1' - }, - result: 'host1unit1' - } - ]; - - testCases.forEach(function (test) { - it(test.title, function () { - expect(controller.getPrincipal(test.content.config, test.content.hostName)).to.equal(test.result); - }); - }); - }); - - describe('#changeDisplayName()', function() { - it('name is HiveServer2', function() { - expect(controller.changeDisplayName('HiveServer2')).to.equal('Hive Metastore and HiveServer2'); - }); - it('name is not HiveServer2', function() { - expect(controller.changeDisplayName('something')).to.equal('something'); - }); - }); -}); http://git-wip-us.apache.org/repos/asf/ambari/blob/c61933d8/ambari-web/test/controllers/main/admin/security/add/step4_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/admin/security/add/step4_test.js b/ambari-web/test/controllers/main/admin/security/add/step4_test.js deleted file mode 100644 index bdc6e10..0000000 --- a/ambari-web/test/controllers/main/admin/security/add/step4_test.js +++ /dev/null @@ -1,484 +0,0 @@ -/** - * 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'); -require('controllers/main/admin/security/security_progress_controller'); -require('controllers/main/admin/security/add/step4'); -require('mixins/wizard/addSecurityConfigs'); -require('utils/polling'); -require('models/cluster_states'); -require('models/service'); - -var controller; - -describe('App.MainAdminSecurityAddStep4Controller', function () { - - beforeEach(function () { - controller = App.MainAdminSecurityAddStep4Controller.create({ - content: {}, - commands: [], - enableSubmit: function () { - this._super() - }, - secureMapping: [], - secureProperties: [], - secureServices: [] - }); - }); - - describe('#isBackBtnDisabled', function () { - it('commands have error', function () { - controller.set('commands', [Em.Object.create({ - isError: true - })]); - expect(controller.get('isBackBtnDisabled')).to.be.false; - }); - it('commands do not have error', function () { - controller.set('commands', [Em.Object.create({ - isError: false - })]); - expect(controller.get('isBackBtnDisabled')).to.be.true; - }); - }); - - describe('#isSecurityApplied', function () { - var testCases = [ - { - title: 'No START_SERVICES command', - commands: [], - result: false - }, - { - title: 'START_SERVICES is not success', - commands: [Em.Object.create({ - name: 'START_SERVICES', - isSuccess: false - })], - result: false - }, - { - title: 'START_SERVICES is success', - commands: [Em.Object.create({ - name: 'START_SERVICES', - isSuccess: true - })], - result: true - } - ]; - - testCases.forEach(function (test) { - it(test.title, function () { - controller.set('commands', test.commands); - expect(controller.get('isSecurityApplied')).to.equal(test.result); - }); - }); - }); - - describe('#enableSubmit()', function () { - var mock = { - setStepsEnable: Em.K, - setLowerStepsDisable: Em.K - }; - - beforeEach(function () { - sinon.stub(App.router, 'get', function () { - return mock; - }); - sinon.spy(mock, 'setStepsEnable'); - sinon.spy(mock, 'setLowerStepsDisable'); - }); - afterEach(function () { - App.router.get.restore(); - mock.setStepsEnable.restore(); - mock.setLowerStepsDisable.restore(); - }); - - it('Command has error', function () { - controller.set('commands', [Em.Object.create({ - isError: true - })]); - controller.enableSubmit(); - expect(controller.get('isSubmitDisabled')).to.be.false; - expect(mock.setStepsEnable.calledOnce).to.be.true; - }); - it('Command is successful', function () { - controller.set('commands', [Em.Object.create({ - isSuccess: true - })]); - controller.enableSubmit(); - expect(controller.get('isSubmitDisabled')).to.be.false; - }); - it('Command is in progress', function () { - controller.set('commands', [Em.Object.create()]); - controller.enableSubmit(); - expect(controller.get('isSubmitDisabled')).to.be.true; - expect(mock.setLowerStepsDisable.calledWith(4)).to.be.true; - }); - }); - - describe('#clearStep()', function () { - it('Clear step info', function () { - controller.set('commands', [Em.Object.create()]); - controller.set('isSubmitDisabled', false); - controller.set('serviceConfigTags', [ - {} - ]); - controller.clearStep(); - expect(controller.get('isSubmitDisabled')).to.be.true; - expect(controller.get('commands')).to.be.empty; - expect(controller.get('serviceConfigTags')).to.be.empty; - }); - }); - - describe('#loadCommands()', function () { - - before(function () { - sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K); - }); - - after(function () { - App.clusterStatus.setClusterStatus.restore(); - }); - - var tests = Em.A([ - { - doesATSSupportKerberos: true, - isATSInstalled: true, - e: { - l: 3, - d: false - } - }, - { - doesATSSupportKerberos: true, - isATSInstalled: false, - e: { - l: 3, - d: false - } - }, - { - doesATSSupportKerberos: false, - isATSInstalled: true, - e: { - l: 4, - d: true - } - }, - { - doesATSSupportKerberos: false, - isATSInstalled: false, - e: { - l: 3, - d: false - } - } - ]); - - tests.forEach(function (test) { - it('doesATSSupportKerberos ' + test.doesATSSupportKerberos.toString() + ', isATSInstalled ' + test.isATSInstalled.toString(), function () { - sinon.stub(App, 'get', function (k) { - if ('doesATSSupportKerberos' === k) return test.doesATSSupportKerberos; - return Em.get(App, k); - }); - controller.set('content.isATSInstalled', test.isATSInstalled); - controller.loadCommands(); - App.get.restore(); - expect(controller.get('commands.length')).to.equal(test.e.l); - expect(controller.get('commands').someProperty('name', 'DELETE_ATS')).to.equal(test.e.d); - }); - }); - - }); - - describe('#loadStep()', function () { - - beforeEach(function () { - sinon.stub(controller, 'clearStep', Em.K); - sinon.stub(controller, 'prepareSecureConfigs', Em.K); - }); - afterEach(function () { - controller.clearStep.restore(); - controller.prepareSecureConfigs.restore(); - controller.resumeSavedCommands.restore(); - }); - - it('Resume saved commands', function () { - sinon.stub(controller, 'resumeSavedCommands', function () { - return true; - }); - - controller.loadStep(); - expect(controller.clearStep.calledOnce).to.be.true; - expect(controller.prepareSecureConfigs.calledOnce).to.be.true; - expect(controller.resumeSavedCommands.calledOnce).to.be.true; - }); - it('No saved commands', function () { - sinon.stub(controller, 'resumeSavedCommands', function () { - return false; - }); - sinon.stub(controller, 'loadCommands', Em.K); - sinon.stub(controller, 'addInfoToCommands', Em.K); - sinon.stub(controller, 'syncStopServicesOperation', Em.K); - sinon.stub(controller, 'addObserverToCommands', Em.K); - sinon.stub(controller, 'moveToNextCommand', Em.K); - - controller.loadStep(); - expect(controller.clearStep.calledOnce).to.be.true; - expect(controller.prepareSecureConfigs.calledOnce).to.be.true; - expect(controller.resumeSavedCommands.calledOnce).to.be.true; - - controller.loadCommands.restore(); - controller.addInfoToCommands.restore(); - controller.syncStopServicesOperation.restore(); - controller.addObserverToCommands.restore(); - controller.moveToNextCommand.restore(); - }); - }); - - describe('#syncStopServicesOperation()', function () { - - afterEach(function () { - App.router.get.restore(); - }); - - it('No running operations', function () { - sinon.stub(App.router, 'get', function () { - return []; - }); - - expect(controller.syncStopServicesOperation()).to.be.false; - }); - it('Running operation is not Stop All Services', function () { - sinon.stub(App.router, 'get', function () { - return [Em.Object.create({isRunning: true})]; - }); - - expect(controller.syncStopServicesOperation()).to.be.false; - }); - it('No STOP_SERVICES in commands', function () { - sinon.stub(App.router, 'get', function () { - return [Em.Object.create({ - isRunning: true, - name: 'Stop All Services' - })]; - }); - controller.set('commands', []); - - expect(controller.syncStopServicesOperation()).to.be.false; - }); - it('Sync stop services commands', function () { - sinon.stub(App.router, 'get', function () { - return [Em.Object.create({ - isRunning: true, - name: 'Stop All Services', - id: 1 - })]; - }); - controller.set('commands', [Em.Object.create({ - name: 'STOP_SERVICES' - })]); - - expect(controller.syncStopServicesOperation()).to.be.true; - expect(controller.get('commands').findProperty('name', 'STOP_SERVICES').get('requestId')).to.equal(1); - }); - }); - - describe('#resumeSavedCommands()', function () { - - beforeEach(function () { - sinon.stub(controller, 'addObserverToCommands', Em.K); - sinon.stub(controller, 'moveToNextCommand', Em.K); - controller.set('commands', []); - }); - afterEach(function () { - controller.moveToNextCommand.restore(); - controller.addObserverToCommands.restore(); - App.db.getSecurityDeployCommands.restore(); - }); - - - it('Commands is null', function () { - sinon.stub(App.db, 'getSecurityDeployCommands', function () { - return null; - }); - expect(controller.resumeSavedCommands()).to.be.false; - }); - it('Commands is empty', function () { - sinon.stub(App.db, 'getSecurityDeployCommands', function () { - return []; - }); - expect(controller.resumeSavedCommands()).to.be.false; - }); - it('Command has error', function () { - sinon.stub(App.db, 'getSecurityDeployCommands', function () { - return [ - { - isError: true, - name: 'command1' - } - ]; - }); - expect(controller.resumeSavedCommands()).to.be.true; - expect(controller.get('commands').mapProperty('name')).to.eql(['command1']); - expect(controller.addObserverToCommands.calledOnce).to.be.true; - }); - it('Command in progress', function () { - sinon.stub(App.db, 'getSecurityDeployCommands', function () { - return [ - { - isStarted: true, - isCompleted: false, - name: 'command1' - } - ]; - }); - expect(controller.resumeSavedCommands()).to.be.true; - expect(controller.get('commands').mapProperty('name')).to.eql(['command1']); - expect(controller.get('commands').findProperty('name', 'command1').get('isStarted')).to.be.false; - expect(controller.addObserverToCommands.calledOnce).to.be.true; - expect(controller.moveToNextCommand.calledOnce).to.be.true; - }); - it('Command completed', function () { - sinon.stub(App.db, 'getSecurityDeployCommands', function () { - return [ - { - isCompleted: true, - name: 'command1' - } - ]; - }); - expect(controller.resumeSavedCommands()).to.be.true; - expect(controller.get('commands').mapProperty('name')).to.eql(['command1']); - expect(controller.addObserverToCommands.calledOnce).to.be.true; - expect(controller.moveToNextCommand.calledOnce).to.be.true; - }); - }); - - describe('#manageSecureConfigs()', function () { - - beforeEach(function () { - sinon.stub(controller, 'setPrincipalValue', Em.K); - }); - afterEach(function () { - controller.setPrincipalValue.restore(); - }); - - it('serviceConfigTags is null', function () { - sinon.stub(controller, 'onJsError', Em.K); - controller.set('serviceConfigTags', null); - controller.set('configs', [ - {id: 'site property'} - ]); - controller.set('commands', [Em.Object.create({ - name: 'APPLY_CONFIGURATIONS' - })]); - - expect(controller.manageSecureConfigs()).to.be.false; - expect(controller.onJsError.calledOnce).to.be.true; - expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isSuccess')).to.be.false; - expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isError')).to.be.true; - - controller.onJsError.restore(); - }); - it('Add configs from site-*.xml', function () { - controller.set('serviceConfigTags', [ - { - siteName: 'site1', - configs: {} - } - ]); - controller.set('configs', [ - { - id: 'site property', - name: 'config1', - value: "value1", - filename: 'site1.xml' - } - ]); - - expect(controller.manageSecureConfigs()).to.be.true; - expect(controller.get('serviceConfigTags')[0].configs).to.eql({'config1': 'value1'}); - }); - it('Add configs from global.xml, config matches "_hosts"', function () { - controller.reopen({ - secureConfigs: [ - { - serviceName: 'service1', - name: 'config1' - } - ] - }); - - controller.set('serviceConfigTags', [ - { - siteName: 'global', - configs: {} - } - ]); - controller.set('globalProperties', [ - { - id: 'site property', - name: 'config1_hosts', - value: "value1", - filename: 'site1.xml' - } - ]); - - expect(controller.manageSecureConfigs()).to.be.true; - expect(controller.get('serviceConfigTags')[0].configs).to.eql({}); - expect(controller.setPrincipalValue.calledWith('service1', 'config1')).to.be.true; - }); - }); - - describe('#deleteComponents()', function () { - it('Send ajax', function () { - sinon.stub(App.ajax, 'send', Em.K); - - controller.deleteComponents('comp1', 'host1'); - expect(App.ajax.send.calledOnce).to.be.true; - - App.ajax.send.restore(); - }); - }); - - describe('#onDeleteComplete()', function () { - it('', function () { - controller.set('commands', [Em.Object.create({ - name: 'DELETE_ATS' - })]); - - controller.onDeleteComplete(); - expect(controller.get('commands').findProperty('name', 'DELETE_ATS').get('isError')).to.be.false; - expect(controller.get('commands').findProperty('name', 'DELETE_ATS').get('isSuccess')).to.be.true; - }); - }); - - describe('#onJsError()', function () { - it('Show popup', function () { - sinon.stub(App.ModalPopup, 'show', Em.K); - - controller.onJsError(); - expect(App.ModalPopup.show.calledOnce).to.be.true; - - App.ModalPopup.show.restore(); - }); - }); - -}); http://git-wip-us.apache.org/repos/asf/ambari/blob/c61933d8/ambari-web/test/controllers/main/admin/security/disable_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/admin/security/disable_test.js b/ambari-web/test/controllers/main/admin/security/disable_test.js deleted file mode 100644 index 82d11d1..0000000 --- a/ambari-web/test/controllers/main/admin/security/disable_test.js +++ /dev/null @@ -1,386 +0,0 @@ -/** - * 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'); -require('controllers/main/admin/security/disable'); - - -describe('App.MainAdminSecurityDisableController', function () { - - var controller = App.MainAdminSecurityDisableController.create({ - serviceConfigTags: null, - secureProperties: null, - secureMapping: null - }); - - - describe('#resumeCommands()', function () { - var context = { - getSecurityDeployCommands: function () { - return this.testData; - } - }; - - var mock = { - setStepsEnable: Em.K, - setLowerStepsDisable: Em.K - }; - - beforeEach(function () { - sinon.stub(App.db, "getSecurityDeployCommands", context.getSecurityDeployCommands); - sinon.stub(App.router, 'get', function () { - return mock; - }); - }); - afterEach(function () { - App.db.getSecurityDeployCommands.restore(); - App.router.get.restore(); - }); - - it('commands are absent in local storage', function () { - App.db.testData = null; - expect(controller.resumeCommands()).to.be.false; - }); - it('zero commands in local storage', function () { - App.db.testData = []; - expect(controller.resumeCommands()).to.be.false; - }); - it('one command is present', function () { - App.db.testData = [ - { - name: 'command1' - } - ]; - controller.get('commands').clear(); - expect(controller.resumeCommands()).to.be.true; - expect(controller.get('commands').mapProperty('name')).to.eql(['command1']); - }); - it('command is started and completed', function () { - App.db.testData = [ - { - name: 'command1', - isStarted: true, - isCompleted: true - } - ]; - controller.get('commands').clear(); - expect(controller.resumeCommands()).to.be.true; - expect(controller.get('commands').mapProperty('name')).to.eql(['command1']); - expect(controller.get('commands').findProperty('name', 'command1').get('isStarted')).to.be.true; - }); - it('command is started but not completed', function () { - App.db.testData = [ - { - name: 'command1', - isStarted: true, - isCompleted: false - } - ]; - controller.get('commands').clear(); - expect(controller.resumeCommands()).to.be.true; - expect(controller.get('commands').mapProperty('name')).to.eql(['command1']); - expect(controller.get('commands').findProperty('name', 'command1').get('isStarted')).to.be.false; - }); - }); - - describe('#isSubmitDisabled', function () { - var testCases = [ - { - title: 'commands is empty', - commands: [], - result: false - }, - { - title: 'one started command', - commands: [Em.Object.create({ - isStarted: true - })], - result: true - }, - { - title: 'one failed command', - commands: [Em.Object.create({ - isError: true - })], - result: false - }, - { - title: 'one success command', - commands: [Em.Object.create({ - isSuccess: true - })], - result: false - }, - { - title: 'not all commands are success', - commands: [ - Em.Object.create({ - isSuccess: true - }), - Em.Object.create({ - isSuccess: false - }) - ], - result: true - } - ]; - - testCases.forEach(function (test) { - it(test.title, function () { - controller.set('commands', test.commands); - expect(controller.get('isSubmitDisabled')).to.equal(test.result); - }); - }); - }); - - describe('#syncStopServicesCommand()', function () { - - it('No background operations', function () { - controller.set('commands', [Em.Object.create({ - name: 'STOP_SERVICES', - requestId: 1 - })]); - controller.syncStopServicesCommand.apply(controller); - expect(controller.get('commands').findProperty('name', 'STOP_SERVICES').get('requestId')).to.equal(1); - }); - it('background operation is not running', function () { - App.router.set('backgroundOperationsController.services', [ - Em.Object.create({ - isRunning: false - }) - ]); - controller.syncStopServicesCommand.apply(controller); - expect(controller.get('commands').findProperty('name', 'STOP_SERVICES').get('requestId')).to.equal(1); - }); - it('background operation is running but not "Stop All Services"', function () { - App.router.set('backgroundOperationsController.services', [ - Em.Object.create({ - isRunning: true - }) - ]); - controller.syncStopServicesCommand.apply(controller); - expect(controller.get('commands').findProperty('name', 'STOP_SERVICES').get('requestId')).to.equal(1); - }); - it('"Stop All Services" operation is running', function () { - App.router.set('backgroundOperationsController.services', [ - Em.Object.create({ - name: 'Stop All Services', - isRunning: true, - id: 2 - }) - ]); - controller.syncStopServicesCommand.apply(controller); - expect(controller.get('commands').findProperty('name', 'STOP_SERVICES').get('requestId')).to.equal(2); - }); - }); - - describe('#manageSecureConfigs()', function () { - - beforeEach(function () { - sinon.stub(controller, "modifySiteConfigs", Em.K); - }); - afterEach(function () { - controller.modifySiteConfigs.restore(); - }); - - var testCases = [ - { - title: 'serviceConfigTags, secureProperties, secureMapping are null', - content: { - serviceConfigTags: null, - secureProperties: null, - secureMapping: null - } - }, - { - title: 'serviceConfigTags is null', - content: { - serviceConfigTags: null, - secureProperties: [], - secureMapping: [] - } - }, - { - title: 'secureProperties is null', - content: { - serviceConfigTags: [], - secureProperties: null, - secureMapping: [] - } - }, - { - title: 'secureMapping is null', - content: { - serviceConfigTags: [], - secureProperties: [], - secureMapping: null - } - } - ]; - - testCases.forEach(function (test) { - it(test.title, function () { - controller.set('commands', [Em.Object.create({ - name: 'APPLY_CONFIGURATIONS' - })]); - controller.set('serviceConfigTags', test.content.serviceConfigTags); - controller.set('secureProperties', test.content.secureProperties); - controller.set('secureMapping', test.content.secureMapping); - - expect(controller.manageSecureConfigs()).to.be.false; - expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isSuccess')).to.be.false; - expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isError')).to.be.true; - }); - }); - it('serviceConfigTags is empty', function () { - controller.set('serviceConfigTags', []); - controller.set('secureProperties', []); - controller.set('secureMapping', []); - - expect(controller.manageSecureConfigs()).to.be.true; - }); - it('serviceConfigTags has cluster-env site', function () { - controller.set('serviceConfigTags', [ - { - siteName: 'cluster-env', - configs: {} - } - ]); - - expect(controller.manageSecureConfigs()).to.be.true; - expect(controller.get('serviceConfigTags').findProperty('siteName', 'cluster-env').configs.security_enabled).to.equal('false'); - }); - it('serviceConfigTags has site.xml', function () { - controller.set('serviceConfigTags', [ - { - siteName: 'site' - } - ]); - expect(controller.manageSecureConfigs()).to.be.true; - expect(controller.modifySiteConfigs.calledOnce).to.be.true; - }); - }); - - describe('#modifySiteConfigs()', function () { - var testCases = [ - { - title: '_serviceConfigTags and secureMapping are null', - content: { - secureMapping: null, - _serviceConfigTags: null - }, - result: false - }, - { - title: '_serviceConfigTags is null', - content: { - secureMapping: [], - _serviceConfigTags: null - }, - result: false - }, - { - title: 'secureMapping is null', - content: { - secureMapping: null, - _serviceConfigTags: {} - }, - result: false - }, - { - title: 'secureMapping and _serviceConfigTags are empty', - content: { - secureMapping: [], - _serviceConfigTags: { - configs: {} - } - }, - result: true - } - ]; - - testCases.forEach(function (test) { - it(test.title, function () { - expect(controller.modifySiteConfigs(test.content.secureMapping, test.content._serviceConfigTags)).to.equal(test.result); - }); - }); - it('secureMapping doesn\'t contain passed siteName', function () { - var secureMapping = []; - var _serviceConfigTags = { - configs: { - 'config2': true - }, - siteName: 'site1' - }; - expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true; - expect(_serviceConfigTags.configs.config2).to.be.true; - }); - it('secureMapping contain passed siteName but doesn\'t match config name', function () { - var secureMapping = [ - { - filename: 'site1.xml' - } - ]; - var _serviceConfigTags = { - configs: { - 'config2': true - }, - siteName: 'site1' - }; - expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true; - expect(_serviceConfigTags.configs.config2).to.be.true; - }); - it('secureMapping contain passed siteName and match config name', function () { - var secureMapping = [ - { - filename: 'site1.xml', - name: 'config2' - } - ]; - var _serviceConfigTags = { - configs: { - 'config2': true - }, - siteName: 'site1' - }; - expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true; - expect(_serviceConfigTags.configs.config2).to.be.undefined; - }); - it('secureMapping contain passed siteName and included in secureConfigValuesMap', function () { - var secureMapping = [ - { - filename: 'site1.xml', - name: 'config2', - nonSecureValue: 'nonSecureValue' - } - ]; - var _serviceConfigTags = { - configs: { - 'config2': true - }, - siteName: 'site1' - }; - controller.set('secureConfigValuesMap', { - 'config2': 'value' - }); - expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true; - expect(_serviceConfigTags.configs.config2).to.equal('nonSecureValue'); - }); - }); -}); http://git-wip-us.apache.org/repos/asf/ambari/blob/c61933d8/ambari-web/test/controllers/main/admin/security/security_progress_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/admin/security/security_progress_controller_test.js b/ambari-web/test/controllers/main/admin/security/security_progress_controller_test.js deleted file mode 100644 index 3ad07f7..0000000 --- a/ambari-web/test/controllers/main/admin/security/security_progress_controller_test.js +++ /dev/null @@ -1,443 +0,0 @@ -/** - * 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'); -require('controllers/main/admin/security/security_progress_controller'); -require('models/host_component'); -require('models/host'); - -describe('App.MainAdminSecurityProgressController', function () { - - var controller = App.MainAdminSecurityProgressController.create({ - loadClusterConfigs: function () {}, - deleteComponents: function () {} - }); - - describe('#retry()', function () { - - beforeEach(function () { - sinon.spy(controller, "startCommand"); - }); - afterEach(function () { - controller.startCommand.restore(); - }); - - it('commands are empty', function () { - controller.set('commands', []); - controller.retry(); - expect(controller.startCommand.called).to.be.false; - }); - - it('command is successful', function () { - controller.set('commands', [ - Em.Object.create({ - name: 'test', - isSuccess: true, - isError: false, - isStarted: true - }) - ]); - controller.retry(); - expect(controller.startCommand.calledOnce).to.be.false; - expect(controller.get('commands').findProperty('name', 'test').get('isError')).to.be.false; - expect(controller.get('commands').findProperty('name', 'test').get('isStarted')).to.be.true; - }); - - it('command is failed', function () { - controller.set('commands', [ - Em.Object.create({ - name: 'test', - isSuccess: true, - isError: true, - isStarted: true - }) - ]); - controller.retry(); - expect(controller.startCommand.calledOnce).to.be.true; - expect(controller.get('commands').findProperty('name', 'test').get('isError')).to.be.false; - expect(controller.get('commands').findProperty('name', 'test').get('isStarted')).to.be.false; - }); - }); - - describe('#updateServices()', function () { - - it('commands are empty', function () { - controller.set('services', [ - {} - ]); - controller.set('commands', []); - controller.updateServices(); - expect(controller.get('services')).to.be.empty; - }); - - it('command doesn\'t have polledData', function () { - controller.set('services', [ - {} - ]); - controller.set('commands', [Em.Object.create({ - label: 'label' - })]); - controller.updateServices(); - expect(controller.get('services')).to.be.empty; - }); - - it('command has polledData', function () { - controller.set('services', [ - {} - ]); - controller.set('commands', [Em.Object.create({ - label: 'service1', - polledData: [ - { - Tasks: { - host_name: 'host1' - } - } - ] - })]); - controller.updateServices(); - expect(controller.get('services').findProperty('name', 'service1').get('hosts')).to.eql([ - { - name: 'host1', - publicName: 'host1', - logTasks: [ - { - Tasks: {host_name: 'host1'} - } - ] - } - ]); - }); - }); - - describe('#setIndex()', function () { - it('commandArray is empty', function () { - var commandArray = []; - controller.setIndex(commandArray); - expect(commandArray).to.be.empty; - expect(controller.get('totalSteps')).to.equal(0); - }); - it('one command in commandArray', function () { - var commandArray = [ - Em.Object.create({name: 'command1'}) - ]; - controller.setIndex(commandArray); - expect(commandArray[0].get('index')).to.equal(1); - expect(controller.get('totalSteps')).to.equal(1); - }); - it('commands with random indexes', function () { - var commandArray = []; - commandArray[3] = Em.Object.create({name: 'command3'}); - commandArray[11] = Em.Object.create({name: 'command11'}); - controller.setIndex(commandArray); - expect(commandArray[3].get('index')).to.equal(4); - expect(commandArray[11].get('index')).to.equal(12); - expect(controller.get('totalSteps')).to.equal(12); - }); - }); - - describe('#startCommand()', function () { - - var command = Em.Object.create({ - start: Em.K - }); - - beforeEach(function () { - sinon.spy(command, "start"); - sinon.spy(controller, "loadClusterConfigs"); - sinon.spy(controller, "deleteComponents"); - sinon.stub(controller, "saveCommands", Em.K); - }); - - afterEach(function () { - command.start.restore(); - controller.loadClusterConfigs.restore(); - controller.deleteComponents.restore(); - controller.saveCommands.restore(); - }); - - it('number of commands doesn\'t match totalSteps', function () { - controller.set('commands', []); - controller.set('totalSteps', 1); - expect(controller.startCommand()).to.be.false; - }); - - it('commands is empty', function () { - controller.set('commands', []); - controller.set('totalSteps', 0); - expect(controller.startCommand()).to.be.false; - }); - - it('command is started and completed', function () { - controller.set('commands', [Em.Object.create({ - isStarted: true, - isCompleted: true - })]); - controller.set('totalSteps', 1); - expect(controller.startCommand()).to.be.false; - }); - - it('command is started and incompleted', function () { - controller.set('commands', [Em.Object.create({ - isStarted: true, - isCompleted: false - })]); - controller.set('totalSteps', 1); - expect(controller.startCommand()).to.be.true; - }); - - it('command parameter passed, isPolling is true', function () { - controller.set('commands', []); - controller.set('totalSteps', 0); - command.set('isPolling', true); - expect(controller.startCommand(command)).to.be.true; - expect(command.get('isStarted')).to.be.true; - expect(command.start.calledOnce).to.be.true; - command.set('isPolling', false); - }); - - it('command parameter passed, name is "APPLY_CONFIGURATIONS"', function () { - command.set('name', 'APPLY_CONFIGURATIONS'); - expect(controller.startCommand(command)).to.be.true; - expect(command.get('isStarted')).to.be.true; - expect(controller.loadClusterConfigs.calledOnce).to.be.true; - }); - - it('command parameter passed, name is "DELETE_ATS"', function () { - command.set('name', 'DELETE_ATS'); - - sinon.stub(App.HostComponent, 'find', function() { - return [Em.Object.create({ - id: 'APP_TIMELINE_SERVER_ats_host', - componentName: 'APP_TIMELINE_SERVER', - hostName: 'ats_host' - })]; - }); - expect(controller.startCommand(command)).to.be.true; - expect(command.get('isStarted')).to.be.true; - expect(controller.deleteComponents.calledWith('APP_TIMELINE_SERVER', 'ats_host')).to.be.true; - - App.HostComponent.find.restore(); - }); - - }); - - describe('#onCompleteCommand()', function () { - - beforeEach(function () { - sinon.spy(controller, "moveToNextCommand"); - sinon.stub(controller, "saveCommands", Em.K); - }); - afterEach(function () { - controller.moveToNextCommand.restore(); - controller.saveCommands.restore(); - - }); - - it('number of commands doesn\'t match totalSteps', function () { - controller.set('commands', []); - controller.set('totalSteps', 1); - expect(controller.onCompleteCommand()).to.be.false; - }); - it('No successful commands', function () { - controller.set('commands', [Em.Object.create({ - isSuccess: false - })]); - controller.set('totalSteps', 1); - expect(controller.onCompleteCommand()).to.be.false; - }); - it('No successful commands', function () { - controller.set('commands', [Em.Object.create({ - isSuccess: false - })]); - controller.set('totalSteps', 1); - expect(controller.onCompleteCommand()).to.be.false; - }); - it('Last command is successful', function () { - controller.set('commands', [ - Em.Object.create({ - isSuccess: false - }), - Em.Object.create({ - isSuccess: true - }) - ]); - controller.set('totalSteps', 2); - expect(controller.onCompleteCommand()).to.be.false; - }); - it('all commands are successful', function () { - controller.set('commands', [ - Em.Object.create({ - isSuccess: true, - name: 'command1' - }), - Em.Object.create({ - isSuccess: false, - name: 'command2' - }) - ]); - controller.set('totalSteps', 2); - expect(controller.onCompleteCommand()).to.be.true; - expect(controller.moveToNextCommand.calledWith(Em.Object.create({ - isSuccess: false, - name: 'command2' - }))).to.be.true; - }); - }); - - describe('#moveToNextCommand()', function () { - - beforeEach(function () { - sinon.spy(controller, "startCommand"); - }); - afterEach(function () { - controller.startCommand.restore(); - }); - - it('No commands present', function () { - controller.set('commands', []); - expect(controller.moveToNextCommand()).to.be.false; - }); - it('Only started command present', function () { - controller.set('commands', [ - Em.Object.create({ - isStarted: true - }) - ]); - expect(controller.moveToNextCommand()).to.be.false; - }); - it('Command is not started', function () { - controller.set('commands', [ - Em.Object.create({ - isStarted: false, - name: 'command1' - }) - ]); - expect(controller.moveToNextCommand()).to.be.true; - expect(controller.startCommand.calledWith(Em.Object.create({ - isStarted: false, - name: 'command1' - }))).to.be.true; - }); - it('Next command provide as argument', function () { - var nextCommand = Em.Object.create({ - isStarted: false, - name: 'command2' - }); - expect(controller.moveToNextCommand(nextCommand)).to.be.true; - expect(controller.startCommand.calledWith(Em.Object.create({ - isStarted: false, - name: 'command2' - }))).to.be.true; - }); - }); - - describe('#setServiceTagNames()', function () { - var testCases = [ - { - title: 'configs is empty object', - content: { - secureService: {}, - configs: {} - }, - result: undefined - }, - { - title: 'secureService.sites is null', - content: { - secureService: { - sites: null - }, - configs: { - site1: {} - } - }, - result: undefined - }, - { - title: 'secureService.sites doesn\'t contain required config tag', - content: { - secureService: { - sites: [] - }, - configs: { - site1: {} - } - }, - result: undefined - }, - { - title: 'secureService.sites contains required config tag', - content: { - secureService: { - sites: ['site1'] - }, - configs: { - site1: { - tag: 'tag1' - } - } - }, - result: { - siteName: 'site1', - tagName: 'tag1', - newTagName: null, - configs: {} - } - } - ]; - testCases.forEach(function (test) { - it(test.title, function () { - expect(controller.setServiceTagNames(test.content.secureService, test.content.configs)).to.eql(test.result); - }); - }); - }); - - describe('#modifyConfigsForSecure', function () { - var cfg = { - properties: { - 'ui.childopts': 'value1', - 'supervisor.childopts': 'value2', - 'common_property': 'value4' - } - }; - var siteName = 'storm-site'; - var result = { - 'ui.childopts': 'value1 -Djava.security.auth.login.config=/etc/storm/conf/storm_jaas.conf', - 'supervisor.childopts': 'value2 -Djava.security.auth.login.config=/etc/storm/conf/storm_jaas.conf', - 'common_property': 'value4' - }; - var propertiesToUpdate = [ - { - siteName: 'storm-site', - name: 'ui.childopts', - append: ' -Djava.security.auth.login.config=/etc/storm/conf/storm_jaas.conf' - }, - { - siteName: 'storm-site', - name: 'supervisor.childopts', - append: ' -Djava.security.auth.login.config=/etc/storm/conf/storm_jaas.conf' - } - ]; - it("should change some storm sonfigs", function () { - controller.set('propertiesToUpdate', propertiesToUpdate); - expect(controller.modifyConfigsForSecure(siteName, cfg)).to.eql(result); - }); - }); -}); http://git-wip-us.apache.org/repos/asf/ambari/blob/c61933d8/ambari-web/test/controllers/main/admin/security_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/admin/security_test.js b/ambari-web/test/controllers/main/admin/security_test.js deleted file mode 100644 index 8557c6c..0000000 --- a/ambari-web/test/controllers/main/admin/security_test.js +++ /dev/null @@ -1,235 +0,0 @@ -/** - * 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'); -require('controllers/main/admin/security'); - - -describe('App.MainAdminSecurityController', function () { - - var controller = App.MainAdminSecurityController.create({ - getServiceConfigsFromServer: function () { - } , - services: [{serviceName: 'HDFS'}] - }); - - describe('#setServiceTagNames()', function () { - var testCases = [ - { - title: 'configs is empty object', - content: { - secureService: {}, - configs: {} - }, - result: undefined - }, - { - title: 'secureService.sites is null', - content: { - secureService: { - sites: null - }, - configs: { - site1: {} - } - }, - result: undefined - }, - { - title: 'secureService.sites doesn\'t contain required config tag', - content: { - secureService: { - sites: [] - }, - configs: { - site1: {} - } - }, - result: undefined - }, - { - title: 'secureService.sites contains required config tag', - content: { - secureService: { - sites: ['site1'] - }, - configs: { - site1: { - tag: 'tag1' - } - } - }, - result: { - siteName: 'site1', - tagName: 'tag1', - newTagName: null, - configs: {} - } - } - ]; - testCases.forEach(function (test) { - it(test.title, function () { - expect(controller.setServiceTagNames(test.content.secureService, test.content.configs)).to.eql(test.result); - }); - }); - }); - - describe('#getSecurityStatusFromServerSuccessCallback()', function () { - - beforeEach(function () { - sinon.spy(controller, 'showSecurityErrorPopup'); - sinon.spy(controller, 'getServiceConfigsFromServer'); - }); - afterEach(function () { - controller.showSecurityErrorPopup.restore(); - controller.getServiceConfigsFromServer.restore(); - }); - - it('desired_configs is empty', function () { - var data = {Clusters: { - desired_configs: {} - }}; - controller.getSecurityStatusFromServerSuccessCallback(data); - expect(controller.showSecurityErrorPopup.called).to.equal(true); - }); - - it('cluster-env is missing', function () { - var data = {Clusters: { - desired_configs: { - 'hdfs-site': {} - } - }}; - controller.getSecurityStatusFromServerSuccessCallback(data); - expect(controller.showSecurityErrorPopup.called).to.equal(true); - }); - - it('cluster-env and hdfs-site are correct', function () { - var data = {Clusters: { - desired_configs: { - 'hdfs-site': { - tag: 1 - }, - 'cluster-env': { - tag: 2 - }, - 'hadoop-env': { - tag: 3 - } - } - }}; - controller.getSecurityStatusFromServerSuccessCallback(data); - expect(controller.get('tag.cluster-env')).to.equal(2); - expect(controller.get('tag.hdfs-site')).to.equal(1); - expect(controller.getServiceConfigsFromServer.called).to.equal(true); - }); - }); - - - describe('#setNnHaStatus()', function () { - - beforeEach(function () { - sinon.stub(App.db, "setIsNameNodeHa", Em.K); - }); - afterEach(function () { - App.db.setIsNameNodeHa.restore(); - }); - - - it('hdfsConfigs is null', function () { - var hdfsConfigs = null; - controller.setNnHaStatus(hdfsConfigs); - expect(App.db.setIsNameNodeHa.withArgs('false').called).to.equal(true); - }); - - it('"dfs.nameservices" is absent in hdfsConfigs', function () { - var hdfsConfigs = {}; - controller.setNnHaStatus(hdfsConfigs); - expect(App.db.setIsNameNodeHa.withArgs('false').called).to.equal(true); - }); - - it('namenodesKey is absent in hdfsConfigs', function () { - var hdfsConfigs = { - 'dfs.nameservices': 'key' - }; - controller.setNnHaStatus(hdfsConfigs); - expect(App.db.setIsNameNodeHa.withArgs('false').called).to.equal(true); - }); - - it('namenodesKey is present in hdfsConfigs', function () { - var hdfsConfigs = { - 'dfs.nameservices': 'key', - 'dfs.ha.namenodes.key': 'true' - }; - controller.setNnHaStatus(hdfsConfigs); - expect(App.db.setIsNameNodeHa.withArgs('true').called).to.equal(true); - }); - }); - - describe('#loadUsers()', function () { - - beforeEach(function () { - sinon.stub(App.db, "setSecureUserInfo", Em.K); - }); - afterEach(function () { - App.db.setSecureUserInfo.restore(); - }); - - it('if defaultUserNameMap is empty then serviceUsers stays the same', function () { - var configs = {}; - controller.set('serviceUsers', []); - controller.set('userNameMap', {}); - controller.loadUsers(configs); - expect(controller.get('serviceUsers')).to.be.empty; - }); - - it('if user config value is missing then use default', function () { - var configs = {}; - controller.set('serviceUsers', []); - controller.set('userNameMap', { - test_user: {defaultValue: 'test', siteName: 'test-env', serviceName: 'TEST' - }}); - controller.loadUsers(configs); - expect(controller.get('serviceUsers')).to.eql([ - { - "id": "puppet var", - "name": "test_user", - "value": "test" - } - ]); - }); - - it('user config value has value', function () { - var configs = { - 'test_user': 'config-value' - }; - controller.set('serviceUsers', []); - controller.set('defaultUserNameMap', { - test_user: {defaultValue: 'test', siteName: 'test-env', serviceName: 'TEST' - }}); - controller.loadUsers(configs); - expect(controller.get('serviceUsers')).to.eql([ - { - "id": "puppet var", - "name": "test_user", - "value": "config-value" - } - ]); - }); - }); -}); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/c61933d8/ambari-web/test/controllers/main/host/details_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/host/details_test.js b/ambari-web/test/controllers/main/host/details_test.js index 4023a0e..0eb81db 100644 --- a/ambari-web/test/controllers/main/host/details_test.js +++ b/ambari-web/test/controllers/main/host/details_test.js @@ -397,17 +397,6 @@ describe('App.MainHostDetailsController', function () { }); }); - describe('#securityEnabled', function () { - it('', function () { - sinon.stub(App.router, 'get').withArgs('mainAdminSecurityController.securityEnabled').returns(true); - - controller.propertyDidChange('securityEnabled'); - expect(controller.get('securityEnabled')).to.be.true; - App.router.get.restore(); - }); - }); - - describe('#addComponent()', function () { beforeEach(function () { sinon.spy(App, "showConfirmationPopup"); @@ -416,15 +405,14 @@ describe('App.MainHostDetailsController', function () { controller.set('content', {hostComponents: [Em.Object.create({ componentName: "HDFS_CLIENT" })]}); - controller.reopen({ - securityEnabled: false - }); + sinon.stub(componentsUtils, 'checkComponentDependencies', Em.K); }); afterEach(function () { App.showConfirmationPopup.restore(); controller.addClientComponent.restore(); controller.primary.restore(); + componentsUtils.checkComponentDependencies.restore(); }); it('add ZOOKEEPER_SERVER', function () { http://git-wip-us.apache.org/repos/asf/ambari/blob/c61933d8/ambari-web/test/controllers/wizard/step8_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/wizard/step8_test.js b/ambari-web/test/controllers/wizard/step8_test.js index a869663..6207372 100644 --- a/ambari-web/test/controllers/wizard/step8_test.js +++ b/ambari-web/test/controllers/wizard/step8_test.js @@ -19,7 +19,6 @@ var App = require('app'); var modelSetup = require('test/init_model_test'); require('utils/ajax/ajax_queue'); -require('controllers/main/admin/security'); require('controllers/main/service/info/configs'); require('controllers/wizard/step8_controller'); var installerStep8Controller, configurationController; http://git-wip-us.apache.org/repos/asf/ambari/blob/c61933d8/ambari-web/test/mixins/wizard/addSeccurityConfigs_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/mixins/wizard/addSeccurityConfigs_test.js b/ambari-web/test/mixins/wizard/addSeccurityConfigs_test.js index c02d894..5fcd724 100644 --- a/ambari-web/test/mixins/wizard/addSeccurityConfigs_test.js +++ b/ambari-web/test/mixins/wizard/addSeccurityConfigs_test.js @@ -28,325 +28,9 @@ describe('App.AddSecurityConfigs', function () { content: {}, enableSubmit: function () { this._super(); - }, - secureMapping: [], - secureProperties: [] + } }); - describe('#secureServices', function() { - it('content.services is correct', function() { - controller.set('content.services', [{}]); - expect(controller.get('secureServices')).to.eql([{}]); - controller.reopen({ - secureServices: [] - }); - }); - }); - - describe('#loadUiSideSecureConfigs()', function() { - - beforeEach(function(){ - sinon.stub(controller, 'checkServiceForConfigValue', function() { - return 'value2'; - }); - sinon.stub(controller, 'setConfigValue', Em.K); - sinon.stub(controller, 'formatConfigName', Em.K); - sinon.stub(App.Service, 'find').returns([{serviceName: 'SOME_SERVICE'}]); - }); - afterEach(function(){ - controller.checkServiceForConfigValue.restore(); - controller.setConfigValue.restore(); - controller.formatConfigName.restore(); - App.Service.find.restore(); - }); - - it('secureMapping is empty', function() { - controller.set('secureMapping', []); - - expect(controller.loadUiSideSecureConfigs()).to.be.empty; - }); - it('Config does not have dependedServiceName', function() { - controller.set('secureMapping', [{ - name: 'config1', - value: 'value1', - filename: 'file1', - serviceName: 'SOME_SERVICE', - foreignKey: null - }]); - - expect(controller.loadUiSideSecureConfigs()).to.eql([{ - "id": "site property", - "name": 'config1', - "value": 'value1', - "filename": 'file1' - }]); - }); - it('Config has dependedServiceName', function() { - controller.set('secureMapping', [{ - name: 'config1', - value: 'value1', - filename: 'file1', - foreignKey: null, - serviceName: 'SOME_SERVICE', - dependedServiceName: 'SOME_SERVICE' - }]); - - expect(controller.loadUiSideSecureConfigs()).to.eql([{ - "id": "site property", - "name": 'config1', - "value": 'value2', - "filename": 'file1' - }]); - }); - it('Config has non-existent serviceName', function() { - controller.set('secureMapping', [{ - name: 'config1', - value: 'value1', - filename: 'file1', - foreignKey: true, - serviceName: 'NO_SERVICE' - }]); - - expect(controller.loadUiSideSecureConfigs()).to.be.empty; - }); - it('Config has correct serviceName', function() { - controller.set('secureMapping', [{ - name: 'config1', - value: 'value1', - filename: 'file1', - foreignKey: true, - serviceName: 'SOME_SERVICE' - }]); - - expect(controller.loadUiSideSecureConfigs()).to.eql([{ - "id": "site property", - "name": 'config1', - "value": 'value1', - "filename": 'file1' - }]); - expect(controller.setConfigValue.calledOnce).to.be.true; - expect(controller.formatConfigName.calledOnce).to.be.true; - }); - }); - - describe('#checkServiceForConfigValue()', function() { - it('services is empty', function() { - var services = []; - - expect(controller.checkServiceForConfigValue('value1', services)).to.equal('value1'); - }); - it('Service is loaded', function() { - var services = [{}]; - sinon.stub(App.Service, 'find', function () { - return Em.Object.create({isLoaded: false}); - }); - - expect(controller.checkServiceForConfigValue('value1', services)).to.equal('value1'); - - App.Service.find.restore(); - }); - it('Service is not loaded', function() { - var services = [{ - replace: 'val' - }]; - sinon.stub(App.Service, 'find', function () { - return Em.Object.create({isLoaded: false}); - }); - - expect(controller.checkServiceForConfigValue('value1', services)).to.equal('ue1'); - - App.Service.find.restore(); - }); - }); - - describe('#formatConfigName()', function() { - it('config.value is null', function() { - var config = { - value: null - }; - - expect(controller.formatConfigName([], config)).to.be.false; - }); - it('config.name does not contain foreignKey', function() { - var config = { - value: 'value1', - name: 'config1' - }; - - expect(controller.formatConfigName([], config)).to.be.false; - }); - it('globalProperties is empty, use uiConfig', function() { - var config = { - value: 'value1', - name: '<foreignKey[0]>', - foreignKey: ['key1'] - }; - controller.set('globalProperties', []); - var uiConfig = [{ - name: 'key1', - value: 'globalValue1' - }]; - - expect(controller.formatConfigName(uiConfig, config)).to.be.true; - expect(config._name).to.equal('globalValue1'); - }); - - }); - - describe('#setConfigValue()', function() { - it('config.value is null', function() { - var config = { - value: null - }; - - expect(controller.setConfigValue(config)).to.be.false; - }); - it('config.value does not match "templateName"', function() { - var config = { - value: '' - }; - - expect(controller.setConfigValue(config)).to.be.false; - }); - it('No such property in global configs', function() { - var config = { - value: '<templateName[0]>', - templateName: ['config1'] - }; - controller.set('globalProperties', []); - controller.set('configs', []); - - expect(controller.setConfigValue(config)).to.be.true; - expect(config.value).to.be.null; - }); - - it('Hive Metastore hostname array is converted to string', function () { - var config = { - value: '<templateName[0]>', - templateName: ['hive_metastore'] - }; - controller.set('globalProperties', []); - controller.set('configs', [ - { - name: 'hive_metastore', - value: ['h0', 'h1', 'h2'] - } - ]); - - expect(controller.setConfigValue(config)).to.be.true; - expect(config.value).to.equal('h0,h1,h2'); - }); - - }); - - describe('#addHostConfig()', function() { - - afterEach(function () { - App.Service.find.restore(); - }); - - it('No such service loaded', function() { - sinon.stub(App.Service, 'find', function(){ - return Em.Object.create({isLoaded: false}); - }); - - expect(controller.addHostConfig('service1', 'comp1', 'config1')).to.be.false; - }); - it('No such service in secureServices', function() { - sinon.stub(App.Service, 'find', function(){ - return Em.Object.create({isLoaded: true}); - }); - controller.set('secureServices', []); - - expect(controller.addHostConfig('service1', 'comp1', 'config1')).to.be.false; - }); - it('Service does not have such host-component', function() { - sinon.stub(App.Service, 'find', function(){ - return Em.Object.create({ - isLoaded: true, - hostComponents: [] - }); - }); - controller.set('secureServices', [{ - serviceName: 'service1' - }]); - - expect(controller.addHostConfig('service1', 'comp1', 'config1')).to.be.false; - }); - }); - - describe('#getPrincipalNames()', function() { - - beforeEach(function () { - controller.set('globalProperties', []); - controller.set('secureProperties', []); - }); - - it('globalProperties and secureProperties are empty', function() { - expect(controller.getPrincipalNames()).to.be.empty; - }); - it('global property name does not match "principal_name"', function() { - controller.set('globalProperties', [{ - name: 'config1' - }]); - expect(controller.getPrincipalNames()).to.be.empty; - }); - it('secure property name does not match "principal_name"', function() { - controller.set('secureProperties', [{ - name: 'config1' - }]); - expect(controller.getPrincipalNames()).to.be.empty; - }); - it('property with such name already exists', function() { - controller.set('globalProperties', [{ - name: 'principal_name' - }]); - controller.set('secureProperties', [{ - name: 'principal_name' - }]); - expect(controller.getPrincipalNames().mapProperty('name')).to.eql(['principal_name']); - }); - }); - - describe('#loadUsersFromServer()', function() { - it('testMode = true', function() { - controller.set('testModeUsers', [{ - name: 'user1', - value: 'value1' - }]); - controller.set('serviceUsers', []); - sinon.stub(App, 'get', function(k) { - if ('testMode' === k) return true; - return Em.get(App, k); - }); - - controller.loadUsersFromServer(); - expect(controller.get('serviceUsers')).to.eql([{ - name: 'user1', - value: 'value1', - id: 'puppet var' - }]); - App.get.restore(); - }); - it('testMode = false', function() { - sinon.stub(App.router, 'set', Em.K); - sinon.stub(App.db, 'getSecureUserInfo', function(){ - return []; - }); - sinon.stub(App, 'get', function(k) { - if ('testMode' === k) return false; - return Em.get(App, k); - }); - - controller.loadUsersFromServer(); - expect(App.db.getSecureUserInfo.calledOnce).to.be.true; - expect(App.router.set.calledWith('mainAdminSecurityController.serviceUsers', [])).to.be.true; - - App.router.set.restore(); - App.get.restore(); - App.db.getSecureUserInfo.restore(); - }); - }); describe('#createServicesStackDescriptorConfigs', function() { var result = controller.createServicesStackDescriptorConfigs(stackDescriptorData); @@ -398,14 +82,14 @@ describe('App.AddSecurityConfigs', function () { property: 'realm', e: [ { key: 'isEditable', value: false }, - { key: 'serviceName', value: 'Cluster' }, + { key: 'serviceName', value: 'Cluster' } ] }, { property: 'keytab_dir', e: [ { key: 'isEditable', value: true }, - { key: 'serviceName', value: 'Cluster' }, + { key: 'serviceName', value: 'Cluster' } ] } ]; @@ -459,7 +143,7 @@ describe('App.AddSecurityConfigs', function () { { property: 'dfs.namenode.kerberos.principal', e: [ - { key: 'filename', value: 'hdfs-site' }, + { key: 'filename', value: 'hdfs-site' } ] }, { @@ -571,7 +255,7 @@ describe('App.AddSecurityConfigs', function () { generateProperty('component_prop1_inherited_principal', 'component_prop1:principal'), generateProperty('component_prop1_inherited_keytab', 'component_prop1:keytab'), generateProperty('component_prop2_inherited_keytab', 'component_prop2:keytab'), - generateProperty('component_prop2_inherited_principal', 'component_prop2:principal'), + generateProperty('component_prop2_inherited_principal', 'component_prop2:principal') ]); var tests = [ { name: 'spnego_inherited_keytab', e: 'spnego_keytab' },
