disable_test.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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/disable');
  20. describe('App.MainAdminSecurityDisableController', function () {
  21. var controller = App.MainAdminSecurityDisableController.create({
  22. serviceConfigTags: null,
  23. secureProperties: null,
  24. secureMapping: null
  25. });
  26. describe('#resumeCommands()', function () {
  27. var context = {
  28. getSecurityDeployCommands: function () {
  29. return this.testData;
  30. }
  31. };
  32. var mock = {
  33. setStepsEnable: Em.K,
  34. setLowerStepsDisable: Em.K
  35. };
  36. beforeEach(function () {
  37. sinon.stub(App.db, "getSecurityDeployCommands", context.getSecurityDeployCommands);
  38. sinon.stub(App.router, 'get', function () {
  39. return mock;
  40. });
  41. });
  42. afterEach(function () {
  43. App.db.getSecurityDeployCommands.restore();
  44. App.router.get.restore();
  45. });
  46. it('commands are absent in local storage', function () {
  47. App.db.testData = null;
  48. expect(controller.resumeCommands()).to.be.false;
  49. });
  50. it('zero commands in local storage', function () {
  51. App.db.testData = [];
  52. expect(controller.resumeCommands()).to.be.false;
  53. });
  54. it('one command is present', function () {
  55. App.db.testData = [
  56. {
  57. name: 'command1'
  58. }
  59. ];
  60. controller.get('commands').clear();
  61. expect(controller.resumeCommands()).to.be.true;
  62. expect(controller.get('commands').mapProperty('name')).to.eql(['command1']);
  63. });
  64. it('command is started and completed', function () {
  65. App.db.testData = [
  66. {
  67. name: 'command1',
  68. isStarted: true,
  69. isCompleted: true
  70. }
  71. ];
  72. controller.get('commands').clear();
  73. expect(controller.resumeCommands()).to.be.true;
  74. expect(controller.get('commands').mapProperty('name')).to.eql(['command1']);
  75. expect(controller.get('commands').findProperty('name', 'command1').get('isStarted')).to.be.true;
  76. });
  77. it('command is started but not completed', function () {
  78. App.db.testData = [
  79. {
  80. name: 'command1',
  81. isStarted: true,
  82. isCompleted: false
  83. }
  84. ];
  85. controller.get('commands').clear();
  86. expect(controller.resumeCommands()).to.be.true;
  87. expect(controller.get('commands').mapProperty('name')).to.eql(['command1']);
  88. expect(controller.get('commands').findProperty('name', 'command1').get('isStarted')).to.be.false;
  89. });
  90. });
  91. describe('#isSubmitDisabled', function () {
  92. var testCases = [
  93. {
  94. title: 'commands is empty',
  95. commands: [],
  96. result: false
  97. },
  98. {
  99. title: 'one started command',
  100. commands: [Em.Object.create({
  101. isStarted: true
  102. })],
  103. result: true
  104. },
  105. {
  106. title: 'one failed command',
  107. commands: [Em.Object.create({
  108. isError: true
  109. })],
  110. result: false
  111. },
  112. {
  113. title: 'one success command',
  114. commands: [Em.Object.create({
  115. isSuccess: true
  116. })],
  117. result: false
  118. },
  119. {
  120. title: 'not all commands are success',
  121. commands: [
  122. Em.Object.create({
  123. isSuccess: true
  124. }),
  125. Em.Object.create({
  126. isSuccess: false
  127. })
  128. ],
  129. result: true
  130. }
  131. ];
  132. testCases.forEach(function (test) {
  133. it(test.title, function () {
  134. controller.set('commands', test.commands);
  135. expect(controller.get('isSubmitDisabled')).to.equal(test.result);
  136. });
  137. });
  138. });
  139. describe('#syncStopServicesCommand()', function () {
  140. it('No background operations', function () {
  141. controller.set('commands', [Em.Object.create({
  142. name: 'STOP_SERVICES',
  143. requestId: 1
  144. })]);
  145. controller.syncStopServicesCommand.apply(controller);
  146. expect(controller.get('commands').findProperty('name', 'STOP_SERVICES').get('requestId')).to.equal(1);
  147. });
  148. it('background operation is not running', function () {
  149. App.router.set('backgroundOperationsController.services', [
  150. Em.Object.create({
  151. isRunning: false
  152. })
  153. ]);
  154. controller.syncStopServicesCommand.apply(controller);
  155. expect(controller.get('commands').findProperty('name', 'STOP_SERVICES').get('requestId')).to.equal(1);
  156. });
  157. it('background operation is running but not "Stop All Services"', function () {
  158. App.router.set('backgroundOperationsController.services', [
  159. Em.Object.create({
  160. isRunning: true
  161. })
  162. ]);
  163. controller.syncStopServicesCommand.apply(controller);
  164. expect(controller.get('commands').findProperty('name', 'STOP_SERVICES').get('requestId')).to.equal(1);
  165. });
  166. it('"Stop All Services" operation is running', function () {
  167. App.router.set('backgroundOperationsController.services', [
  168. Em.Object.create({
  169. name: 'Stop All Services',
  170. isRunning: true,
  171. id: 2
  172. })
  173. ]);
  174. controller.syncStopServicesCommand.apply(controller);
  175. expect(controller.get('commands').findProperty('name', 'STOP_SERVICES').get('requestId')).to.equal(2);
  176. });
  177. });
  178. describe('#manageSecureConfigs()', function () {
  179. beforeEach(function () {
  180. sinon.spy(controller, "deleteDisabledGlobalConfigs");
  181. sinon.stub(controller, "modifySiteConfigs", Em.K);
  182. });
  183. afterEach(function () {
  184. controller.deleteDisabledGlobalConfigs.restore();
  185. controller.modifySiteConfigs.restore();
  186. });
  187. var testCases = [
  188. {
  189. title: 'serviceConfigTags, secureProperties, secureMapping are null',
  190. content: {
  191. serviceConfigTags: null,
  192. secureProperties: null,
  193. secureMapping: null
  194. }
  195. },
  196. {
  197. title: 'serviceConfigTags is null',
  198. content: {
  199. serviceConfigTags: null,
  200. secureProperties: [],
  201. secureMapping: []
  202. }
  203. },
  204. {
  205. title: 'secureProperties is null',
  206. content: {
  207. serviceConfigTags: [],
  208. secureProperties: null,
  209. secureMapping: []
  210. }
  211. },
  212. {
  213. title: 'secureMapping is null',
  214. content: {
  215. serviceConfigTags: [],
  216. secureProperties: [],
  217. secureMapping: null
  218. }
  219. }
  220. ];
  221. testCases.forEach(function (test) {
  222. it(test.title, function () {
  223. controller.set('commands', [Em.Object.create({
  224. name: 'APPLY_CONFIGURATIONS'
  225. })]);
  226. controller.set('serviceConfigTags', test.content.serviceConfigTags);
  227. controller.set('secureProperties', test.content.secureProperties);
  228. controller.set('secureMapping', test.content.secureMapping);
  229. expect(controller.manageSecureConfigs()).to.be.false;
  230. expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isSuccess')).to.be.false;
  231. expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isError')).to.be.true;
  232. });
  233. });
  234. it('serviceConfigTags is empty', function () {
  235. controller.set('serviceConfigTags', []);
  236. controller.set('secureProperties', []);
  237. controller.set('secureMapping', []);
  238. expect(controller.manageSecureConfigs()).to.be.true;
  239. });
  240. it('serviceConfigTags has hadoop-env site', function () {
  241. controller.set('serviceConfigTags', [
  242. {
  243. siteName: 'hadoop-env',
  244. configs: {}
  245. }
  246. ]);
  247. expect(controller.manageSecureConfigs()).to.be.true;
  248. expect(controller.deleteDisabledGlobalConfigs.calledOnce).to.be.true;
  249. expect(controller.get('serviceConfigTags').findProperty('siteName', 'hadoop-env').configs.security_enabled).to.equal('false');
  250. });
  251. it('serviceConfigTags has site.xml', function () {
  252. controller.set('serviceConfigTags', [
  253. {
  254. siteName: 'site'
  255. }
  256. ]);
  257. expect(controller.manageSecureConfigs()).to.be.true;
  258. expect(controller.modifySiteConfigs.calledOnce).to.be.true;
  259. });
  260. });
  261. describe('#deleteDisabledGlobalConfigs()', function () {
  262. var testCases = [
  263. {
  264. title: '_serviceConfigTags and secureProperties are null',
  265. content: {
  266. secureProperties: null,
  267. _serviceConfigTags: null
  268. },
  269. result: false
  270. },
  271. {
  272. title: '_serviceConfigTags is null',
  273. content: {
  274. secureProperties: [],
  275. _serviceConfigTags: null
  276. },
  277. result: false
  278. },
  279. {
  280. title: 'secureProperties is null',
  281. content: {
  282. secureProperties: null,
  283. _serviceConfigTags: {}
  284. },
  285. result: false
  286. },
  287. {
  288. title: 'secureProperties and _serviceConfigTags are empty',
  289. content: {
  290. secureProperties: [],
  291. _serviceConfigTags: {}
  292. },
  293. result: true
  294. }
  295. ];
  296. testCases.forEach(function (test) {
  297. it(test.title, function () {
  298. expect(controller.deleteDisabledGlobalConfigs(test.content.secureProperties, test.content._serviceConfigTags)).to.equal(test.result);
  299. });
  300. });
  301. it('_serviceConfigTags doesn\'t contain secureProperties', function () {
  302. var secureProperties = [
  303. {name: 'config1'}
  304. ];
  305. var _serviceConfigTags = {
  306. configs: {
  307. 'config2': true
  308. }
  309. };
  310. expect(controller.deleteDisabledGlobalConfigs(secureProperties, _serviceConfigTags)).to.be.true;
  311. expect(_serviceConfigTags.configs.config2).to.be.true;
  312. });
  313. it('_serviceConfigTags contains secureProperties', function () {
  314. var secureProperties = [
  315. {name: 'config1'}
  316. ];
  317. var _serviceConfigTags = {
  318. configs: {
  319. 'config1': true
  320. }
  321. };
  322. expect(controller.deleteDisabledGlobalConfigs(secureProperties, _serviceConfigTags)).to.be.true;
  323. expect(_serviceConfigTags.configs.config1).to.be.undefined;
  324. });
  325. });
  326. describe('#modifySiteConfigs()', function () {
  327. var testCases = [
  328. {
  329. title: '_serviceConfigTags and secureMapping are null',
  330. content: {
  331. secureMapping: null,
  332. _serviceConfigTags: null
  333. },
  334. result: false
  335. },
  336. {
  337. title: '_serviceConfigTags is null',
  338. content: {
  339. secureMapping: [],
  340. _serviceConfigTags: null
  341. },
  342. result: false
  343. },
  344. {
  345. title: 'secureMapping is null',
  346. content: {
  347. secureMapping: null,
  348. _serviceConfigTags: {}
  349. },
  350. result: false
  351. },
  352. {
  353. title: 'secureMapping and _serviceConfigTags are empty',
  354. content: {
  355. secureMapping: [],
  356. _serviceConfigTags: {
  357. configs: {}
  358. }
  359. },
  360. result: true
  361. }
  362. ];
  363. testCases.forEach(function (test) {
  364. it(test.title, function () {
  365. expect(controller.modifySiteConfigs(test.content.secureMapping, test.content._serviceConfigTags)).to.equal(test.result);
  366. });
  367. });
  368. it('secureMapping doesn\'t contain passed siteName', function () {
  369. var secureMapping = [];
  370. var _serviceConfigTags = {
  371. configs: {
  372. 'config2': true
  373. },
  374. siteName: 'site1'
  375. };
  376. expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true;
  377. expect(_serviceConfigTags.configs.config2).to.be.true;
  378. });
  379. it('secureMapping contain passed siteName but doesn\'t match config name', function () {
  380. var secureMapping = [
  381. {
  382. filename: 'site1.xml'
  383. }
  384. ];
  385. var _serviceConfigTags = {
  386. configs: {
  387. 'config2': true
  388. },
  389. siteName: 'site1'
  390. };
  391. expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true;
  392. expect(_serviceConfigTags.configs.config2).to.be.true;
  393. });
  394. it('secureMapping contain passed siteName and match config name', function () {
  395. var secureMapping = [
  396. {
  397. filename: 'site1.xml',
  398. name: 'config2'
  399. }
  400. ];
  401. var _serviceConfigTags = {
  402. configs: {
  403. 'config2': true
  404. },
  405. siteName: 'site1'
  406. };
  407. expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true;
  408. expect(_serviceConfigTags.configs.config2).to.be.undefined;
  409. });
  410. it('secureMapping contain passed siteName and included in secureConfigValuesMap', function () {
  411. var secureMapping = [
  412. {
  413. filename: 'site1.xml',
  414. name: 'config2',
  415. nonSecureValue: 'nonSecureValue'
  416. }
  417. ];
  418. var _serviceConfigTags = {
  419. configs: {
  420. 'config2': true
  421. },
  422. siteName: 'site1'
  423. };
  424. controller.set('secureConfigValuesMap', {
  425. 'config2': 'value'
  426. });
  427. expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true;
  428. expect(_serviceConfigTags.configs.config2).to.equal('nonSecureValue');
  429. });
  430. });
  431. });