step4_controller_test.js 13 KB

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