kerberos_test.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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.MainAdminKerberosController', function() {
  20. var controller = App.MainAdminKerberosController.create({});
  21. describe('#prepareConfigProperties', function() {
  22. beforeEach(function() {
  23. sinon.stub(App.Service, 'find').returns([
  24. Em.Object.create({ serviceName: 'KERBEROS'}),
  25. Em.Object.create({ serviceName: 'HDFS' })
  26. ]);
  27. this.result = controller.prepareConfigProperties([
  28. Em.Object.create({ name: 'prop1', isEditable: true, serviceName: 'SERVICE1'}),
  29. Em.Object.create({ name: 'prop2', isEditable: true, serviceName: 'KERBEROS'}),
  30. Em.Object.create({ name: 'prop3', isEditable: true, serviceName: 'HDFS'}),
  31. Em.Object.create({ name: 'prop4', isEditable: true, serviceName: 'Cluster'}),
  32. Em.Object.create({ name: 'prop5', isEditable: true, serviceName: 'SERVICE1'}),
  33. ]);
  34. });
  35. afterEach(function() {
  36. App.Service.find.restore();
  37. });
  38. ['prop1', 'prop5'].forEach(function(item) {
  39. it('property `{0}` should be absent'.format(item), function() {
  40. expect(this.result.findProperty('name', item)).to.be.undefined;
  41. });
  42. });
  43. ['prop2', 'prop3', 'prop4'].forEach(function(item) {
  44. it('property `{0}` should be present and not editable'.format(item), function() {
  45. var prop = this.result.findProperty('name', item);
  46. expect(prop).to.be.ok;
  47. expect(prop.get('isEditable')).to.be.false;
  48. });
  49. });
  50. it('should take displayType from predefinedSiteProperties', function () {
  51. sinon.stub(App.config, 'get').withArgs('preDefinedSiteProperties').returns([
  52. {
  53. name: 'hadoop.security.auth_to_local',
  54. displayType: 'multiLine'
  55. }
  56. ]);
  57. expect(controller.prepareConfigProperties([
  58. Em.Object.create({
  59. name: 'hadoop.security.auth_to_local',
  60. serviceName: 'HDFS'
  61. })
  62. ])[0].get('displayType')).to.equal('multiLine');
  63. App.config.get.restore();
  64. });
  65. });
  66. describe("#runSecurityCheckSuccess()", function () {
  67. beforeEach(function () {
  68. sinon.stub(App, 'showClusterCheckPopup', Em.K);
  69. sinon.stub(controller, 'startKerberosWizard', Em.K);
  70. });
  71. afterEach(function () {
  72. App.showClusterCheckPopup.restore();
  73. controller.startKerberosWizard.restore();
  74. });
  75. it("shows popup", function () {
  76. var check = { items: [{
  77. UpgradeChecks: {
  78. "check": "Work-preserving RM/NM restart is enabled in YARN configs",
  79. "status": "FAIL",
  80. "reason": "FAIL",
  81. "failed_on": [],
  82. "check_type": "SERVICE"
  83. }
  84. }]};
  85. controller.runSecurityCheckSuccess(check,null,{label: "name"});
  86. expect(controller.startKerberosWizard.called).to.be.false;
  87. expect(App.showClusterCheckPopup.called).to.be.true;
  88. });
  89. it("runs startKerberosWizard", function () {
  90. var check = { items: [{
  91. UpgradeChecks: {
  92. "check": "Work-preserving RM/NM restart is enabled in YARN configs",
  93. "status": "PASS",
  94. "reason": "OK",
  95. "failed_on": [],
  96. "check_type": "SERVICE"
  97. }
  98. }]};
  99. controller.runSecurityCheckSuccess(check,null,{label: "name"});
  100. expect(controller.startKerberosWizard.called).to.be.true;
  101. expect(App.showClusterCheckPopup.called).to.be.false;
  102. });
  103. });
  104. describe('#regenerateKeytabs()', function () {
  105. beforeEach(function () {
  106. sinon.spy(App.ModalPopup, "show");
  107. sinon.stub(App.ajax, 'send', Em.K);
  108. sinon.spy(controller, 'restartServicesAfterRegenerate');
  109. sinon.spy(controller, 'restartAllServices');
  110. });
  111. afterEach(function () {
  112. App.ModalPopup.show.restore();
  113. App.ajax.send.restore();
  114. controller.restartServicesAfterRegenerate.restore();
  115. controller.restartAllServices.restore();
  116. });
  117. it('both confirmation popups should be displayed', function () {
  118. var popup = controller.regenerateKeytabs();
  119. expect(App.ModalPopup.show.calledOnce).to.be.true;
  120. popup.onPrimary();
  121. expect(controller.restartServicesAfterRegenerate.calledOnce).to.be.true;
  122. expect(App.ModalPopup.show.calledTwice).to.be.true;
  123. });
  124. it('user checked regeneration only for missing host/components', function () {
  125. var popup = controller.regenerateKeytabs();
  126. popup.set('regenerateKeytabsOnlyForMissing', true);
  127. var popup2 = popup.onPrimary();
  128. popup2.set('restartComponents', true)
  129. popup2.onPrimary();
  130. expect(App.ajax.send.args[0][0].data.type).to.equal('missing');
  131. });
  132. it('user didn\'t check regeneration only for missing host/components', function () {
  133. var popup = controller.regenerateKeytabs();
  134. popup.set('regenerateKeytabsOnlyForMissing', false);
  135. var popup2 = popup.onPrimary();
  136. popup2.set('restartComponents', true)
  137. popup2.onPrimary();
  138. expect(App.ajax.send.args[0][0].data.type).to.equal('all');
  139. });
  140. it('user checked restart services automatically', function () {
  141. var popup = controller.regenerateKeytabs();
  142. popup.set('regenerateKeytabsOnlyForMissing', true);
  143. var popup2 = popup.onPrimary();
  144. popup2.set('restartComponents', true)
  145. popup2.onPrimary();
  146. expect(App.ajax.send.args[0][0].data.withAutoRestart).to.be.true;
  147. });
  148. it('user didn\'t check restart services automatically', function () {
  149. var popup = controller.regenerateKeytabs();
  150. popup.set('regenerateKeytabsOnlyForMissing', true);
  151. var popup2 = popup.onPrimary();
  152. popup2.set('restartComponents', false)
  153. popup2.onPrimary();
  154. expect(App.ajax.send.args[0][0].data.withAutoRestart).to.be.false;
  155. });
  156. });
  157. describe('#getSecurityTypeSuccess', function() {
  158. var tests = [
  159. {
  160. data: { },
  161. e: 'none'
  162. },
  163. {
  164. data: {
  165. items: []
  166. },
  167. e: 'none'
  168. },
  169. {
  170. data: {
  171. items: [
  172. {
  173. configurations: []
  174. }
  175. ]
  176. },
  177. e: 'none'
  178. },
  179. {
  180. data: {
  181. items: [
  182. {
  183. configurations: [
  184. {
  185. type: 'krb-conf',
  186. properties: {
  187. 'kdc_type': 'mit'
  188. }
  189. }
  190. ]
  191. }
  192. ]
  193. },
  194. e: 'none'
  195. },
  196. {
  197. data: {
  198. items: [
  199. {
  200. configurations: [
  201. {
  202. type: 'kerberos-env',
  203. properties: {
  204. 'kdc_type': 'mit'
  205. }
  206. }
  207. ]
  208. }
  209. ]
  210. },
  211. e: 'mit'
  212. },
  213. {
  214. data: {
  215. items: [
  216. {
  217. configurations: [
  218. {
  219. type: 'kerberos-env',
  220. properties: {
  221. 'kdc_type': 'none'
  222. }
  223. }
  224. ]
  225. }
  226. ]
  227. },
  228. e: 'none'
  229. }
  230. ].forEach(function(test) {
  231. it('json is ' + JSON.stringify(test.data) + ' kdc type should be ' + test.e, function() {
  232. controller.set('isManualKerberos', undefined);
  233. controller.getSecurityTypeSuccess(test.data, {}, {});
  234. expect(controller.get('kdc_type')).to.eql(test.e);
  235. });
  236. });
  237. });
  238. });