summaryrefslogtreecommitdiff
path: root/ambari-web/test/controllers/main/admin/kerberos/step2_controller_test.js
blob: 2e603da3c254f22f1eec8738d08a439b60424736 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var App = require('app');
var setups = require('test/init_model_test');
var testHelpers = require('test/helpers');

function getController() {
  return App.KerberosWizardStep2Controller.create({
    wizardController: Em.Object.create({
      deleteKerberosService: Em.K
    }),
    controllers: Em.Object.create(),
    content: Em.Object.create()
  });
}

describe('App.KerberosWizardStep2Controller', function() {
  var controller;

  beforeEach(function() {
    controller = getController();
  });

  App.TestAliases.testAsComputedAlias(getController(), 'isBackBtnDisabled', 'testConnectionInProgress', 'boolean');

  App.TestAliases.testAsComputedAlias(getController(), 'hostNames', 'App.allHostNames', 'array');

  App.TestAliases.testAsComputedAlias(getController(), 'isConfigsLoaded', 'wizardController.stackConfigsLoaded', 'boolean');

  describe('#createKerberosSiteObj', function() {

    beforeEach(function() {
      setups.setupStackVersion(this, 'HDP-2.3');
      sinon.stub(controller, 'tweakKdcTypeValue', Em.K);
      sinon.stub(controller, 'tweakManualKdcProperties', Em.K);
    });

    after(function() {
      setups.restoreStackVersion(this);
      controller.tweakKdcTypeValue.restore();
      controller.tweakManualKdcProperties.restore();
    });

    var _createProperty = function(name, value, displayType) {
      var preDefProp = App.config.get('preDefinedSiteProperties').findProperty('name', name);
      if (preDefProp) {
        return App.ServiceConfigProperty.create(
          $.extend(true, {}, preDefProp, {
            value: value, filename: 'some-site.xml',
            'displayType': displayType,
            isRequiredByAgent: preDefProp.isRequiredByAgent === undefined ? true : preDefProp.isRequiredByAgent
          }));
      }
      return App.ServiceConfigProperty.create({name: name, value: value, isRequiredByAgent: true, filename: 'some-site.xml'});
    };

    var tests = [
      {
        stepConfigs: [
          ['realm', ' SPACES ', 'host'],
          ['admin_server_host', ' space_left', 'host'],
          ['kdc_hosts', ' space_left_and_right ', 'host'],
          ['ldap_url', 'space_right ', 'host']
        ],
        e: {
          realm: 'SPACES',
          admin_server_host: 'space_left',
          kdc_hosts: 'space_left_and_right',
          ldap_url: 'space_right'
        }
      }
    ];

    tests.forEach(function(test) {
      describe('Should trim values for properties ' + Em.keys(test.e).join(','), function() {
        var result;

        beforeEach(function () {
          sinon.stub(App.StackService, 'find').returns([Em.Object.create({serviceName: 'KERBEROS'})]);
          controller.set('stepConfigs', [
            App.ServiceConfig.create({
              configs: test.stepConfigs.map(function(item) { return _createProperty(item[0], item[1], item[2]); })
            })
          ]);
          result = controller.createKerberosSiteObj('some-site', 'random-tag');
        });

        afterEach(function () {
          App.StackService.find.restore();
        });

        Em.keys(test.e).forEach(function(propertyName) {
          it(propertyName, function () {
            expect(result.properties[propertyName]).to.be.eql(test.e[propertyName]);
          });
        });
      });
    });
  });

  describe("#isSubmitDisabled", function () {
    var testCases = [
      {
        title: 'stepConfigs is empty',
        data: {
          stepConfigs: []
        },
        expected: true
      },
      {
        title: 'testConnectionInProgress is true',
        data: {
          stepConfigs: [{}],
          testConnectionInProgress: true
        },
        expected: true
      },
      {
        title: 'submitButtonClicked is true',
        data: {
          stepConfigs: [{}],
          testConnectionInProgress: false,
          submitButtonClicked: true
        },
        expected: true
      },
      {
        title: 'configs has errors',
        data: {
          stepConfigs: [{showConfig: true, errorCount: 1}],
          testConnectionInProgress: false,
          submitButtonClicked: false
        },
        expected: true
      },
      {
        title: 'miscModalVisible is true',
        data: {
          stepConfigs: [{showConfig: true, errorCount: 0}],
          testConnectionInProgress: false,
          submitButtonClicked: false,
          miscModalVisible: true
        },
        expected: true
      },
      {
        title: 'miscModalVisible is false',
        data: {
          stepConfigs: [{showConfig: true, errorCount: 0}],
          testConnectionInProgress: false,
          submitButtonClicked: false,
          miscModalVisible: false
        },
        expected: false
      }
    ];

    testCases.forEach(function(test) {
      it(test.title, function() {
        controller.setProperties(test.data);
        controller.propertyDidChange('isSubmitDisabled');
        expect(controller.get('isSubmitDisabled')).to.be.equal(test.expected);
      });
    });
  });

  describe("#clearStep()", function () {

    beforeEach(function() {
      controller.setProperties({
        configs: [{}],
        serviceConfigTags: [{}],
        servicesInstalled: true
      });
      controller.clearStep();
    });

    it("configs should be empty", function() {
      expect(controller.get('configs')).to.be.empty;
    });

    it("serviceConfigTags should be empty", function() {
      expect(controller.get('serviceConfigTags')).to.be.empty;
    });

    it("servicesInstalled should be false", function() {
      expect(controller.get('servicesInstalled')).to.be.false;
    });
  });

  describe("#loadStep()", function () {

    beforeEach(function() {
      this.mockStackService = sinon.stub(App.StackService, 'find').returns([{
        serviceName: 'KERBEROS'
      }]);
      sinon.stub(controller, 'clearStep');
      sinon.stub(App.config, 'setPreDefinedServiceConfigs');
      sinon.stub(App.config, 'mergeStoredValue');
      sinon.stub(controller, 'filterConfigs');
      sinon.stub(controller, 'getKerberosConfigs');
      sinon.stub(controller, 'initializeKDCStoreProperties');
      sinon.stub(controller, 'applyServicesConfigs');
      sinon.stub(controller, 'updateKDCStoreProperties');
      controller.reopen({
        isConfigsLoaded: true,
        stepConfigs: [Em.Object.create({serviceName: 'KERBEROS'})],
        content: Em.Object.create({
          serviceConfigProperties: [{}]
        }),
        wizardController: {
          skipClientInstall: true
        }
      });
    });

    afterEach(function() {
      this.mockStackService.restore();
      controller.clearStep.restore();
      App.config.setPreDefinedServiceConfigs.restore();
      App.config.mergeStoredValue.restore();
      controller.filterConfigs.restore();
      controller.getKerberosConfigs.restore();
      controller.initializeKDCStoreProperties.restore();
      controller.applyServicesConfigs.restore();
      controller.updateKDCStoreProperties.restore();
    });

    it("KERBEROS service absent", function() {
      this.mockStackService.returns([]);
      expect(controller.loadStep()).to.be.false;
    });

    it("configs not loaded", function() {
      controller.set('isConfigsLoaded', false);
      expect(controller.loadStep()).to.be.false;
    });

    it("clearStep should be called", function() {
      controller.loadStep();
      expect(controller.clearStep.calledOnce).to.be.true;
    });

    it("App.config.setPreDefinedServiceConfigs should be called", function() {
      controller.loadStep();
      expect(App.config.setPreDefinedServiceConfigs.calledOnce).to.be.true;
    });

    it("getKerberosConfigs should be called", function() {
      controller.set('content.serviceConfigProperties', null);
      controller.loadStep();
      expect(controller.getKerberosConfigs.calledOnce).to.be.true;
    });

    it("filterConfigs should be called", function() {
      controller.loadStep();
      expect(controller.filterConfigs.calledOnce).to.be.true;
    });

    it("initializeKDCStoreProperties should be called", function() {
      controller.set('wizardController.skipClientInstall', false);
      controller.loadStep();
      expect(controller.initializeKDCStoreProperties.calledOnce).to.be.true;
    });

    it("applyServicesConfigs should be called", function() {
      controller.loadStep();
      expect(controller.applyServicesConfigs.calledOnce).to.be.true;
    });

    it("updateKDCStoreProperties should be called", function() {
      controller.set('wizardController.skipClientInstall', false);
      controller.loadStep();
      expect(controller.updateKDCStoreProperties.calledOnce).to.be.true;
    });
  });

  describe("#getKerberosConfigs()", function () {

    beforeEach(function() {
      this.mock = sinon.stub(App.configsCollection, 'getAll');
      sinon.stub(App.config, 'getConfigTagFromFileName').returns('t1');
      sinon.stub(App.config, 'get').returns([
        Em.Object.create({
          serviceName: 'KERBEROS',
          configTypes: {
            't1': {}
          }
        })
      ]);
    });

    afterEach(function() {
      this.mock .restore();
      App.config.getConfigTagFromFileName.restore();
      App.config.get.restore();
    });

    it("fileName not specified (serviceName S1)", function() {
      this.mock.returns([
        {
          serviceName: 'S1'
        }
      ]);
      expect(controller.getKerberosConfigs()).to.be.empty;
    });

    it("fileName not specified (serviceName KERBEROS)", function() {
      this.mock.returns([
        {
          serviceName: 'KERBEROS'
        }
      ]);
      expect(controller.getKerberosConfigs()).to.be.eql([
        {
          serviceName: 'KERBEROS'
        }
      ]);
    });

    it("incorrect service", function() {
      this.mock.returns([
        {
          fileName: 'f1',
          serviceName: 'S1'
        }
      ]);
      expect(controller.getKerberosConfigs()).to.be.eql([
        {
          fileName: 'f1',
          serviceName: 'S1'
        }
      ]);
    });

    it("fileName and service correct", function() {
      this.mock.returns([
        {
          fileName: 'f1',
          serviceName: 'KERBEROS'
        }
      ]);
      expect(controller.getKerberosConfigs()).to.be.eql([
        {
          fileName: 'f1',
          serviceName: 'KERBEROS'
        }
      ]);
    });
  });

  describe("#filterConfigs()", function () {
    var configs = [
      Em.Object.create({
        serviceName: 'KERBEROS',
        isVisible: false
      }),
      Em.Object.create({
        serviceName: 'S1',
        isVisible: false
      })
    ];

    beforeEach(function() {
      controller.set('controllers', {
        kerberosWizardController: Em.Object.create({
          skipClientInstall: false,
          overrideVisibility: Em.K
        })
      });
      controller.set('content', Em.Object.create({
        kerberosOption: null
      }));
      sinon.stub(controller.get('controllers.kerberosWizardController'), 'overrideVisibility');
      sinon.stub(controller, 'setKDCTypeProperty');
      sinon.stub(controller, 'setConfigVisibility');
    });

    afterEach(function() {
      controller.setKDCTypeProperty.restore();
      controller.setConfigVisibility.restore();
      controller.get('controllers.kerberosWizardController').overrideVisibility.restore();
    });

    it("KERBEROS config should be visible", function() {
      controller.filterConfigs(configs);
      expect(configs.mapProperty('isVisible')).to.be.eql([true, false]);
    });

    it("setKDCTypeProperty should be called", function() {
      controller.filterConfigs(configs);
      expect(controller.setKDCTypeProperty.calledOnce).to.be.true;
    });

    it("setConfigVisibility should not be called", function() {
      controller.set('content.kerberosOption', Em.I18n.t('admin.kerberos.wizard.step1.option.manual'));
      controller.filterConfigs(configs);
      expect(controller.setConfigVisibility.called).to.be.false;
    });

    it("overrideVisibility should be called", function() {
      controller.set('content.kerberosOption', Em.I18n.t('admin.kerberos.wizard.step1.option.manual'));
      controller.set('controllers.kerberosWizardController.skipClientInstall', true);
      controller.filterConfigs(configs);
      expect(controller.get('controllers.kerberosWizardController').overrideVisibility.calledOnce).to.be.true;
    });

    it("overrideVisibility results are valid", function() {
      configs = [{
        name: 'manage_identities'
      }];
      controller.filterConfigs(configs);
      expect(configs[0].isVisible).to.be.false;
      expect(configs[0].value).to.be.equal('true');
    });

    it("setConfigVisibility should be called", function() {
      controller.filterConfigs(configs);
      expect(controller.setConfigVisibility.calledThrice).to.be.true;
    });
  });

  describe("#setConfigVisibility()", function () {

    it("ad type configs", function() {
      var configs = [{name: 'ldap_url'}];
      controller.setConfigVisibility('ad', configs, Em.I18n.t('admin.kerberos.wizard.step1.option.ad'));
      expect(configs[0].isVisible).to.be.true;
    });

    it("mit type configs", function() {
      var configs = [{name: 'kdc_create_attributes'}];
      controller.setConfigVisibility('mit', configs, Em.I18n.t('admin.kerberos.wizard.step1.option.kdc'));
      expect(configs[0].isVisible).to.be.true;
    });

    it("ipa type configs", function() {
      var configs = [{name: 'group'}];
      controller.setConfigVisibility('ipa', configs, Em.I18n.t('admin.kerberos.wizard.step1.option.ipa'));
      expect(configs[0].isVisible).to.be.true;
    });
  });

  describe("#submit()", function () {

    beforeEach(function() {
      sinon.stub(controller.get('wizardController'), 'deleteKerberosService').returns({
        always: Em.clb
      });
      sinon.stub(controller, 'configureKerberos');
      controller.reopen({
        isSubmitDisabled: false
      });
    });

    afterEach(function() {
      controller.get('wizardController').deleteKerberosService.restore();
      controller.configureKerberos.restore();
    });

    it("deleteKerberosService should not be called", function() {
      controller.set('isSubmitDisabled', true);
      expect(controller.submit()).to.be.false;
      expect(controller.get('wizardController').deleteKerberosService.called).to.be.false;
    });

    it("deleteKerberosService should be called", function() {
      controller.submit();
      expect(controller.get('wizardController').deleteKerberosService.called).to.be.true;
    });

    it("configureKerberos should be called", function() {
      controller.submit();
      expect(controller.configureKerberos.calledOnce).to.be.true;
    });
  });

  describe("#configureKerberos()", function () {
    var mock = Em.Object.create({
      createKerberosResources: Em.K
    });

    beforeEach(function() {
      sinon.stub(App.router, 'get').returns(mock);
      sinon.stub(controller, 'createConfigurations').returns({
        done: Em.clb
      });
      sinon.stub(controller, 'createKerberosAdminSession').returns({
        done: Em.clb
      });
      sinon.stub(App.router, 'send');
      sinon.stub(mock, 'createKerberosResources');
    });

    afterEach(function() {
      App.router.get.restore();
      controller.createConfigurations.restore();
      controller.createKerberosAdminSession.restore();
      App.router.send.restore();
      mock.createKerberosResources.restore();
    });

    it("createConfigurations should be called", function() {
      mock.set('skipClientInstall', true);
      controller.configureKerberos();
      expect(controller.createConfigurations.calledOnce).to.be.true;
    });

    it("createKerberosAdminSession should be called", function() {
      mock.set('skipClientInstall', true);
      controller.configureKerberos();
      expect(controller.createKerberosAdminSession.calledOnce).to.be.true;
    });

    it("App.router.send should be called", function() {
      mock.set('skipClientInstall', true);
      controller.configureKerberos();
      expect(App.router.send.calledWith('next')).to.be.true;
    });

    it("createKerberosResources should be called", function() {
      mock.set('skipClientInstall', false);
      controller.configureKerberos();
      expect(mock.createKerberosResources.calledOnce).to.be.true;
    });
  });

  describe("#createConfigurations()", function () {

    beforeEach(function() {
      sinon.stub(App.StackService, 'find').returns([
        Em.Object.create({
          serviceName: 'KERBEROS',
          configTypes: {
            t1: {},
            t3: {}
          },
          configTypesRendered: {
            t1: {},
            t2: {}
          }
        })
      ]);
      sinon.stub(controller, 'createKerberosSiteObj').returns({
        type: 't1'
      });
    });

    afterEach(function() {
      App.StackService.find.restore();
      controller.createKerberosSiteObj.restore();
    });

    it("App.ajax.send should be called", function() {
      controller.createConfigurations();
      var args = testHelpers.findAjaxRequest('name', 'common.across.services.configurations');
      expect(args[0]).to.be.eql({
        name: 'common.across.services.configurations',
        sender: controller,
        data: {
          data: '[' + JSON.stringify({
            Clusters: {
              desired_config: [
                {
                  type: 't1',
                  service_config_version_note: Em.I18n.t('admin.kerberos.wizard.configuration.note')
                }
              ]
            }
          }).toString() + ']'
        }
      });
    });
  });

  describe("#createKerberosSiteObj()", function () {

    beforeEach(function() {
      sinon.stub(controller, 'tweakKdcTypeValue');
      sinon.stub(controller, 'tweakManualKdcProperties');
      sinon.stub(controller, 'tweakIpaKdcProperties');
      sinon.stub(App.config, 'trimProperty', function(arg) {
        return arg;
      });
      controller.set('stepConfigs', [Em.Object.create({
        configs: []
      })]);
    });

    afterEach(function() {
      controller.tweakKdcTypeValue.restore();
      controller.tweakManualKdcProperties.restore();
      controller.tweakIpaKdcProperties.restore();
      App.config.trimProperty.restore();
    });

    it("tweakKdcTypeValue should be called", function() {
      controller.createKerberosSiteObj();
      expect(controller.tweakKdcTypeValue.calledWith({})).to.be.true;
    });

    it("tweakManualKdcProperties should be called", function() {
      controller.createKerberosSiteObj();
      expect(controller.tweakManualKdcProperties.calledWith({})).to.be.true;
    });

    it("tweakIpaKdcProperties should be called", function() {
      controller.createKerberosSiteObj();
      expect(controller.tweakIpaKdcProperties.calledWith({})).to.be.true;
    });

    it("properties should be empty", function() {
      controller.set('stepConfigs', [Em.Object.create({
        configs: [{
          isRequiredByAgent: false,
          filename: 'site.xml'
        }]
      })]);
      expect(controller.createKerberosSiteObj('site', 'tag')).to.be.eql({
        "type": 'site',
        "tag": 'tag',
        "properties": {}
      });
    });

    it("properties should contain kdc_hosts", function() {
      controller.set('stepConfigs', [Em.Object.create({
        configs: [{
          name: 'kdc_hosts',
          value: 'v1',
          filename: 'site.xml'
        }]
      })]);
      expect(controller.createKerberosSiteObj('site', 'tag')).to.be.eql({
        "type": 'site',
        "tag": 'tag',
        "properties": {
          'kdc_hosts': {
            displayType: 'host',
            value: 'v1'
          }
        }
      });
    });

    it("properties should contain n1", function() {
      controller.set('stepConfigs', [Em.Object.create({
        configs: [{
          name: 'n1',
          value: 'v1',
          filename: 'site.xml'
        }]
      })]);
      expect(controller.createKerberosSiteObj('site', 'tag')).to.be.eql({
        "type": 'site',
        "tag": 'tag',
        "properties": {
          'n1': {
            name: 'n1',
            value: 'v1',
            filename: 'site.xml'
          }
        }
      });
    });
  });

  describe("#tweakKdcTypeValue()", function () {

    beforeEach(function() {
      sinon.stub(App.router, 'get').returns({
        'k1': 'p1'
      });
    });

    afterEach(function() {
      App.router.get.restore();
    });

    it("kdc_type should be p2", function() {
      var properties = {'kdc_type': 'p2'};
      controller.tweakKdcTypeValue(properties);
      expect(properties.kdc_type).to.be.equal('p2')
    });

    it("kdc_type should be k1", function() {
      var properties = {'kdc_type': 'p1'};
      controller.tweakKdcTypeValue(properties);
      expect(properties.kdc_type).to.be.equal('k1')
    });
  });

  describe("#tweakManualKdcProperties()", function () {

    it("properties shouldn't be changed", function() {
      var properties = {
        'kdc_type': 'p1'
      };
      controller.set('controllers.kerberosWizardController', Em.Object.create({
        skipClientInstall: false
      }));
      controller.tweakManualKdcProperties(properties);
      expect(properties).to.be.eql({
        'kdc_type': 'p1'
      });
    });

    it("kdc_type is none", function() {
      var properties = {
        'kdc_type': 'none',
        'manage_identities': 'true'
      };
      controller.set('controllers.kerberosWizardController', Em.Object.create({
        skipClientInstall: false
      }));
      controller.tweakManualKdcProperties(properties);
      expect(properties).to.be.eql({
        'kdc_type': 'none',
        'manage_identities': 'false'
      });
    });

    it("skipClientInstall is true", function() {
      var properties = {
        'kdc_type': 'p1',
        'manage_identities': 'true',
        'install_packages': 'true',
        'manage_krb5_conf': 'true'
      };
      controller.set('controllers.kerberosWizardController', Em.Object.create({
        skipClientInstall: true
      }));
      controller.tweakManualKdcProperties(properties);
      expect(properties).to.be.eql({
        'kdc_type': 'p1',
        'manage_identities': 'false',
        'install_packages': 'false',
        'manage_krb5_conf': 'false'
      });
    });
  });

  describe("#tweakIpaKdcProperties()", function () {

    beforeEach(function() {
      sinon.stub(App.router, 'get').returns({'ipa': 'p1'});
    });

    afterEach(function() {
      App.router.get.restore();
    });

    it("properties should be empty, kdc_type undefined", function() {
      var properties = {};
      controller.tweakIpaKdcProperties(properties);
      expect(properties).to.be.empty;
    });

    it("properties should not be empty", function() {
      var properties = {
        kdc_type: 'p1'
      };
      controller.set('content.kerberosOption', 'p2');
      controller.tweakIpaKdcProperties(properties);
      expect(properties).to.be.eql({
        kdc_type: 'p1'
      });
    });

    it("properties should set config values", function() {
      var properties = {
        'kdc_type': 'p1',
        'install_packages': 'true',
        'manage_krb5_conf': 'true'
      };
      controller.set('content.kerberosOption', 'p1');
      controller.tweakIpaKdcProperties(properties);
      expect(properties).to.be.eql({
        'kdc_type': 'p1',
        'install_packages': 'false',
        'manage_krb5_conf': 'false'
      });
    });
  });

  describe("#createKerberosAdminSession()", function () {

    beforeEach(function() {
      sinon.stub(controller, 'createKDCCredentials');
    });

    afterEach(function() {
      controller.createKDCCredentials.restore();
    });

    it("createKDCCredentials should be called", function() {
      controller.set('wizardController.skipClientInstall', false);
      controller.createKerberosAdminSession([]);
      expect(controller.createKDCCredentials.calledWith([])).to.be.true;
    });

    it("createKDCCredentials should be called, with non-empty configs", function() {
      controller.set('stepConfigs', [Em.Object.create({configs: [{}]})]);
      controller.set('wizardController.skipClientInstall', false);
      controller.createKerberosAdminSession();
      expect(controller.createKDCCredentials.calledWith([{}])).to.be.true;
    });

    it("App.ajax.send should be called", function() {
      App.set('clusterName', 'c1');
      var configs = [
        {
          name: 'admin_principal',
          value: 'v1'
        },
        {
          name: 'admin_password',
          value: 'v2'
        }
      ];
      controller.set('wizardController.skipClientInstall', true);

      controller.createKerberosAdminSession(configs);
      var args = testHelpers.findAjaxRequest('name', 'common.cluster.update');
      expect(args[0]).to.be.eql({
        name: 'common.cluster.update',
        sender: controller,
        data: {
          clusterName: 'c1',
          data: [{
            session_attributes: {
              kerberos_admin: {principal: 'v1', password: 'v2'}
            }
          }]
        }
      });
    });
  });

  describe("#showConnectionInProgressPopup()", function () {

    beforeEach(function() {
      sinon.stub(App, 'showConfirmationPopup');
    });

    afterEach(function() {
      App.showConfirmationPopup.restore();
    });

    it("App.showConfirmationPopup should be called", function() {
      var primary = Em.K;
      controller.showConnectionInProgressPopup(primary);
      expect(App.showConfirmationPopup.calledWith(primary, Em.I18n.t('services.service.config.connection.exitPopup.msg'), null, null, Em.I18n.t('common.exitAnyway'))).to.be.true;
    });
  });


  describe("#setKDCTypeProperty()", function () {

    beforeEach(function() {
      sinon.stub(App.router, 'get').returns({
        'k1': 'p1'
      });
    });

    afterEach(function() {
      App.router.get.restore();
    });

    it("kdcTypeProperty should be set", function() {
      var configs = [{
        filename: 'kerberos-env.xml',
        name: 'kdc_type'
      }];
      controller.set('content.kerberosOption', 'p1');
      controller.setKDCTypeProperty(configs);
      expect(configs[0].value).to.be.equal('p1');
    });
  });
});