addSecurity_controller_test.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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('mixins/common/localStorage');
  20. require('controllers/wizard');
  21. require('controllers/main/admin/security/add/addSecurity_controller');
  22. require('models/cluster');
  23. require('models/service');
  24. describe('App.AddSecurityController', function () {
  25. var controller = App.AddSecurityController.create({
  26. currentStep: null,
  27. content: Em.Object.create({
  28. isATSInstalled: true,
  29. services: [],
  30. isNnHa: 'false',
  31. serviceConfigProperties: null
  32. })
  33. });
  34. describe('#installedServices', function () {
  35. afterEach(function () {
  36. App.Service.find.restore();
  37. });
  38. it('No installed services', function () {
  39. sinon.stub(App.Service, 'find', function () {
  40. return [];
  41. });
  42. expect(controller.get('installedServices')).to.eql([]);
  43. });
  44. it('One service installed', function () {
  45. sinon.stub(App.Service, 'find', function () {
  46. return [Em.Object.create({serviceName: 'HDFS'})];
  47. });
  48. Em.propertyDidChange(controller, 'installedServices');
  49. expect(controller.get('installedServices')).to.eql(['HDFS']);
  50. });
  51. });
  52. describe('#loadAllPriorSteps()', function () {
  53. beforeEach(function () {
  54. sinon.stub(controller, 'loadServiceConfigs', Em.K);
  55. sinon.stub(controller, 'loadServices', Em.K);
  56. sinon.stub(controller, 'loadNnHaStatus', Em.K);
  57. });
  58. afterEach(function () {
  59. controller.loadServiceConfigs.restore();
  60. controller.loadServices.restore();
  61. controller.loadNnHaStatus.restore();
  62. });
  63. var commonSteps = ['4', '3', '2'];
  64. commonSteps.forEach(function (step) {
  65. it('Current step - ' + step, function () {
  66. controller.set('currentStep', step);
  67. controller.loadAllPriorSteps();
  68. expect(controller.loadServiceConfigs.calledOnce).to.be.true;
  69. expect(controller.loadServices.calledOnce).to.be.true;
  70. expect(controller.loadNnHaStatus.calledOnce).to.be.true;
  71. });
  72. });
  73. it('Current step - 1', function () {
  74. controller.set('currentStep', '1');
  75. controller.loadAllPriorSteps();
  76. expect(controller.loadServiceConfigs.called).to.be.false;
  77. expect(controller.loadServices.calledOnce).to.be.true;
  78. expect(controller.loadNnHaStatus.calledOnce).to.be.true;
  79. });
  80. });
  81. describe('#loadServices()', function () {
  82. it('No installed services', function () {
  83. controller.reopen({
  84. installedServices: [],
  85. secureServices: [
  86. {serviceName: 'GENERAL'}
  87. ]
  88. });
  89. controller.loadServices();
  90. expect(controller.get('content.services').mapProperty('serviceName')).to.eql(['GENERAL']);
  91. });
  92. it('Installed service does not match the secure one', function () {
  93. controller.set('installedServices', ["HDFS"]);
  94. controller.loadServices();
  95. expect(controller.get('content.services').mapProperty('serviceName')).to.eql(['GENERAL']);
  96. });
  97. it('Installed service matches the secure one', function () {
  98. controller.set('secureServices', [
  99. {serviceName: 'GENERAL'},
  100. {serviceName: 'HDFS'}
  101. ]);
  102. controller.loadServices();
  103. expect(controller.get('content.services').mapProperty('serviceName')).to.eql(['GENERAL', 'HDFS']);
  104. });
  105. });
  106. describe('#loadNnHaStatus()', function () {
  107. afterEach(function () {
  108. App.db.getIsNameNodeHa.restore();
  109. });
  110. it('NameNode HA is off', function () {
  111. sinon.stub(App.db, 'getIsNameNodeHa', function () {
  112. return false;
  113. });
  114. controller.loadNnHaStatus();
  115. expect(controller.get('content.isNnHa')).to.be.false;
  116. });
  117. it('NameNode HA is on', function () {
  118. sinon.stub(App.db, 'getIsNameNodeHa', function () {
  119. return true;
  120. });
  121. controller.loadNnHaStatus();
  122. expect(controller.get('content.isNnHa')).to.be.true;
  123. });
  124. });
  125. describe('#loadServiceConfigs()', function () {
  126. afterEach(function () {
  127. App.db.getSecureConfigProperties.restore();
  128. });
  129. it('SecureConfigProperties is empty', function () {
  130. sinon.stub(App.db, 'getSecureConfigProperties', function () {
  131. return [];
  132. });
  133. controller.loadServiceConfigs();
  134. expect(controller.get('content.serviceConfigProperties')).to.eql([]);
  135. });
  136. it('SecureConfigProperties has one config', function () {
  137. sinon.stub(App.db, 'getSecureConfigProperties', function () {
  138. return [{}];
  139. });
  140. controller.loadServiceConfigs();
  141. expect(controller.get('content.serviceConfigProperties')).to.eql([{}]);
  142. });
  143. });
  144. describe('#getConfigOverrides()', function () {
  145. var testCases = [
  146. {
  147. title: 'overrides is null',
  148. configProperty: Em.Object.create({overrides: null}),
  149. result: null
  150. },
  151. {
  152. title: 'overrides is empty',
  153. configProperty: Em.Object.create({overrides: []}),
  154. result: null
  155. },
  156. {
  157. title: 'overrides has one override',
  158. configProperty: Em.Object.create({
  159. overrides: [
  160. Em.Object.create({
  161. value: 'value1',
  162. selectedHostOptions: []
  163. })
  164. ]
  165. }),
  166. result: [{
  167. value: 'value1',
  168. hosts: []
  169. }]
  170. },
  171. {
  172. title: 'overrides has one override with hosts',
  173. configProperty: Em.Object.create({
  174. overrides: [
  175. Em.Object.create({
  176. value: 'value1',
  177. selectedHostOptions: ['host1']
  178. })
  179. ]
  180. }),
  181. result: [{
  182. value: 'value1',
  183. hosts: ['host1']
  184. }]
  185. }
  186. ];
  187. testCases.forEach(function(test){
  188. it(test.title, function () {
  189. expect(controller.getConfigOverrides(test.configProperty)).to.eql(test.result);
  190. });
  191. });
  192. });
  193. describe('#saveServiceConfigProperties()', function () {
  194. var testCases = [
  195. {
  196. title: 'stepConfigs is empty',
  197. stepController: Em.Object.create({
  198. stepConfigs: []
  199. }),
  200. result: []
  201. },
  202. {
  203. title: 'No configs in service',
  204. stepController: Em.Object.create({
  205. stepConfigs: [
  206. Em.Object.create({configs: []})
  207. ]
  208. }),
  209. result: []
  210. }
  211. ];
  212. testCases.forEach(function (test) {
  213. it(test.title, function () {
  214. sinon.stub(App.db, 'setSecureConfigProperties', Em.K);
  215. controller.saveServiceConfigProperties(test.stepController);
  216. expect(App.db.setSecureConfigProperties.calledWith(test.result)).to.be.true;
  217. expect(controller.get('content.serviceConfigProperties')).to.eql(test.result);
  218. App.db.setSecureConfigProperties.restore();
  219. });
  220. });
  221. it('Service has config', function () {
  222. var stepController = Em.Object.create({
  223. stepConfigs: [
  224. Em.Object.create({configs: [
  225. Em.Object.create({
  226. name: 'config1',
  227. value: 'value1'
  228. })
  229. ]})
  230. ]
  231. });
  232. sinon.stub(App.db, 'setSecureConfigProperties', Em.K);
  233. controller.saveServiceConfigProperties(stepController);
  234. expect(App.db.setSecureConfigProperties.calledOnce).to.be.true;
  235. expect(controller.get('content.serviceConfigProperties').mapProperty('name')).to.eql(['config1']);
  236. App.db.setSecureConfigProperties.restore();
  237. });
  238. });
  239. });