disable_test.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. App.router = Em.Object.create({
  141. backgroundOperationsController: Em.Object.create({
  142. services: []
  143. })
  144. });
  145. it('No background operations', function () {
  146. controller.set('commands', [Em.Object.create({
  147. name: 'STOP_SERVICES',
  148. requestId: 1
  149. })]);
  150. controller.syncStopServicesCommand.apply(controller);
  151. expect(controller.get('commands').findProperty('name', 'STOP_SERVICES').get('requestId')).to.equal(1);
  152. });
  153. it('background operation is not running', function () {
  154. App.router.set('backgroundOperationsController.services', [
  155. Em.Object.create({
  156. isRunning: false
  157. })
  158. ]);
  159. controller.syncStopServicesCommand.apply(controller);
  160. expect(controller.get('commands').findProperty('name', 'STOP_SERVICES').get('requestId')).to.equal(1);
  161. });
  162. it('background operation is running but not "Stop All Services"', function () {
  163. App.router.set('backgroundOperationsController.services', [
  164. Em.Object.create({
  165. isRunning: true
  166. })
  167. ]);
  168. controller.syncStopServicesCommand.apply(controller);
  169. expect(controller.get('commands').findProperty('name', 'STOP_SERVICES').get('requestId')).to.equal(1);
  170. });
  171. it('"Stop All Services" operation is running', function () {
  172. App.router.set('backgroundOperationsController.services', [
  173. Em.Object.create({
  174. name: 'Stop All Services',
  175. isRunning: true,
  176. id: 2
  177. })
  178. ]);
  179. controller.syncStopServicesCommand.apply(controller);
  180. expect(controller.get('commands').findProperty('name', 'STOP_SERVICES').get('requestId')).to.equal(2);
  181. });
  182. });
  183. describe('#manageSecureConfigs()', function () {
  184. beforeEach(function () {
  185. sinon.spy(controller, "deleteDisabledGlobalConfigs");
  186. sinon.stub(controller, "modifySiteConfigs", Em.K);
  187. });
  188. afterEach(function () {
  189. controller.deleteDisabledGlobalConfigs.restore();
  190. controller.modifySiteConfigs.restore();
  191. });
  192. var testCases = [
  193. {
  194. title: 'serviceConfigTags, secureProperties, secureMapping are null',
  195. content: {
  196. serviceConfigTags: null,
  197. secureProperties: null,
  198. secureMapping: null
  199. }
  200. },
  201. {
  202. title: 'serviceConfigTags is null',
  203. content: {
  204. serviceConfigTags: null,
  205. secureProperties: [],
  206. secureMapping: []
  207. }
  208. },
  209. {
  210. title: 'secureProperties is null',
  211. content: {
  212. serviceConfigTags: [],
  213. secureProperties: null,
  214. secureMapping: []
  215. }
  216. },
  217. {
  218. title: 'secureMapping is null',
  219. content: {
  220. serviceConfigTags: [],
  221. secureProperties: [],
  222. secureMapping: null
  223. }
  224. }
  225. ];
  226. testCases.forEach(function (test) {
  227. it(test.title, function () {
  228. controller.set('commands', [Em.Object.create({
  229. name: 'APPLY_CONFIGURATIONS'
  230. })]);
  231. controller.set('serviceConfigTags', test.content.serviceConfigTags);
  232. controller.set('secureProperties', test.content.secureProperties);
  233. controller.set('secureMapping', test.content.secureMapping);
  234. expect(controller.manageSecureConfigs()).to.be.false;
  235. expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isSuccess')).to.be.false;
  236. expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isError')).to.be.true;
  237. });
  238. });
  239. it('serviceConfigTags is empty', function () {
  240. controller.set('serviceConfigTags', []);
  241. controller.set('secureProperties', []);
  242. controller.set('secureMapping', []);
  243. expect(controller.manageSecureConfigs()).to.be.true;
  244. });
  245. it('serviceConfigTags has global site', function () {
  246. controller.set('serviceConfigTags', [
  247. {
  248. siteName: 'global',
  249. configs: {}
  250. }
  251. ]);
  252. expect(controller.manageSecureConfigs()).to.be.true;
  253. expect(controller.deleteDisabledGlobalConfigs.calledOnce).to.be.true;
  254. expect(controller.get('serviceConfigTags').findProperty('siteName', 'global').configs.security_enabled).to.equal('false');
  255. });
  256. it('serviceConfigTags has site.xml', function () {
  257. controller.set('serviceConfigTags', [
  258. {
  259. siteName: 'site'
  260. }
  261. ]);
  262. expect(controller.manageSecureConfigs()).to.be.true;
  263. expect(controller.modifySiteConfigs.calledOnce).to.be.true;
  264. });
  265. });
  266. describe('#deleteDisabledGlobalConfigs()', function () {
  267. var testCases = [
  268. {
  269. title: '_serviceConfigTags and secureProperties are null',
  270. content: {
  271. secureProperties: null,
  272. _serviceConfigTags: null
  273. },
  274. result: false
  275. },
  276. {
  277. title: '_serviceConfigTags is null',
  278. content: {
  279. secureProperties: [],
  280. _serviceConfigTags: null
  281. },
  282. result: false
  283. },
  284. {
  285. title: 'secureProperties is null',
  286. content: {
  287. secureProperties: null,
  288. _serviceConfigTags: {}
  289. },
  290. result: false
  291. },
  292. {
  293. title: 'secureProperties and _serviceConfigTags are empty',
  294. content: {
  295. secureProperties: [],
  296. _serviceConfigTags: {}
  297. },
  298. result: true
  299. }
  300. ];
  301. testCases.forEach(function (test) {
  302. it(test.title, function () {
  303. expect(controller.deleteDisabledGlobalConfigs(test.content.secureProperties, test.content._serviceConfigTags)).to.equal(test.result);
  304. });
  305. });
  306. it('_serviceConfigTags doesn\'t contain secureProperties', function () {
  307. var secureProperties = [
  308. {name: 'config1'}
  309. ];
  310. var _serviceConfigTags = {
  311. configs: {
  312. 'config2': true
  313. }
  314. };
  315. expect(controller.deleteDisabledGlobalConfigs(secureProperties, _serviceConfigTags)).to.be.true;
  316. expect(_serviceConfigTags.configs.config2).to.be.true;
  317. });
  318. it('_serviceConfigTags contains secureProperties', function () {
  319. var secureProperties = [
  320. {name: 'config1'}
  321. ];
  322. var _serviceConfigTags = {
  323. configs: {
  324. 'config1': true
  325. }
  326. };
  327. expect(controller.deleteDisabledGlobalConfigs(secureProperties, _serviceConfigTags)).to.be.true;
  328. expect(_serviceConfigTags.configs.config1).to.be.undefined;
  329. });
  330. });
  331. describe('#modifySiteConfigs()', function () {
  332. var testCases = [
  333. {
  334. title: '_serviceConfigTags and secureMapping are null',
  335. content: {
  336. secureMapping: null,
  337. _serviceConfigTags: null
  338. },
  339. result: false
  340. },
  341. {
  342. title: '_serviceConfigTags is null',
  343. content: {
  344. secureMapping: [],
  345. _serviceConfigTags: null
  346. },
  347. result: false
  348. },
  349. {
  350. title: 'secureMapping is null',
  351. content: {
  352. secureMapping: null,
  353. _serviceConfigTags: {}
  354. },
  355. result: false
  356. },
  357. {
  358. title: 'secureMapping and _serviceConfigTags are empty',
  359. content: {
  360. secureMapping: [],
  361. _serviceConfigTags: {
  362. configs: {}
  363. }
  364. },
  365. result: true
  366. }
  367. ];
  368. testCases.forEach(function (test) {
  369. it(test.title, function () {
  370. expect(controller.modifySiteConfigs(test.content.secureMapping, test.content._serviceConfigTags)).to.equal(test.result);
  371. });
  372. });
  373. it('secureMapping doesn\'t contain passed siteName', function () {
  374. var secureMapping = [];
  375. var _serviceConfigTags = {
  376. configs: {
  377. 'config2': true
  378. },
  379. siteName: 'site1'
  380. };
  381. expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true;
  382. expect(_serviceConfigTags.configs.config2).to.be.true;
  383. });
  384. it('secureMapping contain passed siteName but doesn\'t match config name', function () {
  385. var secureMapping = [
  386. {
  387. filename: 'site1.xml'
  388. }
  389. ];
  390. var _serviceConfigTags = {
  391. configs: {
  392. 'config2': true
  393. },
  394. siteName: 'site1'
  395. };
  396. expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true;
  397. expect(_serviceConfigTags.configs.config2).to.be.true;
  398. });
  399. it('secureMapping contain passed siteName and match config name', function () {
  400. var secureMapping = [
  401. {
  402. filename: 'site1.xml',
  403. name: 'config2'
  404. }
  405. ];
  406. var _serviceConfigTags = {
  407. configs: {
  408. 'config2': true
  409. },
  410. siteName: 'site1'
  411. };
  412. expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true;
  413. expect(_serviceConfigTags.configs.config2).to.be.undefined;
  414. });
  415. it('secureMapping contain passed siteName and included in secureConfigValuesMap', function () {
  416. var secureMapping = [
  417. {
  418. filename: 'site1.xml',
  419. name: 'config2',
  420. nonSecureValue: 'nonSecureValue'
  421. }
  422. ];
  423. var _serviceConfigTags = {
  424. configs: {
  425. 'config2': true
  426. },
  427. siteName: 'site1'
  428. };
  429. controller.set('secureConfigValuesMap', {
  430. 'config2': 'value'
  431. });
  432. expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true;
  433. expect(_serviceConfigTags.configs.config2).to.equal('nonSecureValue');
  434. });
  435. });
  436. });