kerberos_test.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. App.TestAliases.testAsComputedEqual(controller, 'isManualKerberos', 'kdc_type', 'none');
  22. App.TestAliases.testAsComputedSomeBy(controller, 'isPropertiesChanged', 'stepConfigs', 'isPropertiesChanged', true);
  23. App.TestAliases.testAsComputedOr(controller, 'isSaveButtonDisabled', ['isSubmitDisabled', '!isPropertiesChanged']);
  24. describe('#prepareConfigProperties', function() {
  25. beforeEach(function() {
  26. sinon.stub(App.Service, 'find').returns([
  27. Em.Object.create({ serviceName: 'KERBEROS'}),
  28. Em.Object.create({ serviceName: 'HDFS' })
  29. ]);
  30. this.result = controller.prepareConfigProperties([
  31. Em.Object.create({ name: 'prop1', isEditable: true, serviceName: 'SERVICE1'}),
  32. Em.Object.create({ name: 'prop2', isEditable: true, serviceName: 'KERBEROS'}),
  33. Em.Object.create({ name: 'prop3', isEditable: true, serviceName: 'HDFS'}),
  34. Em.Object.create({ name: 'prop4', isEditable: true, serviceName: 'Cluster'}),
  35. Em.Object.create({ name: 'prop5', isEditable: true, serviceName: 'SERVICE1'}),
  36. ]);
  37. });
  38. afterEach(function() {
  39. App.Service.find.restore();
  40. });
  41. ['prop1', 'prop5'].forEach(function(item) {
  42. it('property `{0}` should be absent'.format(item), function() {
  43. expect(this.result.findProperty('name', item)).to.be.undefined;
  44. });
  45. });
  46. ['prop2', 'prop3', 'prop4'].forEach(function(item) {
  47. it('property `{0}` should be present and not editable'.format(item), function() {
  48. var prop = this.result.findProperty('name', item);
  49. expect(prop).to.be.ok;
  50. expect(prop.get('isEditable')).to.be.false;
  51. });
  52. });
  53. it('should take displayType from predefinedSiteProperties', function () {
  54. sinon.stub(App.configsCollection, 'getAll').returns([
  55. {
  56. name: 'hadoop.security.auth_to_local',
  57. displayType: 'multiLine'
  58. }
  59. ]);
  60. expect(controller.prepareConfigProperties([
  61. Em.Object.create({
  62. name: 'hadoop.security.auth_to_local',
  63. serviceName: 'HDFS'
  64. })
  65. ])[0].get('displayType')).to.equal('multiLine');
  66. App.configsCollection.getAll.restore();
  67. });
  68. });
  69. describe("#runSecurityCheckSuccess()", function () {
  70. beforeEach(function () {
  71. sinon.stub(App, 'showClusterCheckPopup', Em.K);
  72. sinon.stub(controller, 'startKerberosWizard', Em.K);
  73. });
  74. afterEach(function () {
  75. App.showClusterCheckPopup.restore();
  76. controller.startKerberosWizard.restore();
  77. });
  78. it("shows popup", function () {
  79. var check = { items: [{
  80. UpgradeChecks: {
  81. "check": "Work-preserving RM/NM restart is enabled in YARN configs",
  82. "status": "FAIL",
  83. "reason": "FAIL",
  84. "failed_on": [],
  85. "check_type": "SERVICE"
  86. }
  87. }]};
  88. controller.runSecurityCheckSuccess(check,null,{label: "name"});
  89. expect(controller.startKerberosWizard.called).to.be.false;
  90. expect(App.showClusterCheckPopup.called).to.be.true;
  91. });
  92. it("runs startKerberosWizard", function () {
  93. var check = { items: [{
  94. UpgradeChecks: {
  95. "check": "Work-preserving RM/NM restart is enabled in YARN configs",
  96. "status": "PASS",
  97. "reason": "OK",
  98. "failed_on": [],
  99. "check_type": "SERVICE"
  100. }
  101. }]};
  102. controller.runSecurityCheckSuccess(check,null,{label: "name"});
  103. expect(controller.startKerberosWizard.called).to.be.true;
  104. expect(App.showClusterCheckPopup.called).to.be.false;
  105. });
  106. });
  107. describe('#regenerateKeytabs()', function () {
  108. beforeEach(function () {
  109. sinon.spy(App.ModalPopup, "show");
  110. sinon.stub(App.ajax, 'send', Em.K);
  111. sinon.spy(controller, 'restartServicesAfterRegenerate');
  112. sinon.spy(controller, 'restartAllServices');
  113. });
  114. afterEach(function () {
  115. App.ModalPopup.show.restore();
  116. App.ajax.send.restore();
  117. controller.restartServicesAfterRegenerate.restore();
  118. controller.restartAllServices.restore();
  119. });
  120. it('both confirmation popups should be displayed', function () {
  121. var popup = controller.regenerateKeytabs();
  122. expect(App.ModalPopup.show.calledOnce).to.be.true;
  123. popup.onPrimary();
  124. expect(controller.restartServicesAfterRegenerate.calledOnce).to.be.true;
  125. expect(App.ModalPopup.show.calledTwice).to.be.true;
  126. });
  127. it('user checked regeneration only for missing host/components', function () {
  128. var popup = controller.regenerateKeytabs();
  129. popup.set('regenerateKeytabsOnlyForMissing', true);
  130. var popup2 = popup.onPrimary();
  131. popup2.set('restartComponents', true)
  132. popup2.onPrimary();
  133. expect(App.ajax.send.args[0][0].data.type).to.equal('missing');
  134. });
  135. it('user didn\'t check regeneration only for missing host/components', function () {
  136. var popup = controller.regenerateKeytabs();
  137. popup.set('regenerateKeytabsOnlyForMissing', false);
  138. var popup2 = popup.onPrimary();
  139. popup2.set('restartComponents', true)
  140. popup2.onPrimary();
  141. expect(App.ajax.send.args[0][0].data.type).to.equal('all');
  142. });
  143. it('user checked restart services automatically', function () {
  144. var popup = controller.regenerateKeytabs();
  145. popup.set('regenerateKeytabsOnlyForMissing', true);
  146. var popup2 = popup.onPrimary();
  147. popup2.set('restartComponents', true)
  148. popup2.onPrimary();
  149. expect(App.ajax.send.args[0][0].data.withAutoRestart).to.be.true;
  150. });
  151. it('user didn\'t check restart services automatically', function () {
  152. var popup = controller.regenerateKeytabs();
  153. popup.set('regenerateKeytabsOnlyForMissing', true);
  154. var popup2 = popup.onPrimary();
  155. popup2.set('restartComponents', false)
  156. popup2.onPrimary();
  157. expect(App.ajax.send.args[0][0].data.withAutoRestart).to.be.false;
  158. });
  159. });
  160. describe('#getKDCSessionState()', function () {
  161. var mock = {callback: Em.K};
  162. beforeEach(function () {
  163. sinon.stub(App.ajax, 'send', Em.K);
  164. sinon.spy(mock, 'callback');
  165. sinon.stub(controller, 'getSecurityType', function (c) {
  166. c();
  167. });
  168. });
  169. afterEach(function () {
  170. App.ajax.send.restore();
  171. mock.callback.restore();
  172. controller.getSecurityType.restore();
  173. });
  174. [
  175. {
  176. m: 'Skip request, as securityEnabled and isKerberosEnabled are false',
  177. securityEnabled: false,
  178. isKerberosEnabled: false,
  179. kdc_type: 'not_none',
  180. result: false
  181. },
  182. {
  183. m: 'Skip request, as isManualKerberos is true',
  184. securityEnabled: true,
  185. isKerberosEnabled: true,
  186. kdc_type: 'none',
  187. result: false
  188. },
  189. {
  190. m: 'Make request',
  191. securityEnabled: true,
  192. isKerberosEnabled: true,
  193. kdc_type: 'not_none',
  194. result: true
  195. }
  196. ].forEach(function (test) {
  197. it(test.m, function () {
  198. sinon.stub(App, 'get').returns(test.isKerberosEnabled);
  199. controller.set('securityEnabled', test.securityEnabled);
  200. controller.set('kdc_type', test.kdc_type);
  201. controller.getKDCSessionState(mock.callback);
  202. App.get.restore();
  203. if (test.result) {
  204. expect(mock.callback.calledOnce).to.be.false;
  205. expect(App.ajax.send.calledOnce).to.be.true;
  206. } else {
  207. expect(mock.callback.calledOnce).to.be.true;
  208. expect(App.ajax.send.calledOnce).to.be.false;
  209. }
  210. });
  211. });
  212. });
  213. describe('#getSecurityType()', function () {
  214. var mock = {callback: Em.K};
  215. beforeEach(function () {
  216. sinon.stub(App.ajax, 'send', Em.K);
  217. sinon.spy(mock, 'callback');
  218. });
  219. afterEach(function () {
  220. App.ajax.send.restore();
  221. mock.callback.restore();
  222. });
  223. [
  224. {
  225. m: 'Skip request, as securityEnabled and isKerberosEnabled are false',
  226. securityEnabled: false,
  227. isKerberosEnabled: false,
  228. kdc_type: '',
  229. result: false
  230. },
  231. {
  232. m: 'Skip request, as kdc_type exists',
  233. securityEnabled: true,
  234. isKerberosEnabled: true,
  235. kdc_type: 'none',
  236. result: false
  237. },
  238. {
  239. m: 'Make request',
  240. securityEnabled: true,
  241. isKerberosEnabled: true,
  242. kdc_type: '',
  243. result: true
  244. }
  245. ].forEach(function (test) {
  246. it(test.m, function () {
  247. sinon.stub(App, 'get').returns(test.isKerberosEnabled);
  248. controller.set('securityEnabled', test.securityEnabled);
  249. controller.set('kdc_type', test.kdc_type);
  250. controller.getSecurityType(mock.callback);
  251. App.get.restore();
  252. if (test.result) {
  253. expect(mock.callback.calledOnce).to.be.false;
  254. expect(App.ajax.send.calledOnce).to.be.true;
  255. } else {
  256. expect(mock.callback.calledOnce).to.be.true;
  257. expect(App.ajax.send.calledOnce).to.be.false;
  258. }
  259. });
  260. });
  261. });
  262. describe('#getSecurityTypeSuccess', function() {
  263. [
  264. {
  265. data: { },
  266. e: 'none'
  267. },
  268. {
  269. data: {
  270. items: []
  271. },
  272. e: 'none'
  273. },
  274. {
  275. data: {
  276. items: [
  277. {
  278. configurations: []
  279. }
  280. ]
  281. },
  282. e: 'none'
  283. },
  284. {
  285. data: {
  286. items: [
  287. {
  288. configurations: [
  289. {
  290. type: 'krb-conf',
  291. properties: {
  292. 'kdc_type': 'mit'
  293. }
  294. }
  295. ]
  296. }
  297. ]
  298. },
  299. e: 'none'
  300. },
  301. {
  302. data: {
  303. items: [
  304. {
  305. configurations: [
  306. {
  307. type: 'kerberos-env',
  308. properties: {
  309. 'kdc_type': 'mit'
  310. }
  311. }
  312. ]
  313. }
  314. ]
  315. },
  316. e: 'mit'
  317. },
  318. {
  319. data: {
  320. items: [
  321. {
  322. configurations: [
  323. {
  324. type: 'kerberos-env',
  325. properties: {
  326. 'kdc_type': 'none'
  327. }
  328. }
  329. ]
  330. }
  331. ]
  332. },
  333. e: 'none'
  334. }
  335. ].forEach(function(test) {
  336. it('json is ' + JSON.stringify(test.data) + ' kdc type should be ' + test.e, function() {
  337. controller.set('isManualKerberos', undefined);
  338. controller.getSecurityTypeSuccess(test.data, {}, {});
  339. expect(controller.get('kdc_type')).to.eql(test.e);
  340. });
  341. });
  342. });
  343. });