123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544 |
- /**
- * 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() {
- it('componentToUserMap is empty', function() {
- controller.set('componentToUserMap', {});
- expect(controller.buildComponentToOwnerMap([])).to.eql({});
- });
- it('componentToUserMap has properties', function() {
- controller.set('componentToUserMap', {'COMP1': 'config1'});
- var securityUsers = [{
- name: 'config1',
- value: 'value1'
- }];
- expect(controller.buildComponentToOwnerMap(securityUsers)).to.eql({'COMP1': 'value1'});
- });
- });
- describe('#setComponentsConfig()', function() {
- modelSetup.setupStackServiceComponent();
- beforeEach(function(){
- controller.set('content.serviceConfigProperties', [
- {
- serviceName: 'HDFS',
- name: 'principal1',
- value: '_HOST'
- },
- {
- serviceName: 'HDFS',
- name: 'keytab1',
- value: 'value1'
- }
- ]);
- });
- it('componentToConfigMap is empty', function() {
- controller.set('componentToConfigMap', []);
- var result = [];
- controller.setComponentsConfig(result, Em.Object.create(), 'hadoopGroupId');
- expect(result).to.be.empty;
- });
- it('isHadoop2Stack = false, when component from stack2', function() {
- sinon.stub(App, 'get', function () {
- return false;
- });
- controller.set('componentToConfigMap', [{
- componentName: 'DATANODE',
- principal: 'principal1',
- keytab: 'keytab1',
- displayName: 'displayName1',
- isHadoop2Stack: true
- }]);
- var host = Em.Object.create({
- hostComponents: [{componentName: 'DATANODE'}],
- hostName: 'host1'
- });
- var result = [];
- controller.setComponentsConfig(result, host, 'hadoopGroupId');
- expect(result).to.be.empty;
- App.get.restore();
- });
- it('isHadoop2Stack = true, when component from stack2', function() {
- sinon.stub(App, 'get', function () {
- return true;
- });
- controller.set('componentToConfigMap', [{
- componentName: 'DATANODE',
- principal: 'principal1',
- keytab: 'keytab1',
- displayName: 'displayName1',
- isHadoop2Stack: true
- }]);
- 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.set('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.set('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('#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');
- });
- });
- describe('#getSecurityUsers()', function () {
- it('testMode is true, testModeUsers is empty', function () {
- controller.set('testModeUsers', []);
- App.testMode = true;
- expect(controller.getSecurityUsers()).to.eql([]);
- });
- it('testMode is true, testModeUsers is correct', function () {
- controller.set('testModeUsers', [
- {
- name: 'user1',
- value: 'value1'
- }
- ]);
- App.testMode = true;
- expect(controller.getSecurityUsers()).to.eql([
- {
- id: 'puppet var',
- name: 'user1',
- value: 'value1'
- }
- ]);
- });
- it('testMode is false', function () {
- sinon.stub(App.db, 'getSecureUserInfo', function () {
- return [{}];
- });
- App.testMode = false;
- expect(controller.getSecurityUsers()).to.eql([{}]);
- expect(App.db.getSecureUserInfo.calledOnce).to.be.true;
- App.db.getSecureUserInfo.restore();
- });
- });
- });
|