step4_controller_test.js 13 KB

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