step4_controller_test.js 12 KB

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