step4_test.js 34 KB

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