step4_test.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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('mixins/wizard/addSecurityConfigs');
  22. require('utils/polling');
  23. require('models/cluster_states');
  24. require('models/service');
  25. var controller;
  26. describe('App.MainAdminSecurityAddStep4Controller', function () {
  27. beforeEach(function () {
  28. controller = App.MainAdminSecurityAddStep4Controller.create({
  29. content: {},
  30. commands: [],
  31. enableSubmit: function () {
  32. this._super()
  33. },
  34. secureMapping: [],
  35. secureProperties: [],
  36. secureServices: []
  37. });
  38. });
  39. describe('#isBackBtnDisabled', function () {
  40. it('commands have error', function () {
  41. controller.set('commands', [Em.Object.create({
  42. isError: true
  43. })]);
  44. expect(controller.get('isBackBtnDisabled')).to.be.false;
  45. });
  46. it('commands do not have error', function () {
  47. controller.set('commands', [Em.Object.create({
  48. isError: false
  49. })]);
  50. expect(controller.get('isBackBtnDisabled')).to.be.true;
  51. });
  52. });
  53. describe('#isSecurityApplied', function () {
  54. var testCases = [
  55. {
  56. title: 'No START_SERVICES command',
  57. commands: [],
  58. result: false
  59. },
  60. {
  61. title: 'START_SERVICES is not success',
  62. commands: [Em.Object.create({
  63. name: 'START_SERVICES',
  64. isSuccess: false
  65. })],
  66. result: false
  67. },
  68. {
  69. title: 'START_SERVICES is success',
  70. commands: [Em.Object.create({
  71. name: 'START_SERVICES',
  72. isSuccess: true
  73. })],
  74. result: true
  75. }
  76. ];
  77. testCases.forEach(function (test) {
  78. it(test.title, function () {
  79. controller.set('commands', test.commands);
  80. expect(controller.get('isSecurityApplied')).to.equal(test.result);
  81. });
  82. });
  83. });
  84. describe('#enableSubmit()', function () {
  85. var mock = {
  86. setStepsEnable: Em.K,
  87. setLowerStepsDisable: Em.K
  88. };
  89. beforeEach(function () {
  90. sinon.stub(App.router, 'get', function () {
  91. return mock;
  92. });
  93. sinon.spy(mock, 'setStepsEnable');
  94. sinon.spy(mock, 'setLowerStepsDisable');
  95. });
  96. afterEach(function () {
  97. App.router.get.restore();
  98. mock.setStepsEnable.restore();
  99. mock.setLowerStepsDisable.restore();
  100. });
  101. it('Command has error', function () {
  102. controller.set('commands', [Em.Object.create({
  103. isError: true
  104. })]);
  105. controller.enableSubmit();
  106. expect(controller.get('isSubmitDisabled')).to.be.false;
  107. expect(mock.setStepsEnable.calledOnce).to.be.true;
  108. });
  109. it('Command is successful', function () {
  110. controller.set('commands', [Em.Object.create({
  111. isSuccess: true
  112. })]);
  113. controller.enableSubmit();
  114. expect(controller.get('isSubmitDisabled')).to.be.false;
  115. });
  116. it('Command is in progress', function () {
  117. controller.set('commands', [Em.Object.create()]);
  118. controller.enableSubmit();
  119. expect(controller.get('isSubmitDisabled')).to.be.true;
  120. expect(mock.setLowerStepsDisable.calledWith(4)).to.be.true;
  121. });
  122. });
  123. describe('#clearStep()', function () {
  124. it('Clear step info', function () {
  125. controller.set('commands', [Em.Object.create()]);
  126. controller.set('isSubmitDisabled', false);
  127. controller.set('serviceConfigTags', [
  128. {}
  129. ]);
  130. controller.clearStep();
  131. expect(controller.get('isSubmitDisabled')).to.be.true;
  132. expect(controller.get('commands')).to.be.empty;
  133. expect(controller.get('serviceConfigTags')).to.be.empty;
  134. });
  135. });
  136. describe('#loadCommands()', function () {
  137. before(function () {
  138. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  139. });
  140. after(function () {
  141. App.clusterStatus.setClusterStatus.restore();
  142. });
  143. var tests = Em.A([
  144. {
  145. doesATSSupportKerberos: true,
  146. isATSInstalled: true,
  147. e: {
  148. l: 3,
  149. d: false
  150. }
  151. },
  152. {
  153. doesATSSupportKerberos: true,
  154. isATSInstalled: false,
  155. e: {
  156. l: 3,
  157. d: false
  158. }
  159. },
  160. {
  161. doesATSSupportKerberos: false,
  162. isATSInstalled: true,
  163. e: {
  164. l: 4,
  165. d: true
  166. }
  167. },
  168. {
  169. doesATSSupportKerberos: false,
  170. isATSInstalled: false,
  171. e: {
  172. l: 3,
  173. d: false
  174. }
  175. }
  176. ]);
  177. tests.forEach(function (test) {
  178. it('doesATSSupportKerberos ' + test.doesATSSupportKerberos.toString() + ', isATSInstalled ' + test.isATSInstalled.toString(), function () {
  179. sinon.stub(App, 'get', function (k) {
  180. if ('doesATSSupportKerberos' === k) return test.doesATSSupportKerberos;
  181. return Em.get(App, k);
  182. });
  183. controller.set('content.isATSInstalled', test.isATSInstalled);
  184. controller.loadCommands();
  185. App.get.restore();
  186. expect(controller.get('commands.length')).to.equal(test.e.l);
  187. expect(controller.get('commands').someProperty('name', 'DELETE_ATS')).to.equal(test.e.d);
  188. });
  189. });
  190. });
  191. describe('#loadStep()', function () {
  192. beforeEach(function () {
  193. sinon.stub(controller, 'clearStep', Em.K);
  194. sinon.stub(controller, 'prepareSecureConfigs', Em.K);
  195. });
  196. afterEach(function () {
  197. controller.clearStep.restore();
  198. controller.prepareSecureConfigs.restore();
  199. controller.resumeSavedCommands.restore();
  200. });
  201. it('Resume saved commands', function () {
  202. sinon.stub(controller, 'resumeSavedCommands', function () {
  203. return true;
  204. });
  205. controller.loadStep();
  206. expect(controller.clearStep.calledOnce).to.be.true;
  207. expect(controller.prepareSecureConfigs.calledOnce).to.be.true;
  208. expect(controller.resumeSavedCommands.calledOnce).to.be.true;
  209. });
  210. it('No saved commands', function () {
  211. sinon.stub(controller, 'resumeSavedCommands', function () {
  212. return false;
  213. });
  214. sinon.stub(controller, 'loadCommands', Em.K);
  215. sinon.stub(controller, 'addInfoToCommands', Em.K);
  216. sinon.stub(controller, 'syncStopServicesOperation', Em.K);
  217. sinon.stub(controller, 'addObserverToCommands', Em.K);
  218. sinon.stub(controller, 'moveToNextCommand', Em.K);
  219. controller.loadStep();
  220. expect(controller.clearStep.calledOnce).to.be.true;
  221. expect(controller.prepareSecureConfigs.calledOnce).to.be.true;
  222. expect(controller.resumeSavedCommands.calledOnce).to.be.true;
  223. controller.loadCommands.restore();
  224. controller.addInfoToCommands.restore();
  225. controller.syncStopServicesOperation.restore();
  226. controller.addObserverToCommands.restore();
  227. controller.moveToNextCommand.restore();
  228. });
  229. });
  230. describe('#syncStopServicesOperation()', function () {
  231. afterEach(function () {
  232. App.router.get.restore();
  233. });
  234. it('No running operations', function () {
  235. sinon.stub(App.router, 'get', function () {
  236. return [];
  237. });
  238. expect(controller.syncStopServicesOperation()).to.be.false;
  239. });
  240. it('Running operation is not Stop All Services', function () {
  241. sinon.stub(App.router, 'get', function () {
  242. return [Em.Object.create({isRunning: true})];
  243. });
  244. expect(controller.syncStopServicesOperation()).to.be.false;
  245. });
  246. it('No STOP_SERVICES in commands', function () {
  247. sinon.stub(App.router, 'get', function () {
  248. return [Em.Object.create({
  249. isRunning: true,
  250. name: 'Stop All Services'
  251. })];
  252. });
  253. controller.set('commands', []);
  254. expect(controller.syncStopServicesOperation()).to.be.false;
  255. });
  256. it('Sync stop services commands', function () {
  257. sinon.stub(App.router, 'get', function () {
  258. return [Em.Object.create({
  259. isRunning: true,
  260. name: 'Stop All Services',
  261. id: 1
  262. })];
  263. });
  264. controller.set('commands', [Em.Object.create({
  265. name: 'STOP_SERVICES'
  266. })]);
  267. expect(controller.syncStopServicesOperation()).to.be.true;
  268. expect(controller.get('commands').findProperty('name', 'STOP_SERVICES').get('requestId')).to.equal(1);
  269. });
  270. });
  271. describe('#resumeSavedCommands()', function () {
  272. beforeEach(function () {
  273. sinon.stub(controller, 'addObserverToCommands', Em.K);
  274. sinon.stub(controller, 'moveToNextCommand', Em.K);
  275. controller.set('commands', []);
  276. });
  277. afterEach(function () {
  278. controller.moveToNextCommand.restore();
  279. controller.addObserverToCommands.restore();
  280. App.db.getSecurityDeployCommands.restore();
  281. });
  282. it('Commands is null', function () {
  283. sinon.stub(App.db, 'getSecurityDeployCommands', function () {
  284. return null;
  285. });
  286. expect(controller.resumeSavedCommands()).to.be.false;
  287. });
  288. it('Commands is empty', function () {
  289. sinon.stub(App.db, 'getSecurityDeployCommands', function () {
  290. return [];
  291. });
  292. expect(controller.resumeSavedCommands()).to.be.false;
  293. });
  294. it('Command has error', function () {
  295. sinon.stub(App.db, 'getSecurityDeployCommands', function () {
  296. return [
  297. {
  298. isError: true,
  299. name: 'command1'
  300. }
  301. ];
  302. });
  303. expect(controller.resumeSavedCommands()).to.be.true;
  304. expect(controller.get('commands').mapProperty('name')).to.eql(['command1']);
  305. expect(controller.addObserverToCommands.calledOnce).to.be.true;
  306. });
  307. it('Command in progress', function () {
  308. sinon.stub(App.db, 'getSecurityDeployCommands', function () {
  309. return [
  310. {
  311. isStarted: true,
  312. isCompleted: false,
  313. name: 'command1'
  314. }
  315. ];
  316. });
  317. expect(controller.resumeSavedCommands()).to.be.true;
  318. expect(controller.get('commands').mapProperty('name')).to.eql(['command1']);
  319. expect(controller.get('commands').findProperty('name', 'command1').get('isStarted')).to.be.false;
  320. expect(controller.addObserverToCommands.calledOnce).to.be.true;
  321. expect(controller.moveToNextCommand.calledOnce).to.be.true;
  322. });
  323. it('Command completed', function () {
  324. sinon.stub(App.db, 'getSecurityDeployCommands', function () {
  325. return [
  326. {
  327. isCompleted: true,
  328. name: 'command1'
  329. }
  330. ];
  331. });
  332. expect(controller.resumeSavedCommands()).to.be.true;
  333. expect(controller.get('commands').mapProperty('name')).to.eql(['command1']);
  334. expect(controller.addObserverToCommands.calledOnce).to.be.true;
  335. expect(controller.moveToNextCommand.calledOnce).to.be.true;
  336. });
  337. });
  338. describe('#manageSecureConfigs()', function () {
  339. beforeEach(function () {
  340. sinon.stub(controller, 'setPrincipalValue', Em.K);
  341. });
  342. afterEach(function () {
  343. controller.setPrincipalValue.restore();
  344. });
  345. it('serviceConfigTags is null', function () {
  346. sinon.stub(controller, 'onJsError', Em.K);
  347. controller.set('serviceConfigTags', null);
  348. controller.set('configs', [
  349. {id: 'site property'}
  350. ]);
  351. controller.set('commands', [Em.Object.create({
  352. name: 'APPLY_CONFIGURATIONS'
  353. })]);
  354. expect(controller.manageSecureConfigs()).to.be.false;
  355. expect(controller.onJsError.calledOnce).to.be.true;
  356. expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isSuccess')).to.be.false;
  357. expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isError')).to.be.true;
  358. controller.onJsError.restore();
  359. });
  360. it('Add configs from site-*.xml', function () {
  361. controller.set('serviceConfigTags', [
  362. {
  363. siteName: 'site1',
  364. configs: {}
  365. }
  366. ]);
  367. controller.set('configs', [
  368. {
  369. id: 'site property',
  370. name: 'config1',
  371. value: "value1",
  372. filename: 'site1.xml'
  373. }
  374. ]);
  375. expect(controller.manageSecureConfigs()).to.be.true;
  376. expect(controller.get('serviceConfigTags')[0].configs).to.eql({'config1': 'value1'});
  377. });
  378. it('Add configs from global.xml, config matches "_hosts"', function () {
  379. controller.set('serviceConfigTags', [
  380. {
  381. siteName: 'global',
  382. configs: {}
  383. }
  384. ]);
  385. controller.set('globalProperties', [
  386. {
  387. id: 'site property',
  388. name: 'config1_hosts',
  389. value: "value1",
  390. filename: 'site1.xml'
  391. }
  392. ]);
  393. controller.set('secureConfigs', [
  394. {
  395. serviceName: 'service1',
  396. name: 'config1'
  397. }
  398. ]);
  399. expect(controller.manageSecureConfigs()).to.be.true;
  400. expect(controller.get('serviceConfigTags')[0].configs).to.eql({});
  401. expect(controller.setPrincipalValue.calledWith('service1', 'config1')).to.be.true;
  402. });
  403. });
  404. describe('#deleteComponents()', function () {
  405. it('Send ajax', function () {
  406. sinon.stub(App.ajax, 'send', Em.K);
  407. controller.deleteComponents('comp1', 'host1');
  408. expect(App.ajax.send.calledOnce).to.be.true;
  409. App.ajax.send.restore();
  410. });
  411. });
  412. describe('#onDeleteComplete()', function () {
  413. it('', function () {
  414. controller.set('commands', [Em.Object.create({
  415. name: 'DELETE_ATS'
  416. })]);
  417. controller.onDeleteComplete();
  418. expect(controller.get('commands').findProperty('name', 'DELETE_ATS').get('isError')).to.be.false;
  419. expect(controller.get('commands').findProperty('name', 'DELETE_ATS').get('isSuccess')).to.be.true;
  420. });
  421. });
  422. describe('#onJsError()', function () {
  423. it('Show popup', function () {
  424. sinon.stub(App.ModalPopup, 'show', Em.K);
  425. controller.onJsError();
  426. expect(App.ModalPopup.show.calledOnce).to.be.true;
  427. App.ModalPopup.show.restore();
  428. });
  429. });
  430. });