addSecurity_controller_test.js 8.9 KB

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