step4_test.js 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  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/security_progress_controller');
  20. require('controllers/main/admin/security/add/step4');
  21. require('utils/polling');
  22. require('models/cluster_states');
  23. require('models/service');
  24. describe('App.MainAdminSecurityAddStep4Controller', function () {
  25. var controller = App.MainAdminSecurityAddStep4Controller.create({
  26. content: {},
  27. enableSubmit: function () {
  28. this._super()
  29. },
  30. secureMapping: [],
  31. secureProperties: []
  32. });
  33. describe('#secureServices', function() {
  34. it('content.services is correct', function() {
  35. controller.set('content.services', [{}]);
  36. expect(controller.get('secureServices')).to.eql([{}]);
  37. controller.reopen({
  38. secureServices: []
  39. })
  40. });
  41. });
  42. describe('#isBackBtnDisabled', function() {
  43. it('commands have error', function() {
  44. controller.set('commands', [Em.Object.create({
  45. isError: true
  46. })]);
  47. expect(controller.get('isBackBtnDisabled')).to.be.false;
  48. });
  49. it('commands do not have error', function() {
  50. controller.set('commands', [Em.Object.create({
  51. isError: false
  52. })]);
  53. expect(controller.get('isBackBtnDisabled')).to.be.true;
  54. });
  55. });
  56. describe('#isSecurityApplied', function() {
  57. var testCases = [
  58. {
  59. title: 'No START_SERVICES command',
  60. commands: [],
  61. result: false
  62. },
  63. {
  64. title: 'START_SERVICES is not success',
  65. commands: [Em.Object.create({
  66. name: 'START_SERVICES',
  67. isSuccess: false
  68. })],
  69. result: false
  70. },
  71. {
  72. title: 'START_SERVICES is success',
  73. commands: [Em.Object.create({
  74. name: 'START_SERVICES',
  75. isSuccess: true
  76. })],
  77. result: true
  78. }
  79. ];
  80. testCases.forEach(function(test){
  81. it(test.title, function() {
  82. controller.set('commands', test.commands);
  83. expect(controller.get('isSecurityApplied')).to.equal(test.result);
  84. });
  85. });
  86. });
  87. describe('#enableSubmit()', function() {
  88. var mock = {
  89. setStepsEnable: Em.K,
  90. setLowerStepsDisable: Em.K
  91. };
  92. beforeEach(function () {
  93. sinon.stub(App.router, 'get', function () {
  94. return mock;
  95. });
  96. sinon.spy(mock, 'setStepsEnable');
  97. sinon.spy(mock, 'setLowerStepsDisable');
  98. });
  99. afterEach(function () {
  100. App.router.get.restore();
  101. mock.setStepsEnable.restore();
  102. mock.setLowerStepsDisable.restore();
  103. });
  104. it('Command has error', function() {
  105. controller.set('commands', [Em.Object.create({
  106. isError: true
  107. })]);
  108. controller.enableSubmit();
  109. expect(controller.get('isSubmitDisabled')).to.be.false;
  110. expect(mock.setStepsEnable.calledOnce).to.be.true;
  111. });
  112. it('Command is successful', function() {
  113. controller.set('commands', [Em.Object.create({
  114. isSuccess: true
  115. })]);
  116. controller.enableSubmit();
  117. expect(controller.get('isSubmitDisabled')).to.be.false;
  118. });
  119. it('Command is in progress', function() {
  120. controller.set('commands', [Em.Object.create()]);
  121. controller.enableSubmit();
  122. expect(controller.get('isSubmitDisabled')).to.be.true;
  123. expect(mock.setLowerStepsDisable.calledWith(4)).to.be.true;
  124. });
  125. });
  126. describe('#clearStep()', function() {
  127. it('Clear step info', function() {
  128. controller.set('commands', [Em.Object.create()]);
  129. controller.set('isSubmitDisabled', false);
  130. controller.set('serviceConfigTags', [{}]);
  131. controller.clearStep();
  132. expect(controller.get('isSubmitDisabled')).to.be.true;
  133. expect(controller.get('commands')).to.be.empty;
  134. expect(controller.get('serviceConfigTags')).to.be.empty;
  135. });
  136. });
  137. describe('#loadCommands()', function() {
  138. beforeEach(function () {
  139. controller.get('commands').clear();
  140. });
  141. it('No YARN in secureServices', function() {
  142. controller.set('secureServices', []);
  143. controller.loadCommands();
  144. expect(controller.get('commands.length')).to.equal(3);
  145. expect(controller.get('commands').someProperty('name', 'DELETE_ATS')).to.be.false;
  146. });
  147. it('YARN does not have APP_TIMELINE_SERVER', function() {
  148. sinon.stub(App.Service, 'find', function () {
  149. return Em.Object.create({
  150. hostComponents: []
  151. })
  152. });
  153. controller.set('secureServices', [{
  154. serviceName: 'YARN'
  155. }]);
  156. controller.loadCommands();
  157. expect(controller.get('commands.length')).to.equal(3);
  158. expect(controller.get('commands').someProperty('name', 'DELETE_ATS')).to.be.false;
  159. App.Service.find.restore();
  160. });
  161. it('YARN has APP_TIMELINE_SERVER', function() {
  162. sinon.stub(App.Service, 'find', function () {
  163. return Em.Object.create({
  164. hostComponents: [Em.Object.create({
  165. componentName: 'APP_TIMELINE_SERVER'
  166. })]
  167. })
  168. });
  169. controller.set('secureServices', [{
  170. serviceName: 'YARN'
  171. }]);
  172. controller.loadCommands();
  173. expect(controller.get('commands.length')).to.equal(4);
  174. expect(controller.get('commands').someProperty('name', 'DELETE_ATS')).to.be.true;
  175. App.Service.find.restore();
  176. });
  177. });
  178. describe('#loadStep()', function() {
  179. beforeEach(function () {
  180. sinon.stub(controller, 'clearStep', Em.K);
  181. sinon.stub(controller, 'prepareSecureConfigs', Em.K);
  182. });
  183. afterEach(function () {
  184. controller.clearStep.restore();
  185. controller.prepareSecureConfigs.restore();
  186. controller.resumeSavedCommands.restore();
  187. });
  188. it('Resume saved commands', function() {
  189. sinon.stub(controller, 'resumeSavedCommands', function(){
  190. return true;
  191. });
  192. controller.loadStep();
  193. expect(controller.clearStep.calledOnce).to.be.true;
  194. expect(controller.prepareSecureConfigs.calledOnce).to.be.true;
  195. expect(controller.resumeSavedCommands.calledOnce).to.be.true;
  196. });
  197. it('No saved commands', function() {
  198. sinon.stub(controller, 'resumeSavedCommands', function(){
  199. return false;
  200. });
  201. sinon.stub(controller, 'loadCommands', Em.K);
  202. sinon.stub(controller, 'addInfoToCommands', Em.K);
  203. sinon.stub(controller, 'syncStopServicesOperation', Em.K);
  204. sinon.stub(controller, 'addObserverToCommands', Em.K);
  205. sinon.stub(controller, 'moveToNextCommand', Em.K);
  206. controller.loadStep();
  207. expect(controller.clearStep.calledOnce).to.be.true;
  208. expect(controller.prepareSecureConfigs.calledOnce).to.be.true;
  209. expect(controller.resumeSavedCommands.calledOnce).to.be.true;
  210. controller.loadCommands.restore();
  211. controller.addInfoToCommands.restore();
  212. controller.syncStopServicesOperation.restore();
  213. controller.addObserverToCommands.restore();
  214. controller.moveToNextCommand.restore();
  215. });
  216. });
  217. describe('#syncStopServicesOperation()', function() {
  218. afterEach(function () {
  219. App.router.get.restore();
  220. });
  221. it('No running operations', function() {
  222. sinon.stub(App.router, 'get', function(){
  223. return [];
  224. });
  225. expect(controller.syncStopServicesOperation()).to.be.false;
  226. });
  227. it('Running operation is not Stop All Services', function() {
  228. sinon.stub(App.router, 'get', function(){
  229. return [Em.Object.create({isRunning: true})];
  230. });
  231. expect(controller.syncStopServicesOperation()).to.be.false;
  232. });
  233. it('No STOP_SERVICES in commands', function() {
  234. sinon.stub(App.router, 'get', function(){
  235. return [Em.Object.create({
  236. isRunning: true,
  237. name: 'Stop All Services'
  238. })];
  239. });
  240. controller.set('commands', []);
  241. expect(controller.syncStopServicesOperation()).to.be.false;
  242. });
  243. it('Sync stop services commands', function() {
  244. sinon.stub(App.router, 'get', function(){
  245. return [Em.Object.create({
  246. isRunning: true,
  247. name: 'Stop All Services',
  248. id: 1
  249. })];
  250. });
  251. controller.set('commands', [Em.Object.create({
  252. name: 'STOP_SERVICES'
  253. })]);
  254. expect(controller.syncStopServicesOperation()).to.be.true;
  255. expect(controller.get('commands').findProperty('name', 'STOP_SERVICES').get('requestId')).to.equal(1);
  256. });
  257. });
  258. describe('#resumeSavedCommands()', function() {
  259. beforeEach(function(){
  260. sinon.stub(controller, 'addObserverToCommands', Em.K);
  261. sinon.stub(controller, 'moveToNextCommand', Em.K);
  262. controller.set('commands', []);
  263. });
  264. afterEach(function(){
  265. controller.moveToNextCommand.restore();
  266. controller.addObserverToCommands.restore();
  267. App.db.getSecurityDeployCommands.restore();
  268. });
  269. it('Commands is null', function() {
  270. sinon.stub(App.db, 'getSecurityDeployCommands', function(){
  271. return null;
  272. });
  273. expect(controller.resumeSavedCommands()).to.be.false;
  274. });
  275. it('Commands is empty', function() {
  276. sinon.stub(App.db, 'getSecurityDeployCommands', function(){
  277. return [];
  278. });
  279. expect(controller.resumeSavedCommands()).to.be.false;
  280. });
  281. it('Command has error', function() {
  282. sinon.stub(App.db, 'getSecurityDeployCommands', function(){
  283. return [{
  284. isError: true,
  285. name: 'command1'
  286. }];
  287. });
  288. expect(controller.resumeSavedCommands()).to.be.true;
  289. expect(controller.get('commands').mapProperty('name')).to.eql(['command1']);
  290. expect(controller.addObserverToCommands.calledOnce).to.be.true;
  291. });
  292. it('Command in progress', function() {
  293. sinon.stub(App.db, 'getSecurityDeployCommands', function(){
  294. return [{
  295. isStarted: true,
  296. isCompleted: false,
  297. name: 'command1'
  298. }];
  299. });
  300. expect(controller.resumeSavedCommands()).to.be.true;
  301. expect(controller.get('commands').mapProperty('name')).to.eql(['command1']);
  302. expect(controller.get('commands').findProperty('name', 'command1').get('isStarted')).to.be.false;
  303. expect(controller.addObserverToCommands.calledOnce).to.be.true;
  304. expect(controller.moveToNextCommand.calledOnce).to.be.true;
  305. });
  306. it('Command completed', function() {
  307. sinon.stub(App.db, 'getSecurityDeployCommands', function(){
  308. return [{
  309. isCompleted: true,
  310. name: 'command1'
  311. }];
  312. });
  313. expect(controller.resumeSavedCommands()).to.be.true;
  314. expect(controller.get('commands').mapProperty('name')).to.eql(['command1']);
  315. expect(controller.addObserverToCommands.calledOnce).to.be.true;
  316. expect(controller.moveToNextCommand.calledOnce).to.be.true;
  317. });
  318. });
  319. describe('#loadUiSideConfigs()', function() {
  320. beforeEach(function(){
  321. sinon.stub(controller, 'getGlobConfigValue', function(arg1, arg2){
  322. return arg2;
  323. });
  324. sinon.stub(controller, 'checkServiceForConfigValue', function() {
  325. return 'value2';
  326. });
  327. sinon.stub(controller, 'setConfigValue', Em.K);
  328. sinon.stub(controller, 'formatConfigName', Em.K);
  329. });
  330. afterEach(function(){
  331. controller.getGlobConfigValue.restore();
  332. controller.checkServiceForConfigValue.restore();
  333. controller.setConfigValue.restore();
  334. controller.formatConfigName.restore();
  335. });
  336. it('secureMapping is empty', function() {
  337. controller.set('secureMapping', []);
  338. expect(controller.loadUiSideConfigs()).to.be.empty;
  339. });
  340. it('Config does not have dependedServiceName', function() {
  341. controller.set('secureMapping', [{
  342. name: 'config1',
  343. value: 'value1',
  344. filename: 'file1',
  345. foreignKey: null
  346. }]);
  347. expect(controller.loadUiSideConfigs()).to.eql([{
  348. "id": "site property",
  349. "name": 'config1',
  350. "value": 'value1',
  351. "filename": 'file1'
  352. }]);
  353. });
  354. it('Config has dependedServiceName', function() {
  355. controller.set('secureMapping', [{
  356. name: 'config1',
  357. value: 'value1',
  358. filename: 'file1',
  359. foreignKey: null,
  360. dependedServiceName: 'service'
  361. }]);
  362. expect(controller.loadUiSideConfigs()).to.eql([{
  363. "id": "site property",
  364. "name": 'config1',
  365. "value": 'value2',
  366. "filename": 'file1'
  367. }]);
  368. });
  369. it('Config has non-existent serviceName', function() {
  370. controller.set('secureMapping', [{
  371. name: 'config1',
  372. value: 'value1',
  373. filename: 'file1',
  374. foreignKey: true,
  375. serviceName: 'service'
  376. }]);
  377. sinon.stub(App.Service, 'find', function(){
  378. return [];
  379. });
  380. expect(controller.loadUiSideConfigs()).to.be.empty;
  381. App.Service.find.restore();
  382. });
  383. it('Config has correct serviceName', function() {
  384. controller.set('secureMapping', [{
  385. name: 'config1',
  386. value: 'value1',
  387. filename: 'file1',
  388. foreignKey: true,
  389. serviceName: 'HDFS'
  390. }]);
  391. sinon.stub(App.Service, 'find', function(){
  392. return [{serviceName: 'HDFS'}];
  393. });
  394. expect(controller.loadUiSideConfigs()).to.eql([{
  395. "id": "site property",
  396. "name": 'config1',
  397. "value": 'value1',
  398. "filename": 'file1'
  399. }]);
  400. expect(controller.setConfigValue.calledOnce).to.be.true;
  401. expect(controller.formatConfigName.calledOnce).to.be.true;
  402. App.Service.find.restore();
  403. });
  404. });
  405. describe('#checkServiceForConfigValue()', function() {
  406. it('services is empty', function() {
  407. var services = [];
  408. expect(controller.checkServiceForConfigValue('value1', services)).to.equal('value1');
  409. });
  410. it('Service is loaded', function() {
  411. var services = [{}];
  412. sinon.stub(App.Service, 'find', function () {
  413. return Em.Object.create({isLoaded: false});
  414. });
  415. expect(controller.checkServiceForConfigValue('value1', services)).to.equal('value1');
  416. App.Service.find.restore();
  417. });
  418. it('Service is not loaded', function() {
  419. var services = [{
  420. replace: 'val'
  421. }];
  422. sinon.stub(App.Service, 'find', function () {
  423. return Em.Object.create({isLoaded: false});
  424. });
  425. expect(controller.checkServiceForConfigValue('value1', services)).to.equal('ue1');
  426. App.Service.find.restore();
  427. });
  428. });
  429. describe('#getGlobConfigValue()', function() {
  430. var testCases = [
  431. {
  432. title: 'Incorrect expression',
  433. arguments: {
  434. templateName: [],
  435. expression: 'expression'
  436. },
  437. result: 'expression'
  438. },
  439. {
  440. title: 'No such property in global configs',
  441. arguments: {
  442. templateName: ['config2'],
  443. expression: '<[0]>'
  444. },
  445. result: null
  446. },
  447. {
  448. title: 'Property in global configs',
  449. arguments: {
  450. templateName: ['config1'],
  451. expression: '<[0]>'
  452. },
  453. result: 'value1'
  454. },
  455. {
  456. title: 'First property not in global configs',
  457. arguments: {
  458. templateName: ['config2','config1'],
  459. expression: '<[0]>@<[1]>'
  460. },
  461. result: null
  462. }
  463. ];
  464. testCases.forEach(function(test){
  465. it(test.title, function() {
  466. controller.set('globalProperties', [{
  467. name: 'config1',
  468. value: 'value1'
  469. }]);
  470. expect(controller.getGlobConfigValue(test.arguments.templateName, test.arguments.expression)).to.equal(test.result);
  471. });
  472. });
  473. });
  474. describe('#formatConfigName()', function() {
  475. it('config.value is null', function() {
  476. var config = {
  477. value: null
  478. };
  479. expect(controller.formatConfigName([], config)).to.be.false;
  480. });
  481. it('config.name does not contain foreignKey', function() {
  482. var config = {
  483. value: 'value1',
  484. name: 'config1'
  485. };
  486. expect(controller.formatConfigName([], config)).to.be.false;
  487. });
  488. it('globalProperties is empty, use uiConfig', function() {
  489. var config = {
  490. value: 'value1',
  491. name: '<foreignKey[0]>',
  492. foreignKey: ['key1']
  493. };
  494. controller.set('globalProperties', []);
  495. var uiConfig = [{
  496. name: 'key1',
  497. value: 'globalValue1'
  498. }];
  499. expect(controller.formatConfigName(uiConfig, config)).to.be.true;
  500. expect(config._name).to.equal('globalValue1');
  501. });
  502. it('uiConfig is empty, use globalProperties', function() {
  503. var config = {
  504. value: 'value1',
  505. name: '<foreignKey[0]>',
  506. foreignKey: ['key1']
  507. };
  508. controller.set('globalProperties', [{
  509. name: 'key1',
  510. value: 'globalValue1'
  511. }]);
  512. var uiConfig = [];
  513. expect(controller.formatConfigName(uiConfig, config)).to.be.true;
  514. expect(config._name).to.equal('globalValue1');
  515. });
  516. });
  517. describe('#setConfigValue()', function() {
  518. it('config.value is null', function() {
  519. var config = {
  520. value: null
  521. };
  522. expect(controller.setConfigValue(config)).to.be.false;
  523. });
  524. it('config.value does not match "templateName"', function() {
  525. var config = {
  526. value: ''
  527. };
  528. expect(controller.setConfigValue(config)).to.be.false;
  529. });
  530. it('No such property in global configs', function() {
  531. var config = {
  532. value: '<templateName[0]>',
  533. templateName: ['config1']
  534. };
  535. controller.set('globalProperties', []);
  536. expect(controller.setConfigValue(config)).to.be.true;
  537. expect(config.value).to.be.null;
  538. });
  539. it('Property in global configs', function() {
  540. var config = {
  541. value: '<templateName[0]>',
  542. templateName: ['config1']
  543. };
  544. controller.set('globalProperties', [{
  545. name: 'config1',
  546. value: 'value1'
  547. }]);
  548. expect(controller.setConfigValue(config)).to.be.true;
  549. expect(config.value).to.equal('value1');
  550. });
  551. });
  552. describe('#prepareSecureConfigs()', function() {
  553. beforeEach(function(){
  554. sinon.stub(controller, 'loadGlobals', Em.K);
  555. sinon.stub(controller, 'loadUiSideConfigs', function(){
  556. return [{name: 'config1'}];
  557. });
  558. });
  559. afterEach(function(){
  560. controller.loadGlobals.restore();
  561. controller.loadUiSideConfigs.restore();
  562. });
  563. it('content.serviceConfigProperties is empty', function() {
  564. controller.set('content.serviceConfigProperties', []);
  565. controller.prepareSecureConfigs();
  566. expect(controller.loadGlobals.calledOnce).to.be.true;
  567. expect(controller.loadUiSideConfigs.calledOnce).to.be.true;
  568. expect(controller.get('configs')).to.eql([{name: 'config1'}]);
  569. });
  570. it('content.serviceConfigProperties is empty', function() {
  571. controller.set('content.serviceConfigProperties', [{
  572. id: 'site property',
  573. name: 'config2'
  574. }]);
  575. controller.prepareSecureConfigs();
  576. expect(controller.loadGlobals.calledOnce).to.be.true;
  577. expect(controller.loadUiSideConfigs.calledOnce).to.be.true;
  578. expect(controller.get('configs')).to.eql([
  579. {
  580. id: 'site property',
  581. name: 'config2'
  582. },
  583. {name: 'config1'}
  584. ]);
  585. });
  586. });
  587. describe('#loadGlobals()', function() {
  588. beforeEach(function(){
  589. sinon.stub(controller, 'loadStaticGlobal', Em.K);
  590. sinon.stub(controller, 'loadUsersToGlobal', Em.K);
  591. sinon.stub(controller, 'loadHostNamesToGlobal', Em.K);
  592. sinon.stub(controller, 'loadPrimaryNamesToGlobals', Em.K);
  593. });
  594. afterEach(function(){
  595. controller.loadStaticGlobal.restore();
  596. controller.loadUsersToGlobal.restore();
  597. controller.loadHostNamesToGlobal.restore();
  598. controller.loadPrimaryNamesToGlobals.restore();
  599. });
  600. it('content.serviceConfigProperties is empty', function() {
  601. controller.set('content.serviceConfigProperties', []);
  602. controller.loadGlobals();
  603. expect(controller.loadStaticGlobal.calledOnce).to.be.true;
  604. expect(controller.loadUsersToGlobal.calledOnce).to.be.true;
  605. expect(controller.loadHostNamesToGlobal.calledOnce).to.be.true;
  606. expect(controller.loadPrimaryNamesToGlobals.calledOnce).to.be.true;
  607. expect(controller.get('globalProperties')).to.be.empty;
  608. });
  609. it('content.serviceConfigProperties is correct', function() {
  610. controller.set('content.serviceConfigProperties', [{
  611. id: 'puppet var',
  612. name: 'config1'
  613. }]);
  614. controller.loadGlobals();
  615. expect(controller.loadStaticGlobal.calledOnce).to.be.true;
  616. expect(controller.loadUsersToGlobal.calledOnce).to.be.true;
  617. expect(controller.loadHostNamesToGlobal.calledOnce).to.be.true;
  618. expect(controller.loadPrimaryNamesToGlobals.calledOnce).to.be.true;
  619. expect(controller.get('globalProperties')).to.eql([{
  620. id: 'puppet var',
  621. name: 'config1'
  622. }]);
  623. });
  624. });
  625. describe('#loadUsersToGlobal()', function() {
  626. beforeEach(function(){
  627. sinon.stub(controller, 'loadUsersFromServer', Em.K);
  628. });
  629. afterEach(function(){
  630. controller.loadUsersFromServer.restore();
  631. App.router.get.restore();
  632. });
  633. it('serviceUsers is empty', function() {
  634. sinon.stub(App.router, 'get', function(){
  635. return [];
  636. });
  637. controller.set('serviceUsers', []);
  638. controller.set('globalProperties', []);
  639. controller.loadUsersToGlobal();
  640. expect(controller.loadUsersFromServer.calledOnce).to.be.true;
  641. expect(controller.get('globalProperties')).to.be.empty;
  642. });
  643. it('serviceUsers is correct', function() {
  644. sinon.stub(App.router, 'get', function(){
  645. return [{name: 'user1'}];
  646. });
  647. controller.set('serviceUsers', [{}]);
  648. controller.set('globalProperties', []);
  649. controller.loadUsersToGlobal();
  650. expect(controller.loadUsersFromServer.called).to.be.false;
  651. expect(controller.get('globalProperties').mapProperty('name')).to.eql(['user1']);
  652. });
  653. });
  654. describe('#addHostConfig()', function() {
  655. afterEach(function () {
  656. App.Service.find.restore();
  657. });
  658. it('No such service loaded', function() {
  659. sinon.stub(App.Service, 'find', function(){
  660. return Em.Object.create({isLoaded: false});
  661. });
  662. expect(controller.addHostConfig('service1', 'comp1', 'config1')).to.be.false;
  663. });
  664. it('No such service in secureServices', function() {
  665. sinon.stub(App.Service, 'find', function(){
  666. return Em.Object.create({isLoaded: true});
  667. });
  668. controller.set('secureServices', []);
  669. expect(controller.addHostConfig('service1', 'comp1', 'config1')).to.be.false;
  670. });
  671. it('Service does not have such host-component', function() {
  672. sinon.stub(App.Service, 'find', function(){
  673. return Em.Object.create({
  674. isLoaded: true,
  675. hostComponents: []
  676. });
  677. });
  678. controller.set('secureServices', [{
  679. serviceName: 'service1'
  680. }]);
  681. expect(controller.addHostConfig('service1', 'comp1', 'config1')).to.be.false;
  682. });
  683. it('Push config to globalProperties', function() {
  684. sinon.stub(App.Service, 'find', function(){
  685. return Em.Object.create({
  686. isLoaded: true,
  687. hostComponents: [Em.Object.create({
  688. componentName: 'comp1',
  689. host: {hostName: 'host1'}
  690. })]
  691. });
  692. });
  693. controller.set('secureServices', [{
  694. serviceName: 'service1'
  695. }]);
  696. controller.set('globalProperties', []);
  697. expect(controller.addHostConfig('service1', 'comp1', 'config1')).to.be.true;
  698. expect(controller.get('globalProperties')).to.eql([{
  699. id: 'puppet var',
  700. name: 'config1',
  701. value: 'host1'
  702. }]);
  703. });
  704. });
  705. describe('#loadHostNamesToGlobal()', function() {
  706. beforeEach(function () {
  707. sinon.stub(controller, 'addHostConfig', Em.K);
  708. });
  709. afterEach(function () {
  710. controller.addHostConfig.restore();
  711. });
  712. it('componentsConfig is empty', function() {
  713. controller.set('componentsConfig', []);
  714. controller.loadHostNamesToGlobal();
  715. expect(controller.addHostConfig.called).to.be.false;
  716. });
  717. it('componentsConfig is correct', function() {
  718. controller.set('componentsConfig', [{
  719. serviceName: 'service1',
  720. componentName: 'comp1',
  721. configName: 'config1'
  722. }]);
  723. controller.loadHostNamesToGlobal();
  724. expect(controller.addHostConfig.calledWith('service1', 'comp1', 'config1')).to.be.true;
  725. });
  726. });
  727. describe('#loadStaticGlobal()', function() {
  728. it('globalProperties contains "security_enabled" property', function() {
  729. controller.set('globalProperties', [{
  730. name: 'security_enabled'
  731. }]);
  732. controller.loadStaticGlobal();
  733. expect(controller.get('globalProperties').findProperty('name', 'security_enabled').value).to.equal('true');
  734. });
  735. });
  736. describe('#loadPrimaryNamesToGlobals()', function() {
  737. beforeEach(function(){
  738. controller.set('globalProperties', []);
  739. });
  740. afterEach(function () {
  741. controller.getPrincipalNames.restore();
  742. });
  743. it('No principal names', function() {
  744. sinon.stub(controller, 'getPrincipalNames', function(){
  745. return [];
  746. });
  747. controller.loadPrimaryNamesToGlobals();
  748. expect(controller.get('globalProperties')).to.be.empty;
  749. });
  750. it('Principal name does not contain "principal"', function() {
  751. sinon.stub(controller, 'getPrincipalNames', function(){
  752. return [{
  753. name: 'config1',
  754. value: 'value2/value1'
  755. }];
  756. });
  757. controller.loadPrimaryNamesToGlobals();
  758. expect(controller.get('globalProperties')).to.eql([{name: 'config1', value: 'value2'}]);
  759. });
  760. it('Principal name contains "principal"', function() {
  761. sinon.stub(controller, 'getPrincipalNames', function(){
  762. return [{
  763. name: 'principal1',
  764. value: 'value1'
  765. }];
  766. });
  767. controller.loadPrimaryNamesToGlobals();
  768. expect(controller.get('globalProperties')).to.eql([{name: 'primary1', value: 'value1'}]);
  769. });
  770. });
  771. describe('#getPrincipalNames()', function() {
  772. beforeEach(function () {
  773. controller.set('globalProperties', []);
  774. controller.set('secureProperties', []);
  775. });
  776. it('globalProperties and secureProperties are empty', function() {
  777. expect(controller.getPrincipalNames()).to.be.empty;
  778. });
  779. it('global property name does not match "principal_name"', function() {
  780. controller.set('globalProperties', [{
  781. name: 'config1'
  782. }]);
  783. expect(controller.getPrincipalNames()).to.be.empty;
  784. });
  785. it('secure property name does not match "principal_name"', function() {
  786. controller.set('secureProperties', [{
  787. name: 'config1'
  788. }]);
  789. expect(controller.getPrincipalNames()).to.be.empty;
  790. });
  791. it('global property name matches "principal_name"', function() {
  792. controller.set('globalProperties', [{
  793. name: 'principal_name'
  794. }]);
  795. expect(controller.getPrincipalNames()).to.eql([{
  796. name: 'principal_name'
  797. }]);
  798. });
  799. it('property with such name already exists', function() {
  800. controller.set('globalProperties', [{
  801. name: 'principal_name'
  802. }]);
  803. controller.set('secureProperties', [{
  804. name: 'principal_name'
  805. }]);
  806. expect(controller.getPrincipalNames().mapProperty('name')).to.eql(['principal_name']);
  807. });
  808. it('global and secure property name matches "principal_name"', function() {
  809. controller.set('globalProperties', [{
  810. name: 'global_principal_name'
  811. }]);
  812. controller.set('secureProperties', [{
  813. name: 'secure_principal_name',
  814. defaultValue: 'value1'
  815. }]);
  816. expect(controller.getPrincipalNames().mapProperty('name')).to.eql(['global_principal_name', 'secure_principal_name']);
  817. expect(controller.getPrincipalNames().findProperty('name', 'secure_principal_name').value).to.equal('value1');
  818. });
  819. });
  820. describe('#loadUsersFromServer()', function() {
  821. it('testMode = true', function() {
  822. controller.set('testModeUsers', [{
  823. name: 'user1',
  824. value: 'value1'
  825. }]);
  826. controller.set('serviceUsers', []);
  827. App.testMode = true;
  828. controller.loadUsersFromServer();
  829. expect(controller.get('serviceUsers')).to.eql([{
  830. name: 'user1',
  831. value: 'value1',
  832. id: 'puppet var'
  833. }]);
  834. });
  835. it('testMode = false', function() {
  836. sinon.stub(App.router, 'set', Em.K);
  837. sinon.stub(App.db, 'getSecureUserInfo', function(){
  838. return [];
  839. });
  840. App.testMode = false;
  841. controller.loadUsersFromServer();
  842. expect(App.db.getSecureUserInfo.calledOnce).to.be.true;
  843. expect(App.router.set.calledWith('mainAdminSecurityController.serviceUsers', [])).to.be.true;
  844. App.router.set.restore();
  845. App.db.getSecureUserInfo.restore();
  846. });
  847. });
  848. describe('#manageSecureConfigs()', function() {
  849. beforeEach(function () {
  850. sinon.stub(controller, 'setPrincipalValue', Em.K);
  851. });
  852. afterEach(function () {
  853. controller.setPrincipalValue.restore();
  854. });
  855. it('serviceConfigTags is null', function() {
  856. sinon.stub(controller, 'onJsError', Em.K);
  857. controller.set('serviceConfigTags', null);
  858. controller.set('configs', [{id: 'site property'}]);
  859. controller.set('commands', [Em.Object.create({
  860. name: 'APPLY_CONFIGURATIONS'
  861. })]);
  862. expect(controller.manageSecureConfigs()).to.be.false;
  863. expect(controller.onJsError.calledOnce).to.be.true;
  864. expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isSuccess')).to.be.false;
  865. expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isError')).to.be.true;
  866. controller.onJsError.restore();
  867. });
  868. it('Add configs from site-*.xml', function() {
  869. controller.set('serviceConfigTags', [{
  870. siteName: 'site1',
  871. configs: {}
  872. }]);
  873. controller.set('configs', [{
  874. id: 'site property',
  875. name: 'config1',
  876. value: "value1",
  877. filename: 'site1.xml'
  878. }]);
  879. expect(controller.manageSecureConfigs()).to.be.true;
  880. expect(controller.get('serviceConfigTags')[0].configs).to.eql({'config1': 'value1'});
  881. });
  882. it('Add configs from global.xml, config matches "_hosts"', function() {
  883. controller.set('serviceConfigTags', [{
  884. siteName: 'global',
  885. configs: {}
  886. }]);
  887. controller.set('globalProperties', [{
  888. id: 'site property',
  889. name: 'config1_hosts',
  890. value: "value1",
  891. filename: 'site1.xml'
  892. }]);
  893. controller.set('secureConfigs', [{
  894. serviceName: 'service1',
  895. name: 'config1'
  896. }]);
  897. expect(controller.manageSecureConfigs()).to.be.true;
  898. expect(controller.get('serviceConfigTags')[0].configs).to.eql({});
  899. expect(controller.setPrincipalValue.calledWith('service1', 'config1')).to.be.true;
  900. });
  901. it('Add configs from global.xml, config does not match "_hosts"', function() {
  902. controller.set('serviceConfigTags', [{
  903. siteName: 'global',
  904. configs: {}
  905. }]);
  906. controller.set('globalProperties', [{
  907. id: 'site property',
  908. name: 'config1',
  909. value: "value1",
  910. filename: 'site1.xml'
  911. }]);
  912. controller.set('secureConfigs', [{
  913. serviceName: 'service1',
  914. name: 'config1'
  915. }]);
  916. expect(controller.manageSecureConfigs()).to.be.true;
  917. expect(controller.get('serviceConfigTags')[0].configs).to.eql({'config1': 'value1'});
  918. expect(controller.setPrincipalValue.calledWith('service1', 'config1')).to.be.true;
  919. });
  920. });
  921. describe('#setPrincipalValue()', function() {
  922. it('secureServices does not contain such service', function() {
  923. controller.set('secureServices', []);
  924. expect(controller.setPrincipalValue('service1', 'principal1')).to.be.false;
  925. });
  926. it('secureServices contains such service', function() {
  927. controller.set('secureServices', [{
  928. serviceName: 'service1'
  929. }]);
  930. controller.set('globalProperties', [
  931. {
  932. name: 'kerberos_domain',
  933. value: 'value1'
  934. },
  935. {
  936. name: 'principal1',
  937. value: 'value2'
  938. }
  939. ]);
  940. expect(controller.setPrincipalValue('service1', 'principal1')).to.be.true;
  941. expect(controller.get('globalProperties').findProperty('name', 'principal1').value).to.equal('value2@value1');
  942. });
  943. });
  944. describe('#deleteComponents()', function() {
  945. it('Send ajax', function() {
  946. sinon.stub(App.ajax, 'send', Em.K);
  947. controller.deleteComponents('comp1', 'host1');
  948. expect(App.ajax.send.calledOnce).to.be.true;
  949. App.ajax.send.restore();
  950. });
  951. });
  952. describe('#onDeleteComplete()', function() {
  953. it('', function() {
  954. controller.set('commands', [Em.Object.create({
  955. name: 'DELETE_ATS'
  956. })]);
  957. controller.onDeleteComplete();
  958. expect(controller.get('commands').findProperty('name', 'DELETE_ATS').get('isError')).to.be.false;
  959. expect(controller.get('commands').findProperty('name', 'DELETE_ATS').get('isSuccess')).to.be.true;
  960. });
  961. });
  962. describe('#onJsError()', function() {
  963. it('Show popup', function() {
  964. sinon.stub(App.ModalPopup, 'show', Em.K);
  965. controller.onJsError();
  966. expect(App.ModalPopup.show.calledOnce).to.be.true;
  967. App.ModalPopup.show.restore();
  968. });
  969. });
  970. });