step4_test.js 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  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. testCases.forEach(function(test){
  457. it(test.title, function() {
  458. controller.set('globalProperties', [{
  459. name: 'config1',
  460. value: 'value1'
  461. }]);
  462. expect(controller.getGlobConfigValue(test.arguments.templateName, test.arguments.expression)).to.equal(test.result);
  463. });
  464. });
  465. });
  466. describe('#formatConfigName()', function() {
  467. it('config.value is null', function() {
  468. var config = {
  469. value: null
  470. };
  471. expect(controller.formatConfigName([], config)).to.be.false;
  472. });
  473. it('config.name does not contain foreignKey', function() {
  474. var config = {
  475. value: 'value1',
  476. name: 'config1'
  477. };
  478. expect(controller.formatConfigName([], config)).to.be.false;
  479. });
  480. it('globalProperties is empty, use uiConfig', function() {
  481. var config = {
  482. value: 'value1',
  483. name: '<foreignKey[0]>',
  484. foreignKey: ['key1']
  485. };
  486. controller.set('globalProperties', []);
  487. var uiConfig = [{
  488. name: 'key1',
  489. value: 'globalValue1'
  490. }];
  491. expect(controller.formatConfigName(uiConfig, config)).to.be.true;
  492. expect(config._name).to.equal('globalValue1');
  493. });
  494. it('uiConfig is empty, use globalProperties', function() {
  495. var config = {
  496. value: 'value1',
  497. name: '<foreignKey[0]>',
  498. foreignKey: ['key1']
  499. };
  500. controller.set('globalProperties', [{
  501. name: 'key1',
  502. value: 'globalValue1'
  503. }]);
  504. var uiConfig = [];
  505. expect(controller.formatConfigName(uiConfig, config)).to.be.true;
  506. expect(config._name).to.equal('globalValue1');
  507. });
  508. });
  509. describe('#setConfigValue()', function() {
  510. it('config.value is null', function() {
  511. var config = {
  512. value: null
  513. };
  514. expect(controller.setConfigValue(config)).to.be.false;
  515. });
  516. it('config.value does not match "templateName"', function() {
  517. var config = {
  518. value: ''
  519. };
  520. expect(controller.setConfigValue(config)).to.be.false;
  521. });
  522. it('No such property in global configs', function() {
  523. var config = {
  524. value: '<templateName[0]>',
  525. templateName: ['config1']
  526. };
  527. controller.set('globalProperties', []);
  528. expect(controller.setConfigValue(config)).to.be.true;
  529. expect(config.value).to.be.null;
  530. });
  531. it('Property in global configs', function() {
  532. var config = {
  533. value: '<templateName[0]>',
  534. templateName: ['config1']
  535. };
  536. controller.set('globalProperties', [{
  537. name: 'config1',
  538. value: 'value1'
  539. }]);
  540. expect(controller.setConfigValue(config)).to.be.true;
  541. expect(config.value).to.equal('value1');
  542. });
  543. });
  544. describe('#prepareSecureConfigs()', function() {
  545. beforeEach(function(){
  546. sinon.stub(controller, 'loadGlobals', Em.K);
  547. sinon.stub(controller, 'loadUiSideConfigs', function(){
  548. return [{name: 'config1'}];
  549. });
  550. });
  551. afterEach(function(){
  552. controller.loadGlobals.restore();
  553. controller.loadUiSideConfigs.restore();
  554. });
  555. it('content.serviceConfigProperties is empty', function() {
  556. controller.set('content.serviceConfigProperties', []);
  557. controller.prepareSecureConfigs();
  558. expect(controller.loadGlobals.calledOnce).to.be.true;
  559. expect(controller.loadUiSideConfigs.calledOnce).to.be.true;
  560. expect(controller.get('configs')).to.eql([{name: 'config1'}]);
  561. });
  562. it('content.serviceConfigProperties is empty', function() {
  563. controller.set('content.serviceConfigProperties', [{
  564. id: 'site property',
  565. name: 'config2'
  566. }]);
  567. controller.prepareSecureConfigs();
  568. expect(controller.loadGlobals.calledOnce).to.be.true;
  569. expect(controller.loadUiSideConfigs.calledOnce).to.be.true;
  570. expect(controller.get('configs')).to.eql([
  571. {
  572. id: 'site property',
  573. name: 'config2'
  574. },
  575. {name: 'config1'}
  576. ]);
  577. });
  578. });
  579. describe('#loadGlobals()', function() {
  580. beforeEach(function(){
  581. sinon.stub(controller, 'loadStaticGlobal', Em.K);
  582. sinon.stub(controller, 'loadUsersToGlobal', Em.K);
  583. sinon.stub(controller, 'loadHostNamesToGlobal', Em.K);
  584. sinon.stub(controller, 'loadPrimaryNamesToGlobals', Em.K);
  585. });
  586. afterEach(function(){
  587. controller.loadStaticGlobal.restore();
  588. controller.loadUsersToGlobal.restore();
  589. controller.loadHostNamesToGlobal.restore();
  590. controller.loadPrimaryNamesToGlobals.restore();
  591. });
  592. it('content.serviceConfigProperties is empty', function() {
  593. controller.set('content.serviceConfigProperties', []);
  594. controller.loadGlobals();
  595. expect(controller.loadStaticGlobal.calledOnce).to.be.true;
  596. expect(controller.loadUsersToGlobal.calledOnce).to.be.true;
  597. expect(controller.loadHostNamesToGlobal.calledOnce).to.be.true;
  598. expect(controller.loadPrimaryNamesToGlobals.calledOnce).to.be.true;
  599. expect(controller.get('globalProperties')).to.be.empty;
  600. });
  601. it('content.serviceConfigProperties is correct', function() {
  602. controller.set('content.serviceConfigProperties', [{
  603. id: 'puppet var',
  604. name: 'config1'
  605. }]);
  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.eql([{
  612. id: 'puppet var',
  613. name: 'config1'
  614. }]);
  615. });
  616. });
  617. describe('#loadUsersToGlobal()', function() {
  618. beforeEach(function(){
  619. sinon.stub(controller, 'loadUsersFromServer', Em.K);
  620. });
  621. afterEach(function(){
  622. controller.loadUsersFromServer.restore();
  623. App.router.get.restore();
  624. });
  625. it('serviceUsers is empty', function() {
  626. sinon.stub(App.router, 'get', function(){
  627. return [];
  628. });
  629. controller.set('serviceUsers', []);
  630. controller.set('globalProperties', []);
  631. controller.loadUsersToGlobal();
  632. expect(controller.loadUsersFromServer.calledOnce).to.be.true;
  633. expect(controller.get('globalProperties')).to.be.empty;
  634. });
  635. it('serviceUsers is correct', function() {
  636. sinon.stub(App.router, 'get', function(){
  637. return [{name: 'user1'}];
  638. });
  639. controller.set('serviceUsers', [{}]);
  640. controller.set('globalProperties', []);
  641. controller.loadUsersToGlobal();
  642. expect(controller.loadUsersFromServer.called).to.be.false;
  643. expect(controller.get('globalProperties').mapProperty('name')).to.eql(['user1']);
  644. });
  645. });
  646. describe('#addHostConfig()', function() {
  647. afterEach(function () {
  648. App.Service.find.restore();
  649. });
  650. it('No such service loaded', function() {
  651. sinon.stub(App.Service, 'find', function(){
  652. return Em.Object.create({isLoaded: false});
  653. });
  654. expect(controller.addHostConfig('service1', 'comp1', 'config1')).to.be.false;
  655. });
  656. it('No such service in secureServices', function() {
  657. sinon.stub(App.Service, 'find', function(){
  658. return Em.Object.create({isLoaded: true});
  659. });
  660. controller.set('secureServices', []);
  661. expect(controller.addHostConfig('service1', 'comp1', 'config1')).to.be.false;
  662. });
  663. it('Service does not have such host-component', function() {
  664. sinon.stub(App.Service, 'find', function(){
  665. return Em.Object.create({
  666. isLoaded: true,
  667. hostComponents: []
  668. });
  669. });
  670. controller.set('secureServices', [{
  671. serviceName: 'service1'
  672. }]);
  673. expect(controller.addHostConfig('service1', 'comp1', 'config1')).to.be.false;
  674. });
  675. it('Push config to globalProperties', function() {
  676. sinon.stub(App.Service, 'find', function(){
  677. return Em.Object.create({
  678. isLoaded: true,
  679. hostComponents: [Em.Object.create({
  680. componentName: 'comp1',
  681. host: {hostName: 'host1'}
  682. })]
  683. });
  684. });
  685. controller.set('secureServices', [{
  686. serviceName: 'service1'
  687. }]);
  688. controller.set('globalProperties', []);
  689. expect(controller.addHostConfig('service1', 'comp1', 'config1')).to.be.true;
  690. expect(controller.get('globalProperties')).to.eql([{
  691. id: 'puppet var',
  692. name: 'config1',
  693. value: 'host1'
  694. }]);
  695. });
  696. });
  697. describe('#loadHostNamesToGlobal()', function() {
  698. beforeEach(function () {
  699. sinon.stub(controller, 'addHostConfig', Em.K);
  700. });
  701. afterEach(function () {
  702. controller.addHostConfig.restore();
  703. });
  704. it('componentsConfig is empty', function() {
  705. controller.set('componentsConfig', []);
  706. controller.loadHostNamesToGlobal();
  707. expect(controller.addHostConfig.called).to.be.false;
  708. });
  709. it('componentsConfig is correct', function() {
  710. controller.set('componentsConfig', [{
  711. serviceName: 'service1',
  712. componentName: 'comp1',
  713. configName: 'config1'
  714. }]);
  715. controller.loadHostNamesToGlobal();
  716. expect(controller.addHostConfig.calledWith('service1', 'comp1', 'config1')).to.be.true;
  717. });
  718. });
  719. describe('#loadStaticGlobal()', function() {
  720. it('globalProperties contains "security_enabled" property', function() {
  721. controller.set('globalProperties', [{
  722. name: 'security_enabled'
  723. }]);
  724. controller.loadStaticGlobal();
  725. expect(controller.get('globalProperties').findProperty('name', 'security_enabled').value).to.equal('true');
  726. });
  727. });
  728. describe('#loadPrimaryNamesToGlobals()', function() {
  729. beforeEach(function(){
  730. controller.set('globalProperties', []);
  731. });
  732. afterEach(function () {
  733. controller.getPrincipalNames.restore();
  734. });
  735. it('No principal names', function() {
  736. sinon.stub(controller, 'getPrincipalNames', function(){
  737. return [];
  738. });
  739. controller.loadPrimaryNamesToGlobals();
  740. expect(controller.get('globalProperties')).to.be.empty;
  741. });
  742. it('Principal name does not contain "principal"', function() {
  743. sinon.stub(controller, 'getPrincipalNames', function(){
  744. return [{
  745. name: 'config1',
  746. value: 'value2/value1'
  747. }];
  748. });
  749. controller.loadPrimaryNamesToGlobals();
  750. expect(controller.get('globalProperties')).to.eql([{name: 'config1', value: 'value2'}]);
  751. });
  752. it('Principal name contains "principal"', function() {
  753. sinon.stub(controller, 'getPrincipalNames', function(){
  754. return [{
  755. name: 'principal1',
  756. value: 'value1'
  757. }];
  758. });
  759. controller.loadPrimaryNamesToGlobals();
  760. expect(controller.get('globalProperties')).to.eql([{name: 'primary1', value: 'value1'}]);
  761. });
  762. });
  763. describe('#getPrincipalNames()', function() {
  764. beforeEach(function () {
  765. controller.set('globalProperties', []);
  766. controller.set('secureProperties', []);
  767. });
  768. it('globalProperties and secureProperties are empty', function() {
  769. expect(controller.getPrincipalNames()).to.be.empty;
  770. });
  771. it('global property name does not match "principal_name"', function() {
  772. controller.set('globalProperties', [{
  773. name: 'config1'
  774. }]);
  775. expect(controller.getPrincipalNames()).to.be.empty;
  776. });
  777. it('secure property name does not match "principal_name"', function() {
  778. controller.set('secureProperties', [{
  779. name: 'config1'
  780. }]);
  781. expect(controller.getPrincipalNames()).to.be.empty;
  782. });
  783. it('global property name matches "principal_name"', function() {
  784. controller.set('globalProperties', [{
  785. name: 'principal_name'
  786. }]);
  787. expect(controller.getPrincipalNames()).to.eql([{
  788. name: 'principal_name'
  789. }]);
  790. });
  791. it('property with such name already exists', function() {
  792. controller.set('globalProperties', [{
  793. name: 'principal_name'
  794. }]);
  795. controller.set('secureProperties', [{
  796. name: 'principal_name'
  797. }]);
  798. expect(controller.getPrincipalNames().mapProperty('name')).to.eql(['principal_name']);
  799. });
  800. it('global and secure property name matches "principal_name"', function() {
  801. controller.set('globalProperties', [{
  802. name: 'global_principal_name'
  803. }]);
  804. controller.set('secureProperties', [{
  805. name: 'secure_principal_name',
  806. defaultValue: 'value1'
  807. }]);
  808. expect(controller.getPrincipalNames().mapProperty('name')).to.eql(['global_principal_name', 'secure_principal_name']);
  809. expect(controller.getPrincipalNames().findProperty('name', 'secure_principal_name').value).to.equal('value1');
  810. });
  811. });
  812. describe('#loadUsersFromServer()', function() {
  813. it('testMode = true', function() {
  814. controller.set('testModeUsers', [{
  815. name: 'user1',
  816. value: 'value1'
  817. }]);
  818. controller.set('serviceUsers', []);
  819. App.testMode = true;
  820. controller.loadUsersFromServer();
  821. expect(controller.get('serviceUsers')).to.eql([{
  822. name: 'user1',
  823. value: 'value1',
  824. id: 'puppet var'
  825. }]);
  826. });
  827. it('testMode = false', function() {
  828. sinon.stub(App.router, 'set', Em.K);
  829. sinon.stub(App.db, 'getSecureUserInfo', function(){
  830. return [];
  831. });
  832. App.testMode = false;
  833. controller.loadUsersFromServer();
  834. expect(App.db.getSecureUserInfo.calledOnce).to.be.true;
  835. expect(App.router.set.calledWith('mainAdminSecurityController.serviceUsers', [])).to.be.true;
  836. App.router.set.restore();
  837. App.db.getSecureUserInfo.restore();
  838. });
  839. });
  840. describe('#manageSecureConfigs()', function() {
  841. beforeEach(function () {
  842. sinon.stub(controller, 'setPrincipalValue', Em.K);
  843. });
  844. afterEach(function () {
  845. controller.setPrincipalValue.restore();
  846. });
  847. it('serviceConfigTags is null', function() {
  848. sinon.stub(controller, 'onJsError', Em.K);
  849. controller.set('serviceConfigTags', null);
  850. controller.set('configs', [{id: 'site property'}]);
  851. controller.set('commands', [Em.Object.create({
  852. name: 'APPLY_CONFIGURATIONS'
  853. })]);
  854. expect(controller.manageSecureConfigs()).to.be.false;
  855. expect(controller.onJsError.calledOnce).to.be.true;
  856. expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isSuccess')).to.be.false;
  857. expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isError')).to.be.true;
  858. controller.onJsError.restore();
  859. });
  860. it('Add configs from site-*.xml', function() {
  861. controller.set('serviceConfigTags', [{
  862. siteName: 'site1',
  863. configs: {}
  864. }]);
  865. controller.set('configs', [{
  866. id: 'site property',
  867. name: 'config1',
  868. value: "value1",
  869. filename: 'site1.xml'
  870. }]);
  871. expect(controller.manageSecureConfigs()).to.be.true;
  872. expect(controller.get('serviceConfigTags')[0].configs).to.eql({'config1': 'value1'});
  873. });
  874. it('Add configs from global.xml, config matches "_hosts"', function() {
  875. controller.set('serviceConfigTags', [{
  876. siteName: 'global',
  877. configs: {}
  878. }]);
  879. controller.set('globalProperties', [{
  880. id: 'site property',
  881. name: 'config1_hosts',
  882. value: "value1",
  883. filename: 'site1.xml'
  884. }]);
  885. controller.set('secureConfigs', [{
  886. serviceName: 'service1',
  887. name: 'config1'
  888. }]);
  889. expect(controller.manageSecureConfigs()).to.be.true;
  890. expect(controller.get('serviceConfigTags')[0].configs).to.eql({});
  891. expect(controller.setPrincipalValue.calledWith('service1', 'config1')).to.be.true;
  892. });
  893. it('Add configs from global.xml, config does not match "_hosts"', function() {
  894. controller.set('serviceConfigTags', [{
  895. siteName: 'global',
  896. configs: {}
  897. }]);
  898. controller.set('globalProperties', [{
  899. id: 'site property',
  900. name: 'config1',
  901. value: "value1",
  902. filename: 'site1.xml'
  903. }]);
  904. controller.set('secureConfigs', [{
  905. serviceName: 'service1',
  906. name: 'config1'
  907. }]);
  908. expect(controller.manageSecureConfigs()).to.be.true;
  909. expect(controller.get('serviceConfigTags')[0].configs).to.eql({'config1': 'value1'});
  910. expect(controller.setPrincipalValue.calledWith('service1', 'config1')).to.be.true;
  911. });
  912. });
  913. describe('#setPrincipalValue()', function() {
  914. it('secureServices does not contain such service', function() {
  915. controller.set('secureServices', []);
  916. expect(controller.setPrincipalValue('service1', 'principal1')).to.be.false;
  917. });
  918. it('secureServices contains such service', function() {
  919. controller.set('secureServices', [{
  920. serviceName: 'service1'
  921. }]);
  922. controller.set('globalProperties', [
  923. {
  924. name: 'kerberos_domain',
  925. value: 'value1'
  926. },
  927. {
  928. name: 'principal1',
  929. value: 'value2'
  930. }
  931. ]);
  932. expect(controller.setPrincipalValue('service1', 'principal1')).to.be.true;
  933. expect(controller.get('globalProperties').findProperty('name', 'principal1').value).to.equal('value2@value1');
  934. });
  935. });
  936. describe('#deleteComponents()', function() {
  937. it('Send ajax', function() {
  938. sinon.stub(App.ajax, 'send', Em.K);
  939. controller.deleteComponents('comp1', 'host1');
  940. expect(App.ajax.send.calledOnce).to.be.true;
  941. App.ajax.send.restore();
  942. });
  943. });
  944. describe('#onDeleteComplete()', function() {
  945. it('', function() {
  946. controller.set('commands', [Em.Object.create({
  947. name: 'DELETE_ATS'
  948. })]);
  949. controller.onDeleteComplete();
  950. expect(controller.get('commands').findProperty('name', 'DELETE_ATS').get('isError')).to.be.false;
  951. expect(controller.get('commands').findProperty('name', 'DELETE_ATS').get('isSuccess')).to.be.true;
  952. });
  953. });
  954. describe('#onJsError()', function() {
  955. it('Show popup', function() {
  956. sinon.stub(App.ModalPopup, 'show', Em.K);
  957. controller.onJsError();
  958. expect(App.ModalPopup.show.calledOnce).to.be.true;
  959. App.ModalPopup.show.restore();
  960. });
  961. });
  962. });