step3_test.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('controllers/main/admin/security/add/step3');
  20. var stringUtils = require('utils/string_utils');
  21. var modelSetup = require('test/init_model_test');
  22. describe('App.MainAdminSecurityAddStep3Controller', function () {
  23. var controller = App.MainAdminSecurityAddStep3Controller.create({
  24. content: {}
  25. });
  26. describe('#openInfoInNewTab()', function() {
  27. it('Correct data', function() {
  28. var mock = {
  29. document: {
  30. write: function(){}
  31. },
  32. focus: function(){}
  33. };
  34. sinon.stub(window, 'open', function () {
  35. return mock;
  36. });
  37. sinon.stub(stringUtils, 'arrayToCSV', function () {
  38. return 'CSV_CONTENT';
  39. });
  40. sinon.spy(mock.document, 'write');
  41. sinon.spy(mock, 'focus');
  42. controller.set('hostComponents', ['comp1']);
  43. controller.openInfoInNewTab();
  44. expect(window.open.calledWith('')).to.be.true;
  45. expect(stringUtils.arrayToCSV.calledWith(['comp1'])).to.be.true;
  46. expect(mock.document.write.calledWith('CSV_CONTENT')).to.be.true;
  47. expect(mock.focus.calledOnce).to.be.true;
  48. window.open.restore();
  49. stringUtils.arrayToCSV.restore();
  50. });
  51. });
  52. describe('#loadStep()', function() {
  53. beforeEach(function(){
  54. sinon.stub(controller, 'getSecurityUsers', function () {
  55. return [{
  56. name: 'user_group',
  57. value: 'value1'
  58. }];
  59. });
  60. });
  61. afterEach(function(){
  62. controller.getSecurityUsers.restore();
  63. });
  64. it('No hosts installed', function() {
  65. controller.set('hosts', []);
  66. controller.loadStep();
  67. expect(controller.get('hostComponents')).to.be.empty;
  68. });
  69. it('One host installed', function () {
  70. controller.set('hosts', [Em.Object.create({hostName: 'host1'})]);
  71. sinon.stub(controller, 'setMandatoryConfigs', function (result) {
  72. return result.push('setMandatoryConfigs');
  73. });
  74. sinon.stub(controller, 'setComponentsConfig', function (result) {
  75. return result.push('setComponentsConfig');
  76. });
  77. sinon.stub(controller, 'setHostComponentsSecureValue', function (result) {
  78. return result.push('setHostComponentsSecureValue');
  79. });
  80. controller.loadStep();
  81. expect(controller.setMandatoryConfigs.calledOnce).to.be.true;
  82. expect(controller.setComponentsConfig.calledOnce).to.be.true;
  83. expect(controller.setHostComponentsSecureValue.calledOnce).to.be.true;
  84. expect(controller.get('hostComponents')).to.eql(["setMandatoryConfigs", "setComponentsConfig", "setHostComponentsSecureValue"]);
  85. controller.setMandatoryConfigs.restore();
  86. controller.setComponentsConfig.restore();
  87. controller.setHostComponentsSecureValue.restore();
  88. });
  89. });
  90. describe('#buildComponentToOwnerMap()', function() {
  91. beforeEach(function(){
  92. sinon.stub(controller, 'getSecurityUsers', function () {
  93. return [{
  94. name: 'storm_user',
  95. value: 'storm'
  96. }];
  97. });
  98. });
  99. afterEach(function(){
  100. controller.getSecurityUsers.restore();
  101. });
  102. it('componentToUserMap is empty', function() {
  103. sinon.stub(controller, 'get').withArgs('componentToUserMap').returns({});
  104. expect(controller.buildComponentToOwnerMap([])).to.eql({});
  105. controller.get.restore();
  106. });
  107. it('componentToUserMap has properties', function() {
  108. var securityUsers = [{
  109. name: 'config1',
  110. value: 'value1'
  111. }];
  112. sinon.stub(controller, 'get').withArgs('componentToUserMap').returns({'COMP1': 'config1'});
  113. expect(controller.buildComponentToOwnerMap(securityUsers)).to.eql({'COMP1': 'value1'});
  114. controller.get.restore();
  115. });
  116. });
  117. describe('#setComponentsConfig()', function() {
  118. beforeEach(function(){
  119. modelSetup.setupStackServiceComponent();
  120. controller.set('content.serviceConfigProperties', [
  121. {
  122. serviceName: 'HDFS',
  123. name: 'principal1',
  124. value: '_HOST'
  125. },
  126. {
  127. serviceName: 'HDFS',
  128. name: 'keytab1',
  129. value: 'value1'
  130. }
  131. ]);
  132. });
  133. afterEach(function() {
  134. modelSetup.cleanStackServiceComponent();
  135. });
  136. it('componentToConfigMap is empty', function() {
  137. controller.reopen({
  138. componentToConfigMap: []
  139. });
  140. var result = [];
  141. controller.setComponentsConfig(result, Em.Object.create({hostName: 'c6401',hostComponents: []}), 'hadoopGroupId');
  142. expect(result).to.be.empty;
  143. });
  144. it('isHadoop2Stack = false, when component from stack2', function() {
  145. sinon.stub(App, 'get', function () {
  146. return false;
  147. });
  148. controller.reopen({
  149. componentToConfigMap: [{
  150. componentName: 'DATANODE',
  151. principal: 'principal1',
  152. keytab: 'keytab1',
  153. displayName: 'displayName1',
  154. isHadoop2Stack: true
  155. }]
  156. });
  157. var host = Em.Object.create({
  158. hostComponents: [{componentName: 'DATANODE'}],
  159. hostName: 'host1'
  160. });
  161. var result = [];
  162. controller.setComponentsConfig(result, host, 'hadoopGroupId');
  163. expect(result).to.be.empty;
  164. App.get.restore();
  165. });
  166. it('isHadoop2Stack = true, when component from stack2', function() {
  167. sinon.stub(App, 'get', function () {
  168. return true;
  169. });
  170. controller.reopen({
  171. componentToConfigMap: [{
  172. componentName: 'DATANODE',
  173. principal: 'principal1',
  174. keytab: 'keytab1',
  175. displayName: 'displayName1',
  176. isHadoop2Stack: true
  177. }]
  178. });
  179. var host = Em.Object.create({
  180. hostComponents: [{componentName: 'DATANODE'}],
  181. hostName: 'host1'
  182. });
  183. var result = [];
  184. controller.setComponentsConfig(result, host, 'hadoopGroupId');
  185. expect(result.length).to.equal(1);
  186. App.get.restore();
  187. });
  188. it('Component does not match host-component', function() {
  189. controller.reopen({
  190. componentToConfigMap: [{
  191. componentName: 'DATANODE',
  192. principal: 'principal1',
  193. keytab: 'keytab1',
  194. displayName: 'displayName1'
  195. }]
  196. });
  197. var host = Em.Object.create({
  198. hostComponents: [{componentName: 'DATANODE1'}],
  199. hostName: 'host1'
  200. });
  201. var result = [];
  202. controller.setComponentsConfig(result, host, 'hadoopGroupId');
  203. expect(result).to.be.empty;
  204. });
  205. it('Component matches host-component', function() {
  206. controller.reopen({
  207. componentToConfigMap: [{
  208. componentName: 'DATANODE',
  209. principal: 'principal1',
  210. keytab: 'keytab1',
  211. displayName: 'displayName1'
  212. }]
  213. });
  214. var host = Em.Object.create({
  215. hostComponents: [{componentName: 'DATANODE'}],
  216. hostName: 'host1'
  217. });
  218. var result = [];
  219. controller.setComponentsConfig(result, host, 'hadoopGroupId');
  220. expect(result.length).to.equal(1);
  221. });
  222. });
  223. describe('#setMandatoryConfigs()', function() {
  224. beforeEach(function () {
  225. sinon.stub(App.Service, 'find', function () {
  226. return [
  227. {serviceName: 'SERVICE1'}
  228. ];
  229. });
  230. controller.set('content.serviceConfigProperties', [
  231. {
  232. serviceName: 'GENERAL',
  233. name: 'kerberos_domain',
  234. value: 'realm1'
  235. }
  236. ]);
  237. });
  238. afterEach(function () {
  239. App.Service.find.restore();
  240. });
  241. it('mandatoryConfigs is empty', function() {
  242. var result = [];
  243. controller.set('mandatoryConfigs', []);
  244. controller.setMandatoryConfigs(result, [], '', '');
  245. expect(result).to.be.empty;
  246. });
  247. it('config has unknown service to check', function() {
  248. var result = [];
  249. controller.set('mandatoryConfigs', [{
  250. userConfig: 'kerberos_domain',
  251. keytab: 'kerberos_domain',
  252. displayName: '',
  253. checkService: 'HBASE'
  254. }]);
  255. controller.setMandatoryConfigs(result, [], '', '');
  256. expect(result).to.be.empty;
  257. });
  258. it('config should be added', function() {
  259. var result = [];
  260. controller.set('mandatoryConfigs', [{
  261. userConfig: 'userConfig1',
  262. keytab: 'kerberos_domain',
  263. displayName: ''
  264. }]);
  265. var securityUsers = [{
  266. name: 'userConfig1',
  267. value: 'value1'
  268. }];
  269. controller.setMandatoryConfigs(result, securityUsers, '', '');
  270. expect(result.length).to.equal(1);
  271. });
  272. });
  273. describe('#setHostComponentsSecureValue()', function() {
  274. beforeEach(function () {
  275. sinon.stub(controller, 'buildComponentToOwnerMap', Em.K);
  276. sinon.stub(controller, 'changeDisplayName', Em.K);
  277. sinon.stub(controller, 'getSecureProperties', function(){
  278. return {principal: '', keytab: ''};
  279. });
  280. });
  281. afterEach(function () {
  282. controller.buildComponentToOwnerMap.restore();
  283. controller.changeDisplayName.restore();
  284. controller.getSecureProperties.restore();
  285. });
  286. it('host.hostComponents is empty', function() {
  287. var result = [];
  288. var host = Em.Object.create({
  289. hostComponents: []
  290. });
  291. controller.setHostComponentsSecureValue(result, host);
  292. expect(result).to.be.empty;
  293. });
  294. it('host-component does not match component to display', function() {
  295. var result = [];
  296. var host = Em.Object.create({
  297. hostComponents: [Em.Object.create({
  298. componentName: 'UNKNOWN'
  299. })]
  300. });
  301. controller.setHostComponentsSecureValue(result, host);
  302. expect(result).to.be.empty;
  303. });
  304. it('host-component matches component to display', function() {
  305. var result = [];
  306. var host = Em.Object.create({
  307. hostComponents: [Em.Object.create({
  308. componentName: 'DATANODE'
  309. })]
  310. });
  311. controller.setHostComponentsSecureValue(result, host, {}, [], '');
  312. expect(result.length).to.equal(1);
  313. });
  314. it('addedPrincipalsHost already contain such config', function() {
  315. var result = [];
  316. var host = Em.Object.create({
  317. hostName: 'host1',
  318. hostComponents: [Em.Object.create({
  319. componentName: 'DATANODE'
  320. })]
  321. });
  322. controller.setHostComponentsSecureValue(result, host, {'host1--': true}, [], '');
  323. expect(result.length).to.be.empty;
  324. });
  325. });
  326. describe('#setHostComponentsSecureValue()', function () {
  327. it('DRPC Server principal should point to Nimbus host for HDP-2.2 stack', function () {
  328. sinon.stub(App, 'get').withArgs('isHadoop22Stack').returns(true);
  329. sinon.stub(controller, 'get').withArgs('content.serviceConfigProperties').returns([]);
  330. sinon.stub(controller, 'getNimbusHostName').returns('nimbus_host');
  331. sinon.stub(controller, 'buildComponentToOwnerMap').returns({'DRPC_SERVER': 'storm'});
  332. sinon.stub(controller, 'getSecureProperties').returns({
  333. "keytab": "/etc/security/keytabs/nimbus.service.keytab",
  334. "principal": "nimbus/nimbus_host"
  335. });
  336. sinon.stub(controller, 'getSecurityUsers', function () {
  337. return [
  338. {
  339. name: 'storm_user',
  340. value: 'storm'
  341. }
  342. ];
  343. });
  344. var host = Em.Object.create({
  345. hostComponents: [Em.Object.create({
  346. componentName: 'DRPC_SERVER',
  347. displayName: 'DRPC Server'
  348. })]
  349. });
  350. var result = [];
  351. controller.setHostComponentsSecureValue(result, host, {}, [], 'hadoopId');
  352. expect(result).to.be.not.empty;
  353. expect(controller.getSecureProperties.args[0][2]).to.equal('nimbus_host');
  354. var hostComponent = result[0];
  355. expect(hostComponent.principal).to.equal('nimbus/nimbus_host');
  356. expect(hostComponent.owner).to.equal('storm');
  357. App.get.restore();
  358. controller.get.restore();
  359. controller.getNimbusHostName.restore();
  360. controller.buildComponentToOwnerMap.restore();
  361. controller.getSecureProperties.restore();
  362. controller.getSecurityUsers.restore();
  363. });
  364. });
  365. describe('#getSecureProperties()', function () {
  366. beforeEach(function () {
  367. sinon.stub(controller, 'getPrincipal', function () {
  368. return 'principal';
  369. });
  370. });
  371. afterEach(function () {
  372. controller.getPrincipal.restore();
  373. });
  374. var testCases = [
  375. {
  376. title: 'serviceConfigs is empty',
  377. content: {
  378. serviceConfigs: [],
  379. componentName: ''
  380. },
  381. result: {}
  382. },
  383. {
  384. title: 'Config has component that does not match component name',
  385. content: {
  386. serviceConfigs: [{
  387. component: 'comp1'
  388. }],
  389. componentName: 'comp2'
  390. },
  391. result: {}
  392. },
  393. {
  394. title: 'Config has components that does not match component name',
  395. content: {
  396. serviceConfigs: [{
  397. components: ['comp1']
  398. }],
  399. componentName: 'comp2'
  400. },
  401. result: {}
  402. },
  403. {
  404. title: 'Config has component that matches component name',
  405. content: {
  406. serviceConfigs: [{
  407. name: 'C_principal_name',
  408. component: 'comp1',
  409. value: 'value1'
  410. }],
  411. componentName: 'comp1'
  412. },
  413. result: {
  414. principal: 'principal'
  415. }
  416. },
  417. {
  418. title: 'Config has components that matches component name',
  419. content: {
  420. serviceConfigs: [{
  421. name: 'C_principal_name',
  422. components: ['comp1'],
  423. value: 'value1'
  424. }],
  425. componentName: 'comp1'
  426. },
  427. result: {
  428. principal: 'principal'
  429. }
  430. },
  431. {
  432. title: 'Config name without correct postfix',
  433. content: {
  434. serviceConfigs: [{
  435. name: 'config1',
  436. component: 'comp1',
  437. value: 'value1'
  438. }],
  439. componentName: 'comp1'
  440. },
  441. result: {}
  442. },
  443. {
  444. title: 'Config name with "_keytab" postfix',
  445. content: {
  446. serviceConfigs: [{
  447. name: 'c_keytab',
  448. component: 'comp1',
  449. value: 'value1'
  450. }],
  451. componentName: 'comp1'
  452. },
  453. result: {
  454. keytab: 'value1'
  455. }
  456. },
  457. {
  458. title: 'Config name with "_keytab_path" postfix',
  459. content: {
  460. serviceConfigs: [{
  461. name: 'c_keytab_path',
  462. component: 'comp1',
  463. value: 'value1'
  464. }],
  465. componentName: 'comp1'
  466. },
  467. result: {
  468. keytab: 'value1'
  469. }
  470. }
  471. ];
  472. testCases.forEach(function (test) {
  473. it(test.title, function () {
  474. expect(controller.getSecureProperties(test.content.serviceConfigs, test.content.componentName, '')).to.eql(test.result);
  475. });
  476. });
  477. });
  478. describe('#getPrincipal()', function () {
  479. var testCases = [
  480. {
  481. title: 'Config value missing "_HOST" string, unit is empty',
  482. content: {
  483. config: {
  484. value: 'value1',
  485. unit: ''
  486. },
  487. hostName: ''
  488. },
  489. result: 'value1'
  490. },
  491. {
  492. title: 'Config value missing "_HOST" string, unit is correct',
  493. content: {
  494. config: {
  495. value: 'value1',
  496. unit: 'unit1'
  497. },
  498. hostName: ''
  499. },
  500. result: 'value1unit1'
  501. },
  502. {
  503. title: 'Config value contains "_HOST" string, host name in lowercase',
  504. content: {
  505. config: {
  506. value: '_HOST',
  507. unit: 'unit1'
  508. },
  509. hostName: 'host1'
  510. },
  511. result: 'host1unit1'
  512. },
  513. {
  514. title: 'Config value contains "_HOST" string, host name in uppercase',
  515. content: {
  516. config: {
  517. value: '_HOST',
  518. unit: 'unit1'
  519. },
  520. hostName: 'HOST1'
  521. },
  522. result: 'host1unit1'
  523. }
  524. ];
  525. testCases.forEach(function (test) {
  526. it(test.title, function () {
  527. expect(controller.getPrincipal(test.content.config, test.content.hostName)).to.equal(test.result);
  528. });
  529. });
  530. });
  531. describe('#changeDisplayName()', function() {
  532. it('name is HiveServer2', function() {
  533. expect(controller.changeDisplayName('HiveServer2')).to.equal('Hive Metastore and HiveServer2');
  534. });
  535. it('name is not HiveServer2', function() {
  536. expect(controller.changeDisplayName('something')).to.equal('something');
  537. });
  538. });
  539. });