kerberos_test.js 11 KB

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