step4_test.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  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, 'checkServiceForConfigValue', function() {
  326. return 'value2';
  327. });
  328. sinon.stub(controller, 'setConfigValue', Em.K);
  329. sinon.stub(controller, 'formatConfigName', Em.K);
  330. });
  331. afterEach(function(){
  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('#formatConfigName()', function() {
  430. it('config.value is null', function() {
  431. var config = {
  432. value: null
  433. };
  434. expect(controller.formatConfigName([], config)).to.be.false;
  435. });
  436. it('config.name does not contain foreignKey', function() {
  437. var config = {
  438. value: 'value1',
  439. name: 'config1'
  440. };
  441. expect(controller.formatConfigName([], config)).to.be.false;
  442. });
  443. it('globalProperties is empty, use uiConfig', function() {
  444. var config = {
  445. value: 'value1',
  446. name: '<foreignKey[0]>',
  447. foreignKey: ['key1']
  448. };
  449. controller.set('globalProperties', []);
  450. var uiConfig = [{
  451. name: 'key1',
  452. value: 'globalValue1'
  453. }];
  454. expect(controller.formatConfigName(uiConfig, config)).to.be.true;
  455. expect(config._name).to.equal('globalValue1');
  456. });
  457. });
  458. describe('#setConfigValue()', function() {
  459. it('config.value is null', function() {
  460. var config = {
  461. value: null
  462. };
  463. expect(controller.setConfigValue(config)).to.be.false;
  464. });
  465. it('config.value does not match "templateName"', function() {
  466. var config = {
  467. value: ''
  468. };
  469. expect(controller.setConfigValue(config)).to.be.false;
  470. });
  471. it('No such property in global configs', function() {
  472. var config = {
  473. value: '<templateName[0]>',
  474. templateName: ['config1']
  475. };
  476. controller.set('globalProperties', []);
  477. expect(controller.setConfigValue(config)).to.be.true;
  478. expect(config.value).to.be.null;
  479. });
  480. });
  481. describe('#prepareSecureConfigs()', function() {
  482. beforeEach(function(){
  483. sinon.stub(controller, 'loadUiSideConfigs', function(){
  484. return [{name: 'config1'}];
  485. });
  486. });
  487. afterEach(function(){
  488. controller.loadUiSideConfigs.restore();
  489. });
  490. it('content.serviceConfigProperties is empty', function() {
  491. controller.set('content.serviceConfigProperties', []);
  492. controller.prepareSecureConfigs();
  493. expect(controller.loadUiSideConfigs.calledOnce).to.be.true;
  494. expect(controller.get('configs')).to.eql([{name: 'config1'}]);
  495. });
  496. it('content.serviceConfigProperties is empty', function() {
  497. controller.set('content.serviceConfigProperties', [{
  498. id: 'site property',
  499. name: 'config2'
  500. }]);
  501. controller.prepareSecureConfigs();
  502. expect(controller.loadUiSideConfigs.calledOnce).to.be.true;
  503. expect(controller.get('configs')).to.eql([
  504. {
  505. id: 'site property',
  506. name: 'config2'
  507. },
  508. {name: 'config1'}
  509. ]);
  510. });
  511. });
  512. describe('#loadUsersToGlobal()', function() {
  513. beforeEach(function(){
  514. sinon.stub(controller, 'loadUsersFromServer', Em.K);
  515. });
  516. afterEach(function(){
  517. controller.loadUsersFromServer.restore();
  518. App.router.get.restore();
  519. });
  520. it('serviceUsers is empty', function() {
  521. sinon.stub(App.router, 'get', function(){
  522. return [];
  523. });
  524. controller.set('serviceUsers', []);
  525. controller.set('globalProperties', []);
  526. controller.loadUsersToGlobal();
  527. expect(controller.loadUsersFromServer.calledOnce).to.be.true;
  528. expect(controller.get('globalProperties')).to.be.empty;
  529. });
  530. it('serviceUsers is correct', function() {
  531. sinon.stub(App.router, 'get', function(){
  532. return [{name: 'user1'}];
  533. });
  534. controller.set('serviceUsers', [{}]);
  535. controller.set('globalProperties', []);
  536. controller.loadUsersToGlobal();
  537. expect(controller.loadUsersFromServer.called).to.be.false;
  538. expect(controller.get('globalProperties').mapProperty('name')).to.eql(['user1']);
  539. });
  540. });
  541. describe('#addHostConfig()', function() {
  542. afterEach(function () {
  543. App.Service.find.restore();
  544. });
  545. it('No such service loaded', function() {
  546. sinon.stub(App.Service, 'find', function(){
  547. return Em.Object.create({isLoaded: false});
  548. });
  549. expect(controller.addHostConfig('service1', 'comp1', 'config1')).to.be.false;
  550. });
  551. it('No such service in secureServices', function() {
  552. sinon.stub(App.Service, 'find', function(){
  553. return Em.Object.create({isLoaded: true});
  554. });
  555. controller.set('secureServices', []);
  556. expect(controller.addHostConfig('service1', 'comp1', 'config1')).to.be.false;
  557. });
  558. it('Service does not have such host-component', function() {
  559. sinon.stub(App.Service, 'find', function(){
  560. return Em.Object.create({
  561. isLoaded: true,
  562. hostComponents: []
  563. });
  564. });
  565. controller.set('secureServices', [{
  566. serviceName: 'service1'
  567. }]);
  568. expect(controller.addHostConfig('service1', 'comp1', 'config1')).to.be.false;
  569. });
  570. it('Push config to globalProperties', function() {
  571. sinon.stub(App.Service, 'find', function(){
  572. return Em.Object.create({
  573. isLoaded: true,
  574. hostComponents: [Em.Object.create({
  575. componentName: 'comp1',
  576. hostName: 'host1'
  577. })]
  578. });
  579. });
  580. controller.set('secureServices', [{
  581. serviceName: 'service1'
  582. }]);
  583. controller.set('globalProperties', []);
  584. expect(controller.addHostConfig('service1', 'comp1', 'config1')).to.be.true;
  585. expect(controller.get('globalProperties')).to.eql([{
  586. id: 'puppet var',
  587. name: 'config1',
  588. value: 'host1'
  589. }]);
  590. });
  591. });
  592. describe('#loadHostNamesToGlobal()', function() {
  593. beforeEach(function () {
  594. sinon.stub(controller, 'addHostConfig', Em.K);
  595. });
  596. afterEach(function () {
  597. controller.addHostConfig.restore();
  598. });
  599. it('componentsConfig is empty', function() {
  600. controller.set('componentsConfig', []);
  601. controller.loadHostNamesToGlobal();
  602. expect(controller.addHostConfig.called).to.be.false;
  603. });
  604. it('componentsConfig is correct', function() {
  605. controller.set('componentsConfig', [{
  606. serviceName: 'service1',
  607. componentName: 'comp1',
  608. configName: 'config1'
  609. }]);
  610. controller.loadHostNamesToGlobal();
  611. expect(controller.addHostConfig.calledWith('service1', 'comp1', 'config1')).to.be.true;
  612. });
  613. });
  614. describe('#loadStaticGlobal()', function() {
  615. it('globalProperties contains "security_enabled" property', function() {
  616. controller.set('globalProperties', [{
  617. name: 'security_enabled'
  618. }]);
  619. controller.loadStaticGlobal();
  620. expect(controller.get('globalProperties').findProperty('name', 'security_enabled').value).to.equal('true');
  621. });
  622. });
  623. describe('#loadPrimaryNamesToGlobals()', function() {
  624. beforeEach(function(){
  625. controller.set('globalProperties', []);
  626. });
  627. afterEach(function () {
  628. controller.getPrincipalNames.restore();
  629. });
  630. it('No principal names', function() {
  631. sinon.stub(controller, 'getPrincipalNames', function(){
  632. return [];
  633. });
  634. controller.loadPrimaryNamesToGlobals();
  635. expect(controller.get('globalProperties')).to.be.empty;
  636. });
  637. it('Principal name does not contain "principal"', function() {
  638. sinon.stub(controller, 'getPrincipalNames', function(){
  639. return [{
  640. name: 'config1',
  641. value: 'value2/value1'
  642. }];
  643. });
  644. controller.loadPrimaryNamesToGlobals();
  645. expect(controller.get('globalProperties')).to.eql([{name: 'config1', value: 'value2'}]);
  646. });
  647. it('Principal name contains "principal"', function() {
  648. sinon.stub(controller, 'getPrincipalNames', function(){
  649. return [{
  650. name: 'principal1',
  651. value: 'value1'
  652. }];
  653. });
  654. controller.loadPrimaryNamesToGlobals();
  655. expect(controller.get('globalProperties')).to.eql([{name: 'primary1', value: 'value1'}]);
  656. });
  657. });
  658. describe('#getPrincipalNames()', function() {
  659. beforeEach(function () {
  660. controller.set('globalProperties', []);
  661. controller.set('secureProperties', []);
  662. });
  663. it('globalProperties and secureProperties are empty', function() {
  664. expect(controller.getPrincipalNames()).to.be.empty;
  665. });
  666. it('global property name does not match "principal_name"', function() {
  667. controller.set('globalProperties', [{
  668. name: 'config1'
  669. }]);
  670. expect(controller.getPrincipalNames()).to.be.empty;
  671. });
  672. it('secure property name does not match "principal_name"', function() {
  673. controller.set('secureProperties', [{
  674. name: 'config1'
  675. }]);
  676. expect(controller.getPrincipalNames()).to.be.empty;
  677. });
  678. it('global property name matches "principal_name"', function() {
  679. controller.set('globalProperties', [{
  680. name: 'principal_name'
  681. }]);
  682. expect(controller.getPrincipalNames()).to.eql([{
  683. name: 'principal_name'
  684. }]);
  685. });
  686. it('property with such name already exists', function() {
  687. controller.set('globalProperties', [{
  688. name: 'principal_name'
  689. }]);
  690. controller.set('secureProperties', [{
  691. name: 'principal_name'
  692. }]);
  693. expect(controller.getPrincipalNames().mapProperty('name')).to.eql(['principal_name']);
  694. });
  695. it('global and secure property name matches "principal_name"', function() {
  696. controller.set('globalProperties', [{
  697. name: 'global_principal_name'
  698. }]);
  699. controller.set('secureProperties', [{
  700. name: 'secure_principal_name',
  701. defaultValue: 'value1'
  702. }]);
  703. expect(controller.getPrincipalNames().mapProperty('name')).to.eql(['global_principal_name', 'secure_principal_name']);
  704. expect(controller.getPrincipalNames().findProperty('name', 'secure_principal_name').value).to.equal('value1');
  705. });
  706. });
  707. describe('#loadUsersFromServer()', function() {
  708. it('testMode = true', function() {
  709. controller.set('testModeUsers', [{
  710. name: 'user1',
  711. value: 'value1'
  712. }]);
  713. controller.set('serviceUsers', []);
  714. sinon.stub(App, 'get', function(k) {
  715. if ('testMode' === k) return true;
  716. return Em.get(App, k);
  717. });
  718. controller.loadUsersFromServer();
  719. expect(controller.get('serviceUsers')).to.eql([{
  720. name: 'user1',
  721. value: 'value1',
  722. id: 'puppet var'
  723. }]);
  724. App.get.restore();
  725. });
  726. it('testMode = false', function() {
  727. sinon.stub(App.router, 'set', Em.K);
  728. sinon.stub(App.db, 'getSecureUserInfo', function(){
  729. return [];
  730. });
  731. sinon.stub(App, 'get', function(k) {
  732. if ('testMode' === k) return false;
  733. return Em.get(App, k);
  734. });
  735. controller.loadUsersFromServer();
  736. expect(App.db.getSecureUserInfo.calledOnce).to.be.true;
  737. expect(App.router.set.calledWith('mainAdminSecurityController.serviceUsers', [])).to.be.true;
  738. App.router.set.restore();
  739. App.get.restore();
  740. App.db.getSecureUserInfo.restore();
  741. });
  742. });
  743. describe('#manageSecureConfigs()', function() {
  744. beforeEach(function () {
  745. sinon.stub(controller, 'setPrincipalValue', Em.K);
  746. });
  747. afterEach(function () {
  748. controller.setPrincipalValue.restore();
  749. });
  750. it('serviceConfigTags is null', function() {
  751. sinon.stub(controller, 'onJsError', Em.K);
  752. controller.set('serviceConfigTags', null);
  753. controller.set('configs', [{id: 'site property'}]);
  754. controller.set('commands', [Em.Object.create({
  755. name: 'APPLY_CONFIGURATIONS'
  756. })]);
  757. expect(controller.manageSecureConfigs()).to.be.false;
  758. expect(controller.onJsError.calledOnce).to.be.true;
  759. expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isSuccess')).to.be.false;
  760. expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isError')).to.be.true;
  761. controller.onJsError.restore();
  762. });
  763. it('Add configs from site-*.xml', function() {
  764. controller.set('serviceConfigTags', [{
  765. siteName: 'site1',
  766. configs: {}
  767. }]);
  768. controller.set('configs', [{
  769. id: 'site property',
  770. name: 'config1',
  771. value: "value1",
  772. filename: 'site1.xml'
  773. }]);
  774. expect(controller.manageSecureConfigs()).to.be.true;
  775. expect(controller.get('serviceConfigTags')[0].configs).to.eql({'config1': 'value1'});
  776. });
  777. it('Add configs from global.xml, config matches "_hosts"', function() {
  778. controller.set('serviceConfigTags', [{
  779. siteName: 'global',
  780. configs: {}
  781. }]);
  782. controller.set('globalProperties', [{
  783. id: 'site property',
  784. name: 'config1_hosts',
  785. value: "value1",
  786. filename: 'site1.xml'
  787. }]);
  788. controller.set('secureConfigs', [{
  789. serviceName: 'service1',
  790. name: 'config1'
  791. }]);
  792. expect(controller.manageSecureConfigs()).to.be.true;
  793. expect(controller.get('serviceConfigTags')[0].configs).to.eql({});
  794. expect(controller.setPrincipalValue.calledWith('service1', 'config1')).to.be.true;
  795. });
  796. it('Add configs from global.xml, config does not match "_hosts"', function() {
  797. controller.set('serviceConfigTags', [{
  798. siteName: 'global',
  799. configs: {}
  800. }]);
  801. controller.set('globalProperties', [{
  802. id: 'site property',
  803. name: 'config1',
  804. value: "value1",
  805. filename: 'site1.xml'
  806. }]);
  807. controller.set('secureConfigs', [{
  808. serviceName: 'service1',
  809. name: 'config1'
  810. }]);
  811. expect(controller.manageSecureConfigs()).to.be.true;
  812. expect(controller.get('serviceConfigTags')[0].configs).to.eql({'config1': 'value1'});
  813. expect(controller.setPrincipalValue.calledWith('service1', 'config1')).to.be.true;
  814. });
  815. });
  816. describe('#setPrincipalValue()', function() {
  817. it('secureServices does not contain such service', function() {
  818. controller.set('secureServices', []);
  819. expect(controller.setPrincipalValue('service1', 'principal1')).to.be.false;
  820. });
  821. it('secureServices contains such service', function() {
  822. controller.set('secureServices', [{
  823. serviceName: 'service1'
  824. }]);
  825. controller.set('globalProperties', [
  826. {
  827. name: 'kerberos_domain',
  828. value: 'value1'
  829. },
  830. {
  831. name: 'principal1',
  832. value: 'value2'
  833. }
  834. ]);
  835. expect(controller.setPrincipalValue('service1', 'principal1')).to.be.true;
  836. expect(controller.get('globalProperties').findProperty('name', 'principal1').value).to.equal('value2@value1');
  837. });
  838. });
  839. describe('#deleteComponents()', function() {
  840. it('Send ajax', function() {
  841. sinon.stub(App.ajax, 'send', Em.K);
  842. controller.deleteComponents('comp1', 'host1');
  843. expect(App.ajax.send.calledOnce).to.be.true;
  844. App.ajax.send.restore();
  845. });
  846. });
  847. describe('#onDeleteComplete()', function() {
  848. it('', function() {
  849. controller.set('commands', [Em.Object.create({
  850. name: 'DELETE_ATS'
  851. })]);
  852. controller.onDeleteComplete();
  853. expect(controller.get('commands').findProperty('name', 'DELETE_ATS').get('isError')).to.be.false;
  854. expect(controller.get('commands').findProperty('name', 'DELETE_ATS').get('isSuccess')).to.be.true;
  855. });
  856. });
  857. describe('#onJsError()', function() {
  858. it('Show popup', function() {
  859. sinon.stub(App.ModalPopup, 'show', Em.K);
  860. controller.onJsError();
  861. expect(App.ModalPopup.show.calledOnce).to.be.true;
  862. App.ModalPopup.show.restore();
  863. });
  864. });
  865. });