addSecurity_controller_test.js 9.0 KB

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