addSecurity_controller_test.js 8.9 KB

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