disable_test.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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.stub(controller, "modifySiteConfigs", Em.K);
  181. });
  182. afterEach(function () {
  183. controller.modifySiteConfigs.restore();
  184. });
  185. var testCases = [
  186. {
  187. title: 'serviceConfigTags, secureProperties, secureMapping are null',
  188. content: {
  189. serviceConfigTags: null,
  190. secureProperties: null,
  191. secureMapping: null
  192. }
  193. },
  194. {
  195. title: 'serviceConfigTags is null',
  196. content: {
  197. serviceConfigTags: null,
  198. secureProperties: [],
  199. secureMapping: []
  200. }
  201. },
  202. {
  203. title: 'secureProperties is null',
  204. content: {
  205. serviceConfigTags: [],
  206. secureProperties: null,
  207. secureMapping: []
  208. }
  209. },
  210. {
  211. title: 'secureMapping is null',
  212. content: {
  213. serviceConfigTags: [],
  214. secureProperties: [],
  215. secureMapping: null
  216. }
  217. }
  218. ];
  219. testCases.forEach(function (test) {
  220. it(test.title, function () {
  221. controller.set('commands', [Em.Object.create({
  222. name: 'APPLY_CONFIGURATIONS'
  223. })]);
  224. controller.set('serviceConfigTags', test.content.serviceConfigTags);
  225. controller.set('secureProperties', test.content.secureProperties);
  226. controller.set('secureMapping', test.content.secureMapping);
  227. expect(controller.manageSecureConfigs()).to.be.false;
  228. expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isSuccess')).to.be.false;
  229. expect(controller.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS').get('isError')).to.be.true;
  230. });
  231. });
  232. it('serviceConfigTags is empty', function () {
  233. controller.set('serviceConfigTags', []);
  234. controller.set('secureProperties', []);
  235. controller.set('secureMapping', []);
  236. expect(controller.manageSecureConfigs()).to.be.true;
  237. });
  238. it('serviceConfigTags has cluster-env site', function () {
  239. controller.set('serviceConfigTags', [
  240. {
  241. siteName: 'cluster-env',
  242. configs: {}
  243. }
  244. ]);
  245. expect(controller.manageSecureConfigs()).to.be.true;
  246. expect(controller.get('serviceConfigTags').findProperty('siteName', 'cluster-env').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('#modifySiteConfigs()', function () {
  259. var testCases = [
  260. {
  261. title: '_serviceConfigTags and secureMapping are null',
  262. content: {
  263. secureMapping: null,
  264. _serviceConfigTags: null
  265. },
  266. result: false
  267. },
  268. {
  269. title: '_serviceConfigTags is null',
  270. content: {
  271. secureMapping: [],
  272. _serviceConfigTags: null
  273. },
  274. result: false
  275. },
  276. {
  277. title: 'secureMapping is null',
  278. content: {
  279. secureMapping: null,
  280. _serviceConfigTags: {}
  281. },
  282. result: false
  283. },
  284. {
  285. title: 'secureMapping and _serviceConfigTags are empty',
  286. content: {
  287. secureMapping: [],
  288. _serviceConfigTags: {
  289. configs: {}
  290. }
  291. },
  292. result: true
  293. }
  294. ];
  295. testCases.forEach(function (test) {
  296. it(test.title, function () {
  297. expect(controller.modifySiteConfigs(test.content.secureMapping, test.content._serviceConfigTags)).to.equal(test.result);
  298. });
  299. });
  300. it('secureMapping doesn\'t contain passed siteName', function () {
  301. var secureMapping = [];
  302. var _serviceConfigTags = {
  303. configs: {
  304. 'config2': true
  305. },
  306. siteName: 'site1'
  307. };
  308. expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true;
  309. expect(_serviceConfigTags.configs.config2).to.be.true;
  310. });
  311. it('secureMapping contain passed siteName but doesn\'t match config name', function () {
  312. var secureMapping = [
  313. {
  314. filename: 'site1.xml'
  315. }
  316. ];
  317. var _serviceConfigTags = {
  318. configs: {
  319. 'config2': true
  320. },
  321. siteName: 'site1'
  322. };
  323. expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true;
  324. expect(_serviceConfigTags.configs.config2).to.be.true;
  325. });
  326. it('secureMapping contain passed siteName and match config name', function () {
  327. var secureMapping = [
  328. {
  329. filename: 'site1.xml',
  330. name: 'config2'
  331. }
  332. ];
  333. var _serviceConfigTags = {
  334. configs: {
  335. 'config2': true
  336. },
  337. siteName: 'site1'
  338. };
  339. expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true;
  340. expect(_serviceConfigTags.configs.config2).to.be.undefined;
  341. });
  342. it('secureMapping contain passed siteName and included in secureConfigValuesMap', function () {
  343. var secureMapping = [
  344. {
  345. filename: 'site1.xml',
  346. name: 'config2',
  347. nonSecureValue: 'nonSecureValue'
  348. }
  349. ];
  350. var _serviceConfigTags = {
  351. configs: {
  352. 'config2': true
  353. },
  354. siteName: 'site1'
  355. };
  356. controller.set('secureConfigValuesMap', {
  357. 'config2': 'value'
  358. });
  359. expect(controller.modifySiteConfigs(secureMapping, _serviceConfigTags)).to.be.true;
  360. expect(_serviceConfigTags.configs.config2).to.equal('nonSecureValue');
  361. });
  362. });
  363. });