disable_test.js 13 KB

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