step4_controller_test.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. var c = App.KerberosWizardStep4Controller.create({
  20. wizardController: Em.Object.create({
  21. name: ''
  22. })
  23. });
  24. describe('App.KerberosWizardStep4Controller', function() {
  25. App.TestAliases.testAsComputedEqual(c, 'isWithinAddService', 'wizardController.name', 'addServiceController');
  26. describe('#isSubmitDisabled', function() {
  27. var controller = App.KerberosWizardStep4Controller.create({});
  28. var configs = Em.A([
  29. App.ServiceConfigProperty.create({ name: 'prop1', value: 'someVal1', identityType: 'user', category: 'Ambari Principals', serviceName: 'Cluster'})
  30. ]);
  31. controller.set('stepConfigs', controller.createServiceConfig(configs));
  32. it('configuration errors are absent, submit should be not disabled', function() {
  33. expect(controller.get('stepConfigs')[0].get('errorCount')).to.be.equal(0);
  34. expect(controller.get('isSubmitDisabled')).to.be.false;
  35. });
  36. it('config has invalid value, submit should be disabled', function() {
  37. var serviceConfig = controller.get('stepConfigs')[0];
  38. serviceConfig.get('configs').findProperty('name', 'prop1').set('value', '');
  39. expect(serviceConfig.get('errorCount')).to.be.equal(1);
  40. expect(controller.get('isSubmitDisabled')).to.be.true;
  41. });
  42. });
  43. describe('#createServiceConfig', function() {
  44. var controller = App.KerberosWizardStep4Controller.create({});
  45. it('should create instance of App.ServiceConfig', function() {
  46. var configs = controller.createServiceConfig([], []);
  47. expect(configs).to.have.property('length').equal(2);
  48. expect(configs[0]).to.be.instanceof(App.ServiceConfig);
  49. expect(configs[1]).to.be.instanceof(App.ServiceConfig);
  50. });
  51. });
  52. describe('#prepareConfigProperties', function() {
  53. var properties = Em.A([
  54. Em.Object.create({ name: 'realm', value: '', serviceName: 'Cluster' }),
  55. Em.Object.create({ name: 'spnego_keytab', value: 'spnego_keytab_value', serviceName: 'Cluster' }),
  56. Em.Object.create({ name: 'hdfs_keytab', value: '', serviceName: 'HDFS', identityType: 'user', observesValueFrom: 'spnego_keytab' }),
  57. Em.Object.create({ name: 'falcon_keytab', value: 'falcon_keytab_value', serviceName: 'FALCON' }),
  58. Em.Object.create({ name: 'mapreduce_keytab', value: 'mapreduce_keytab_value', serviceName: 'MAPREDUCE2' }),
  59. Em.Object.create({ name: 'hdfs_principal', value: 'hdfs_principal_value', identityType: 'user', serviceName: 'HDFS' }),
  60. Em.Object.create({ name: 'hadoop.security.auth_to_local', serviceName: 'HDFS' })
  61. ]);
  62. var propertyValidationCases = [
  63. {
  64. property: 'spnego_keytab',
  65. e: [
  66. { key: 'category', value: 'Global' },
  67. { key: 'observesValueFrom', absent: true }
  68. ]
  69. },
  70. {
  71. property: 'realm',
  72. e: [
  73. { key: 'category', value: 'Global' },
  74. { key: 'value', value: 'realm_value' }
  75. ]
  76. },
  77. {
  78. property: 'hdfs_keytab',
  79. e: [
  80. { key: 'category', value: 'Ambari Principals' },
  81. { key: 'value', value: 'spnego_keytab_value' },
  82. { key: 'observesValueFrom', value: 'spnego_keytab' }
  83. ]
  84. },
  85. {
  86. property: 'hadoop.security.auth_to_local',
  87. e: [
  88. { key: 'displayType', value: 'multiLine' }
  89. ]
  90. }
  91. ];
  92. var absentPropertiesTest = ['falcon_keytab', 'mapreduce_keytab'];
  93. before(function() {
  94. var controller = App.KerberosWizardStep4Controller.create({
  95. wizardController: {
  96. getDBProperty: function() {
  97. return Em.A([
  98. Em.Object.create({ name: 'realm', value: 'realm_value' })
  99. ]);
  100. },
  101. loadCachedStepConfigValues: function() {
  102. return null;
  103. }
  104. }
  105. });
  106. sinon.stub(App.Service, 'find').returns(Em.A([
  107. { serviceName: 'HDFS' }
  108. ]));
  109. sinon.stub(App.configsCollection, 'getAll').returns([
  110. {
  111. name: 'hadoop.security.auth_to_local',
  112. displayType: 'multiLine'
  113. }
  114. ]);
  115. sinon.stub(App.router, 'get').withArgs('mainAdminKerberosController.isManualKerberos').returns(false);
  116. this.result = controller.prepareConfigProperties(properties);
  117. });
  118. after(function() {
  119. App.Service.find.restore();
  120. App.configsCollection.getAll.restore();
  121. App.router.get.restore();
  122. });
  123. it('should contains properties only for installed services', function() {
  124. expect(this.result.mapProperty('serviceName').uniq()).to.be.eql(['Cluster', 'HDFS']);
  125. });
  126. absentPropertiesTest.forEach(function(item) {
  127. it('property `{0}` should be absent'.format(item), function() {
  128. expect(this.result.findProperty('name', item)).to.be.undefined;
  129. });
  130. }, this);
  131. propertyValidationCases.forEach(function(test) {
  132. it('property {0} should be created'.format(test.property), function() {
  133. expect(this.result.findProperty('name', test.property)).to.be.ok;
  134. });
  135. test.e.forEach(function(expected) {
  136. it('property `{0}` should have `{1}` with value `{2}`'.format(test.property, expected.key, expected.value), function() {
  137. if (!!expected.absent) {
  138. expect(this.result.findProperty('name', test.property)).to.not.have.deep.property(expected.key);
  139. } else {
  140. expect(this.result.findProperty('name', test.property)).to.have.deep.property(expected.key, expected.value);
  141. }
  142. }, this);
  143. }, this);
  144. });
  145. });
  146. describe('#setStepConfigs', function() {
  147. describe('Add Service Wizard', function() {
  148. var properties = Em.A([
  149. Em.Object.create({ name: 'realm', value: '', serviceName: 'Cluster' }),
  150. Em.Object.create({ name: 'spnego_keytab', value: 'spnego_keytab_value', serviceName: 'Cluster', isEditable: true }),
  151. Em.Object.create({ name: 'hdfs_keytab', value: '', serviceName: 'HDFS', observesValueFrom: 'spnego_keytab', isEditable: true }),
  152. Em.Object.create({ name: 'falcon_keytab', value: 'falcon_keytab_value', serviceName: 'FALCON', isEditable: true }),
  153. Em.Object.create({ name: 'mapreduce_keytab', value: 'mapreduce_keytab_value', serviceName: 'MAPREDUCE2', isEditable: true })
  154. ]);
  155. var res;
  156. var controller;
  157. before(function() {
  158. sinon.stub(App.StackService, 'find').returns([
  159. Em.Object.create({
  160. serviceName: 'KERBEROS',
  161. configCategories: [],
  162. configTypeList: []
  163. }),
  164. Em.Object.create({
  165. serviceName: 'HDFS',
  166. configCategories: [],
  167. configTypeList: []
  168. }),
  169. Em.Object.create({
  170. serviceName: 'MAPREDUCE2',
  171. configTypeList: []
  172. })
  173. ]);
  174. sinon.stub(App.Service, 'find').returns([
  175. Em.Object.create({
  176. serviceName: 'HDFS'
  177. }),
  178. Em.Object.create({
  179. serviceName: 'KERBEROS'
  180. })
  181. ]);
  182. controller = App.KerberosWizardStep4Controller.create({
  183. selectedServiceNames: ['FALCON', 'MAPREDUCE2'],
  184. installedServiceNames: ['HDFS', 'KERBEROS'],
  185. wizardController: Em.Object.create({
  186. name: 'addServiceController',
  187. getDBProperty: function() {
  188. return Em.A([
  189. Em.Object.create({ name: 'realm', value: 'realm_value' })
  190. ]);
  191. },
  192. loadCachedStepConfigValues : function() {
  193. return null;
  194. }
  195. })
  196. });
  197. sinon.stub(App.router, 'get').withArgs('mainAdminKerberosController.isManualKerberos').returns(false);
  198. controller.setStepConfigs(properties);
  199. res = controller.get('stepConfigs')[0].get('configs').concat(controller.get('stepConfigs')[1].get('configs'));
  200. });
  201. Em.A([
  202. { name: 'spnego_keytab', e: false },
  203. { name: 'falcon_keytab', e: true },
  204. { name: 'hdfs_keytab', e: false },
  205. { name: 'mapreduce_keytab', e: true }
  206. ]).forEach(function(test) {
  207. it('Add Service: property `{0}` should be {1} editable'.format(test.name, !!test.e ? '' : 'not '), function() {
  208. expect(res.findProperty('name', test.name).get('isEditable')).to.eql(test.e);
  209. });
  210. });
  211. after(function() {
  212. controller.destroy();
  213. controller = null;
  214. App.StackService.find.restore();
  215. App.Service.find.restore();
  216. App.router.get.restore();
  217. });
  218. });
  219. });
  220. describe("#createCategoryForServices()", function() {
  221. var controller = App.KerberosWizardStep4Controller.create({
  222. wizardController: {
  223. name: 'addServiceController'
  224. }
  225. });
  226. beforeEach(function() {
  227. sinon.stub(App.Service, 'find').returns([
  228. Em.Object.create({
  229. serviceName: 'HDFS',
  230. displayName: 'HDFS'
  231. })
  232. ]);
  233. sinon.stub(App.StackService, 'find').returns([
  234. Em.Object.create({
  235. serviceName: 'HDFS',
  236. displayName: 'HDFS',
  237. isInstalled: true
  238. }),
  239. Em.Object.create({
  240. serviceName: 'MAPREDUCE2',
  241. displayName: 'MapReduce 2',
  242. isInstalled: false,
  243. isSelected: true
  244. })
  245. ]);
  246. });
  247. afterEach(function() {
  248. App.Service.find.restore();
  249. App.StackService.find.restore();
  250. });
  251. it('for add service', function() {
  252. expect(controller.createCategoryForServices()).to.eql([App.ServiceConfigCategory.create({ name: 'HDFS', displayName: 'HDFS', collapsedByDefault: true}),
  253. App.ServiceConfigCategory.create({ name: 'MAPREDUCE2', displayName: 'MapReduce 2', collapsedByDefault: true})]);
  254. });
  255. it('for kerberos wizard', function() {
  256. controller.set('wizardController.name', 'KerberosWizard');
  257. expect(controller.createCategoryForServices()).to.eql([App.ServiceConfigCategory.create({ name: 'HDFS', displayName: 'HDFS', collapsedByDefault: true})]);
  258. });
  259. });
  260. describe('#loadStep', function() {
  261. var controller;
  262. describe('skip "Configure Identities" step. ', function() {
  263. beforeEach(function() {
  264. controller = App.KerberosWizardStep4Controller.create({});
  265. this.wizardController = App.AddServiceController.create({});
  266. controller.set('wizardController', this.wizardController);
  267. sinon.stub(controller, 'clearStep').returns(true);
  268. sinon.stub(controller, 'setStepConfigs').returns(true);
  269. sinon.stub(App.router, 'send').withArgs('next');
  270. });
  271. afterEach(function() {
  272. controller.clearStep.restore();
  273. controller.setStepConfigs.restore();
  274. App.router.send.restore();
  275. });
  276. var tests = [
  277. {
  278. securityEnabled: true,
  279. stepSkipped: false
  280. },
  281. {
  282. securityEnabled: false,
  283. stepSkipped: true
  284. }
  285. ];
  286. tests.forEach(function(test) {
  287. var message = 'Security {0} configure identities step should be {1}'.format(!!test.securityEnabled ? 'enabled' : 'disabled', !!test.stepSkipped ? 'skipped' : 'not skipped');
  288. describe(message, function() {
  289. beforeEach(function () {
  290. sinon.stub(App, 'get').withArgs('isKerberosEnabled').returns(test.securityEnabled);
  291. this.wizardController.checkSecurityStatus();
  292. controller.loadStep();
  293. });
  294. afterEach(function () {
  295. App.get.restore();
  296. });
  297. it('`send` is ' + (test.stepSkipped ? '' : 'not') + ' called with `next`', function () {
  298. expect(App.router.send.calledWith('next')).to.be.eql(test.stepSkipped);
  299. });
  300. });
  301. }, this);
  302. it('step should not be disabled for Add Kerberos wizard', function() {
  303. controller.set('wizardController', App.KerberosWizardController.create({}));
  304. controller.loadStep();
  305. expect(App.router.send.calledWith('next')).to.be.false;
  306. });
  307. });
  308. });
  309. });