step2_controller_test.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  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 setups = require('test/init_model_test');
  20. var testHelpers = require('test/helpers');
  21. function getController() {
  22. return App.KerberosWizardStep2Controller.create({
  23. wizardController: Em.Object.create({
  24. deleteKerberosService: Em.K
  25. }),
  26. controllers: Em.Object.create(),
  27. content: Em.Object.create()
  28. });
  29. }
  30. describe('App.KerberosWizardStep2Controller', function() {
  31. var controller;
  32. beforeEach(function() {
  33. controller = getController();
  34. });
  35. App.TestAliases.testAsComputedAlias(getController(), 'isBackBtnDisabled', 'testConnectionInProgress', 'boolean');
  36. App.TestAliases.testAsComputedAlias(getController(), 'hostNames', 'App.allHostNames', 'array');
  37. App.TestAliases.testAsComputedAlias(getController(), 'isConfigsLoaded', 'wizardController.stackConfigsLoaded', 'boolean');
  38. describe('#createKerberosSiteObj', function() {
  39. beforeEach(function() {
  40. setups.setupStackVersion(this, 'HDP-2.3');
  41. sinon.stub(controller, 'tweakKdcTypeValue', Em.K);
  42. sinon.stub(controller, 'tweakManualKdcProperties', Em.K);
  43. });
  44. after(function() {
  45. setups.restoreStackVersion(this);
  46. controller.tweakKdcTypeValue.restore();
  47. controller.tweakManualKdcProperties.restore();
  48. });
  49. var _createProperty = function(name, value, displayType) {
  50. var preDefProp = App.config.get('preDefinedSiteProperties').findProperty('name', name);
  51. if (preDefProp) {
  52. return App.ServiceConfigProperty.create(
  53. $.extend(true, {}, preDefProp, {
  54. value: value, filename: 'some-site.xml',
  55. 'displayType': displayType,
  56. isRequiredByAgent: preDefProp.isRequiredByAgent === undefined ? true : preDefProp.isRequiredByAgent
  57. }));
  58. }
  59. return App.ServiceConfigProperty.create({name: name, value: value, isRequiredByAgent: true, filename: 'some-site.xml'});
  60. };
  61. var tests = [
  62. {
  63. stepConfigs: [
  64. ['realm', ' SPACES ', 'host'],
  65. ['admin_server_host', ' space_left', 'host'],
  66. ['kdc_hosts', ' space_left_and_right ', 'host'],
  67. ['ldap_url', 'space_right ', 'host']
  68. ],
  69. e: {
  70. realm: 'SPACES',
  71. admin_server_host: 'space_left',
  72. kdc_hosts: 'space_left_and_right',
  73. ldap_url: 'space_right'
  74. }
  75. }
  76. ];
  77. tests.forEach(function(test) {
  78. describe('Should trim values for properties ' + Em.keys(test.e).join(','), function() {
  79. var result;
  80. beforeEach(function () {
  81. sinon.stub(App.StackService, 'find').returns([Em.Object.create({serviceName: 'KERBEROS'})]);
  82. controller.set('stepConfigs', [
  83. App.ServiceConfig.create({
  84. configs: test.stepConfigs.map(function(item) { return _createProperty(item[0], item[1], item[2]); })
  85. })
  86. ]);
  87. result = controller.createKerberosSiteObj('some-site', 'random-tag');
  88. });
  89. afterEach(function () {
  90. App.StackService.find.restore();
  91. });
  92. Em.keys(test.e).forEach(function(propertyName) {
  93. it(propertyName, function () {
  94. expect(result.properties[propertyName]).to.be.eql(test.e[propertyName]);
  95. });
  96. });
  97. });
  98. });
  99. });
  100. describe("#isSubmitDisabled", function () {
  101. var testCases = [
  102. {
  103. title: 'stepConfigs is empty',
  104. data: {
  105. stepConfigs: []
  106. },
  107. expected: true
  108. },
  109. {
  110. title: 'testConnectionInProgress is true',
  111. data: {
  112. stepConfigs: [{}],
  113. testConnectionInProgress: true
  114. },
  115. expected: true
  116. },
  117. {
  118. title: 'submitButtonClicked is true',
  119. data: {
  120. stepConfigs: [{}],
  121. testConnectionInProgress: false,
  122. submitButtonClicked: true
  123. },
  124. expected: true
  125. },
  126. {
  127. title: 'configs has errors',
  128. data: {
  129. stepConfigs: [{showConfig: true, errorCount: 1}],
  130. testConnectionInProgress: false,
  131. submitButtonClicked: false
  132. },
  133. expected: true
  134. },
  135. {
  136. title: 'miscModalVisible is true',
  137. data: {
  138. stepConfigs: [{showConfig: true, errorCount: 0}],
  139. testConnectionInProgress: false,
  140. submitButtonClicked: false,
  141. miscModalVisible: true
  142. },
  143. expected: true
  144. },
  145. {
  146. title: 'miscModalVisible is false',
  147. data: {
  148. stepConfigs: [{showConfig: true, errorCount: 0}],
  149. testConnectionInProgress: false,
  150. submitButtonClicked: false,
  151. miscModalVisible: false
  152. },
  153. expected: false
  154. }
  155. ];
  156. testCases.forEach(function(test) {
  157. it(test.title, function() {
  158. controller.setProperties(test.data);
  159. controller.propertyDidChange('isSubmitDisabled');
  160. expect(controller.get('isSubmitDisabled')).to.be.equal(test.expected);
  161. });
  162. });
  163. });
  164. describe("#clearStep()", function () {
  165. beforeEach(function() {
  166. controller.setProperties({
  167. configs: [{}],
  168. serviceConfigTags: [{}],
  169. servicesInstalled: true
  170. });
  171. controller.clearStep();
  172. });
  173. it("configs should be empty", function() {
  174. expect(controller.get('configs')).to.be.empty;
  175. });
  176. it("serviceConfigTags should be empty", function() {
  177. expect(controller.get('serviceConfigTags')).to.be.empty;
  178. });
  179. it("servicesInstalled should be false", function() {
  180. expect(controller.get('servicesInstalled')).to.be.false;
  181. });
  182. });
  183. describe("#loadStep()", function () {
  184. beforeEach(function() {
  185. this.mockStackService = sinon.stub(App.StackService, 'find').returns([{
  186. serviceName: 'KERBEROS'
  187. }]);
  188. sinon.stub(controller, 'clearStep');
  189. sinon.stub(App.config, 'setPreDefinedServiceConfigs');
  190. sinon.stub(controller, 'filterConfigs');
  191. sinon.stub(controller, 'getKerberosConfigs');
  192. sinon.stub(controller, 'initializeKDCStoreProperties');
  193. sinon.stub(controller, 'applyServicesConfigs');
  194. sinon.stub(controller, 'updateKDCStoreProperties');
  195. controller.reopen({
  196. isConfigsLoaded: true,
  197. stepConfigs: [Em.Object.create({serviceName: 'KERBEROS'})],
  198. content: Em.Object.create({
  199. serviceConfigProperties: [{}]
  200. }),
  201. wizardController: {
  202. skipClientInstall: true
  203. }
  204. });
  205. });
  206. afterEach(function() {
  207. this.mockStackService.restore();
  208. controller.clearStep.restore();
  209. App.config.setPreDefinedServiceConfigs.restore();
  210. controller.filterConfigs.restore();
  211. controller.getKerberosConfigs.restore();
  212. controller.initializeKDCStoreProperties.restore();
  213. controller.applyServicesConfigs.restore();
  214. controller.updateKDCStoreProperties.restore();
  215. });
  216. it("KERBEROS service absent", function() {
  217. this.mockStackService.returns([]);
  218. expect(controller.loadStep()).to.be.false;
  219. });
  220. it("configs not loaded", function() {
  221. controller.set('isConfigsLoaded', false);
  222. expect(controller.loadStep()).to.be.false;
  223. });
  224. it("clearStep should be called", function() {
  225. controller.loadStep();
  226. expect(controller.clearStep.calledOnce).to.be.true;
  227. });
  228. it("App.config.setPreDefinedServiceConfigs should be called", function() {
  229. controller.loadStep();
  230. expect(App.config.setPreDefinedServiceConfigs.calledOnce).to.be.true;
  231. });
  232. it("getKerberosConfigs should be called", function() {
  233. controller.set('content.serviceConfigProperties', null);
  234. controller.loadStep();
  235. expect(controller.getKerberosConfigs.calledOnce).to.be.true;
  236. });
  237. it("filterConfigs should be called", function() {
  238. controller.loadStep();
  239. expect(controller.filterConfigs.calledOnce).to.be.true;
  240. });
  241. it("initializeKDCStoreProperties should be called", function() {
  242. controller.set('wizardController.skipClientInstall', false);
  243. controller.loadStep();
  244. expect(controller.initializeKDCStoreProperties.calledOnce).to.be.true;
  245. });
  246. it("applyServicesConfigs should be called", function() {
  247. controller.loadStep();
  248. expect(controller.applyServicesConfigs.calledOnce).to.be.true;
  249. });
  250. it("updateKDCStoreProperties should be called", function() {
  251. controller.set('wizardController.skipClientInstall', false);
  252. controller.loadStep();
  253. expect(controller.updateKDCStoreProperties.calledOnce).to.be.true;
  254. });
  255. });
  256. describe("#getKerberosConfigs()", function () {
  257. beforeEach(function() {
  258. this.mock = sinon.stub(App.configsCollection, 'getAll');
  259. sinon.stub(App.config, 'getConfigTagFromFileName').returns('t1');
  260. sinon.stub(App.config, 'get').returns([
  261. Em.Object.create({
  262. serviceName: 'KERBEROS',
  263. configTypes: {
  264. 't1': {}
  265. }
  266. })
  267. ]);
  268. });
  269. afterEach(function() {
  270. this.mock .restore();
  271. App.config.getConfigTagFromFileName.restore();
  272. App.config.get.restore();
  273. });
  274. it("fileName not specified", function() {
  275. this.mock.returns([
  276. {
  277. serviceName: 'S1'
  278. }
  279. ]);
  280. expect(controller.getKerberosConfigs()).to.be.empty;
  281. });
  282. it("fileName not specified", function() {
  283. this.mock.returns([
  284. {
  285. serviceName: 'KERBEROS'
  286. }
  287. ]);
  288. expect(controller.getKerberosConfigs()).to.be.eql([
  289. {
  290. serviceName: 'KERBEROS'
  291. }
  292. ]);
  293. });
  294. it("incorrect service", function() {
  295. this.mock.returns([
  296. {
  297. fileName: 'f1',
  298. serviceName: 'S1'
  299. }
  300. ]);
  301. expect(controller.getKerberosConfigs()).to.be.eql([
  302. {
  303. fileName: 'f1',
  304. serviceName: 'S1'
  305. }
  306. ]);
  307. });
  308. it("fileName and service correct", function() {
  309. this.mock.returns([
  310. {
  311. fileName: 'f1',
  312. serviceName: 'KERBEROS'
  313. }
  314. ]);
  315. expect(controller.getKerberosConfigs()).to.be.eql([
  316. {
  317. fileName: 'f1',
  318. serviceName: 'KERBEROS'
  319. }
  320. ]);
  321. });
  322. });
  323. describe("#filterConfigs()", function () {
  324. var configs = [
  325. Em.Object.create({
  326. serviceName: 'KERBEROS',
  327. isVisible: false
  328. }),
  329. Em.Object.create({
  330. serviceName: 'S1',
  331. isVisible: false
  332. })
  333. ];
  334. beforeEach(function() {
  335. controller.set('controllers', {
  336. kerberosWizardController: Em.Object.create({
  337. skipClientInstall: false,
  338. overrideVisibility: Em.K
  339. })
  340. });
  341. controller.set('content', Em.Object.create({
  342. kerberosOption: null
  343. }));
  344. sinon.stub(controller.get('controllers.kerberosWizardController'), 'overrideVisibility');
  345. sinon.stub(controller, 'setKDCTypeProperty');
  346. sinon.stub(controller, 'setConfigVisibility');
  347. });
  348. afterEach(function() {
  349. controller.setKDCTypeProperty.restore();
  350. controller.setConfigVisibility.restore();
  351. controller.get('controllers.kerberosWizardController').overrideVisibility.restore();
  352. });
  353. it("KERBEROS config should be visible", function() {
  354. controller.filterConfigs(configs);
  355. expect(configs.mapProperty('isVisible')).to.be.eql([true, false]);
  356. });
  357. it("setKDCTypeProperty should be called", function() {
  358. controller.filterConfigs(configs);
  359. expect(controller.setKDCTypeProperty.calledOnce).to.be.true;
  360. });
  361. it("setConfigVisibility should not be called", function() {
  362. controller.set('content.kerberosOption', Em.I18n.t('admin.kerberos.wizard.step1.option.manual'));
  363. controller.filterConfigs(configs);
  364. expect(controller.setConfigVisibility.called).to.be.false;
  365. });
  366. it("overrideVisibility should be called", function() {
  367. controller.set('content.kerberosOption', Em.I18n.t('admin.kerberos.wizard.step1.option.manual'));
  368. controller.set('controllers.kerberosWizardController.skipClientInstall', true);
  369. controller.filterConfigs(configs);
  370. expect(controller.get('controllers.kerberosWizardController').overrideVisibility.calledOnce).to.be.true;
  371. });
  372. it("overrideVisibility should be called", function() {
  373. configs = [{
  374. name: 'manage_identities'
  375. }];
  376. controller.filterConfigs(configs);
  377. expect(configs[0].isVisible).to.be.false;
  378. expect(configs[0].value).to.be.equal('true');
  379. });
  380. it("setConfigVisibility should be called", function() {
  381. controller.filterConfigs(configs);
  382. expect(controller.setConfigVisibility.calledThrice).to.be.true;
  383. });
  384. });
  385. describe("#setConfigVisibility()", function () {
  386. it("ad type configs", function() {
  387. var configs = [{name: 'ldap_url'}];
  388. controller.setConfigVisibility('ad', configs, Em.I18n.t('admin.kerberos.wizard.step1.option.ad'));
  389. expect(configs[0].isVisible).to.be.true;
  390. });
  391. it("mit type configs", function() {
  392. var configs = [{name: 'kdc_create_attributes'}];
  393. controller.setConfigVisibility('mit', configs, Em.I18n.t('admin.kerberos.wizard.step1.option.kdc'));
  394. expect(configs[0].isVisible).to.be.true;
  395. });
  396. it("ipa type configs", function() {
  397. var configs = [{name: 'group'}];
  398. controller.setConfigVisibility('ipa', configs, Em.I18n.t('admin.kerberos.wizard.step1.option.ipa'));
  399. expect(configs[0].isVisible).to.be.true;
  400. });
  401. });
  402. describe("#submit()", function () {
  403. beforeEach(function() {
  404. sinon.stub(controller.get('wizardController'), 'deleteKerberosService').returns({
  405. always: Em.clb
  406. });
  407. sinon.stub(controller, 'configureKerberos');
  408. controller.reopen({
  409. isSubmitDisabled: false
  410. });
  411. });
  412. afterEach(function() {
  413. controller.get('wizardController').deleteKerberosService.restore();
  414. controller.configureKerberos.restore();
  415. });
  416. it("deleteKerberosService should not be called", function() {
  417. controller.set('isSubmitDisabled', true);
  418. expect(controller.submit()).to.be.false;
  419. expect(controller.get('wizardController').deleteKerberosService.called).to.be.false;
  420. });
  421. it("deleteKerberosService should be called", function() {
  422. controller.submit();
  423. expect(controller.get('wizardController').deleteKerberosService.called).to.be.true;
  424. });
  425. it("configureKerberos should be called", function() {
  426. controller.submit();
  427. expect(controller.configureKerberos.calledOnce).to.be.true;
  428. });
  429. });
  430. describe("#configureKerberos()", function () {
  431. var mock = Em.Object.create({
  432. createKerberosResources: Em.K
  433. });
  434. beforeEach(function() {
  435. sinon.stub(App.router, 'get').returns(mock);
  436. sinon.stub(controller, 'createConfigurations').returns({
  437. done: Em.clb
  438. });
  439. sinon.stub(controller, 'createKerberosAdminSession').returns({
  440. done: Em.clb
  441. });
  442. sinon.stub(App.router, 'send');
  443. sinon.stub(mock, 'createKerberosResources');
  444. });
  445. afterEach(function() {
  446. App.router.get.restore();
  447. controller.createConfigurations.restore();
  448. controller.createKerberosAdminSession.restore();
  449. App.router.send.restore();
  450. mock.createKerberosResources.restore();
  451. });
  452. it("createConfigurations should be called", function() {
  453. mock.set('skipClientInstall', true);
  454. controller.configureKerberos();
  455. expect(controller.createConfigurations.calledOnce).to.be.true;
  456. });
  457. it("createKerberosAdminSession should be called", function() {
  458. mock.set('skipClientInstall', true);
  459. controller.configureKerberos();
  460. expect(controller.createKerberosAdminSession.calledOnce).to.be.true;
  461. });
  462. it("App.router.send should be called", function() {
  463. mock.set('skipClientInstall', true);
  464. controller.configureKerberos();
  465. expect(App.router.send.calledWith('next')).to.be.true;
  466. });
  467. it("App.router.send should be called", function() {
  468. mock.set('skipClientInstall', false);
  469. controller.configureKerberos();
  470. expect(mock.createKerberosResources.calledOnce).to.be.true;
  471. });
  472. });
  473. describe("#createConfigurations()", function () {
  474. beforeEach(function() {
  475. sinon.stub(App.StackService, 'find').returns([
  476. Em.Object.create({
  477. serviceName: 'KERBEROS',
  478. configTypes: {
  479. t1: {},
  480. t3: {}
  481. },
  482. configTypesRendered: {
  483. t1: {},
  484. t2: {}
  485. }
  486. })
  487. ]);
  488. sinon.stub(controller, 'createKerberosSiteObj').returns({
  489. type: 't1'
  490. });
  491. });
  492. afterEach(function() {
  493. App.StackService.find.restore();
  494. controller.createKerberosSiteObj.restore();
  495. });
  496. it("App.ajax.send should be called", function() {
  497. controller.createConfigurations();
  498. var args = testHelpers.findAjaxRequest('name', 'common.across.services.configurations');
  499. expect(args[0]).to.be.eql({
  500. name: 'common.across.services.configurations',
  501. sender: controller,
  502. data: {
  503. data: '[' + JSON.stringify({
  504. Clusters: {
  505. desired_config: [
  506. {
  507. type: 't1',
  508. service_config_version_note: Em.I18n.t('admin.kerberos.wizard.configuration.note')
  509. }
  510. ]
  511. }
  512. }).toString() + ']'
  513. }
  514. });
  515. });
  516. });
  517. describe("#createKerberosSiteObj()", function () {
  518. beforeEach(function() {
  519. sinon.stub(controller, 'tweakKdcTypeValue');
  520. sinon.stub(controller, 'tweakManualKdcProperties');
  521. sinon.stub(controller, 'tweakIpaKdcProperties');
  522. sinon.stub(App.config, 'trimProperty', function(arg) {
  523. return arg;
  524. });
  525. controller.set('stepConfigs', [Em.Object.create({
  526. configs: []
  527. })]);
  528. });
  529. afterEach(function() {
  530. controller.tweakKdcTypeValue.restore();
  531. controller.tweakManualKdcProperties.restore();
  532. controller.tweakIpaKdcProperties.restore();
  533. App.config.trimProperty.restore();
  534. });
  535. it("tweakKdcTypeValue should be called", function() {
  536. controller.createKerberosSiteObj();
  537. expect(controller.tweakKdcTypeValue.calledWith({})).to.be.true;
  538. });
  539. it("tweakManualKdcProperties should be called", function() {
  540. controller.createKerberosSiteObj();
  541. expect(controller.tweakManualKdcProperties.calledWith({})).to.be.true;
  542. });
  543. it("tweakIpaKdcProperties should be called", function() {
  544. controller.createKerberosSiteObj();
  545. expect(controller.tweakIpaKdcProperties.calledWith({})).to.be.true;
  546. });
  547. it("properties should be empty", function() {
  548. controller.set('stepConfigs', [Em.Object.create({
  549. configs: [{
  550. isRequiredByAgent: false,
  551. filename: 'site.xml'
  552. }]
  553. })]);
  554. expect(controller.createKerberosSiteObj('site', 'tag')).to.be.eql({
  555. "type": 'site',
  556. "tag": 'tag',
  557. "properties": {}
  558. });
  559. });
  560. it("properties should contain kdc_hosts", function() {
  561. controller.set('stepConfigs', [Em.Object.create({
  562. configs: [{
  563. name: 'kdc_hosts',
  564. value: 'v1',
  565. filename: 'site.xml'
  566. }]
  567. })]);
  568. expect(controller.createKerberosSiteObj('site', 'tag')).to.be.eql({
  569. "type": 'site',
  570. "tag": 'tag',
  571. "properties": {
  572. 'kdc_hosts': {
  573. displayType: 'host',
  574. value: 'v1'
  575. }
  576. }
  577. });
  578. });
  579. it("properties should contain n1", function() {
  580. controller.set('stepConfigs', [Em.Object.create({
  581. configs: [{
  582. name: 'n1',
  583. value: 'v1',
  584. filename: 'site.xml'
  585. }]
  586. })]);
  587. expect(controller.createKerberosSiteObj('site', 'tag')).to.be.eql({
  588. "type": 'site',
  589. "tag": 'tag',
  590. "properties": {
  591. 'n1': {
  592. name: 'n1',
  593. value: 'v1',
  594. filename: 'site.xml'
  595. }
  596. }
  597. });
  598. });
  599. });
  600. describe("#tweakKdcTypeValue()", function () {
  601. beforeEach(function() {
  602. sinon.stub(App.router, 'get').returns({
  603. 'k1': 'p1'
  604. });
  605. });
  606. afterEach(function() {
  607. App.router.get.restore();
  608. });
  609. it("kdc_type should be p2", function() {
  610. var properties = {'kdc_type': 'p2'};
  611. controller.tweakKdcTypeValue(properties);
  612. expect(properties['kdc_type']).to.be.equal('p2')
  613. });
  614. it("kdc_type should be k1", function() {
  615. var properties = {'kdc_type': 'p1'};
  616. controller.tweakKdcTypeValue(properties);
  617. expect(properties['kdc_type']).to.be.equal('k1')
  618. });
  619. });
  620. describe("#tweakManualKdcProperties()", function () {
  621. it("properties shouldn't be changed", function() {
  622. var properties = {
  623. 'kdc_type': 'p1'
  624. };
  625. controller.set('controllers.kerberosWizardController', Em.Object.create({
  626. skipClientInstall: false
  627. }));
  628. controller.tweakManualKdcProperties(properties);
  629. expect(properties).to.be.eql({
  630. 'kdc_type': 'p1'
  631. });
  632. });
  633. it("kdc_type is none", function() {
  634. var properties = {
  635. 'kdc_type': 'none',
  636. 'manage_identities': 'true'
  637. };
  638. controller.set('controllers.kerberosWizardController', Em.Object.create({
  639. skipClientInstall: false
  640. }));
  641. controller.tweakManualKdcProperties(properties);
  642. expect(properties).to.be.eql({
  643. 'kdc_type': 'none',
  644. 'manage_identities': 'false'
  645. });
  646. });
  647. it("skipClientInstall is true", function() {
  648. var properties = {
  649. 'kdc_type': 'p1',
  650. 'manage_identities': 'true',
  651. 'install_packages': 'true',
  652. 'manage_krb5_conf': 'true'
  653. };
  654. controller.set('controllers.kerberosWizardController', Em.Object.create({
  655. skipClientInstall: true
  656. }));
  657. controller.tweakManualKdcProperties(properties);
  658. expect(properties).to.be.eql({
  659. 'kdc_type': 'p1',
  660. 'manage_identities': 'false',
  661. 'install_packages': 'false',
  662. 'manage_krb5_conf': 'false'
  663. });
  664. });
  665. });
  666. describe("#tweakIpaKdcProperties()", function () {
  667. beforeEach(function() {
  668. sinon.stub(App.router, 'get').returns({'ipa': 'p1'});
  669. });
  670. afterEach(function() {
  671. App.router.get.restore();
  672. });
  673. it("properties should be empty, kdc_type undefined", function() {
  674. var properties = {};
  675. controller.tweakIpaKdcProperties(properties);
  676. expect(properties).to.be.empty;
  677. });
  678. it("properties should not be empty", function() {
  679. var properties = {
  680. kdc_type: 'p1'
  681. };
  682. controller.set('content.kerberosOption', 'p2');
  683. controller.tweakIpaKdcProperties(properties);
  684. expect(properties).to.be.eql({
  685. kdc_type: 'p1'
  686. });
  687. });
  688. it("properties should set config values", function() {
  689. var properties = {
  690. 'kdc_type': 'p1',
  691. 'install_packages': 'true',
  692. 'manage_krb5_conf': 'true'
  693. };
  694. controller.set('content.kerberosOption', 'p1');
  695. controller.tweakIpaKdcProperties(properties);
  696. expect(properties).to.be.eql({
  697. 'kdc_type': 'p1',
  698. 'install_packages': 'false',
  699. 'manage_krb5_conf': 'false'
  700. });
  701. });
  702. });
  703. describe("#createKerberosAdminSession()", function () {
  704. beforeEach(function() {
  705. sinon.stub(controller, 'createKDCCredentials');
  706. });
  707. afterEach(function() {
  708. controller.createKDCCredentials.restore();
  709. });
  710. it("createKDCCredentials should be called", function() {
  711. controller.set('wizardController.skipClientInstall', false);
  712. controller.createKerberosAdminSession([]);
  713. expect(controller.createKDCCredentials.calledWith([])).to.be.true;
  714. });
  715. it("createKDCCredentials should be called, with non-empty configs", function() {
  716. controller.set('stepConfigs', [Em.Object.create({configs: [{}]})]);
  717. controller.set('wizardController.skipClientInstall', false);
  718. controller.createKerberosAdminSession();
  719. expect(controller.createKDCCredentials.calledWith([{}])).to.be.true;
  720. });
  721. it("App.ajax.send should be called", function() {
  722. App.set('clusterName', 'c1');
  723. var configs = [
  724. {
  725. name: 'admin_principal',
  726. value: 'v1'
  727. },
  728. {
  729. name: 'admin_password',
  730. value: 'v2'
  731. }
  732. ];
  733. controller.set('wizardController.skipClientInstall', true);
  734. controller.createKerberosAdminSession(configs);
  735. var args = testHelpers.findAjaxRequest('name', 'common.cluster.update');
  736. expect(args[0]).to.be.eql({
  737. name: 'common.cluster.update',
  738. sender: controller,
  739. data: {
  740. clusterName: 'c1',
  741. data: [{
  742. session_attributes: {
  743. kerberos_admin: {principal: 'v1', password: 'v2'}
  744. }
  745. }]
  746. }
  747. });
  748. });
  749. });
  750. describe("#showConnectionInProgressPopup()", function () {
  751. beforeEach(function() {
  752. sinon.stub(App, 'showConfirmationPopup');
  753. });
  754. afterEach(function() {
  755. App.showConfirmationPopup.restore();
  756. });
  757. it("App.showConfirmationPopup should be called", function() {
  758. var primary = Em.K;
  759. controller.showConnectionInProgressPopup(primary);
  760. expect(App.showConfirmationPopup.calledWith(primary, Em.I18n.t('services.service.config.connection.exitPopup.msg'), null, null, Em.I18n.t('common.exitAnyway'))).to.be.true;
  761. });
  762. });
  763. describe("#setKDCTypeProperty()", function () {
  764. beforeEach(function() {
  765. sinon.stub(App.router, 'get').returns({
  766. 'k1': 'p1'
  767. });
  768. });
  769. afterEach(function() {
  770. App.router.get.restore();
  771. });
  772. it("kdcTypeProperty should be set", function() {
  773. var configs = [{
  774. filename: 'kerberos-env.xml',
  775. name: 'kdc_type'
  776. }];
  777. controller.set('content.kerberosOption', 'p1');
  778. controller.setKDCTypeProperty(configs);
  779. expect(configs[0].value).to.be.equal('p1');
  780. });
  781. });
  782. });