123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- /**
- * 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.
- */
- require('mixins/common/kdc_credentials_controller_mixin');
- var App = require('app');
- var credentialsUtils = require('utils/credentials');
- var mixedObject;
- describe('App.KDCCredentialsControllerMixin', function() {
- beforeEach(function() {
- mixedObject = Em.Object.create(App.KDCCredentialsControllerMixin);
- });
- afterEach(function() {
- mixedObject.destroy();
- });
- describe('#initilizeKDCStoreProperties', function() {
- [
- {
- isStorePersisted: true,
- e: {
- isEditable: true,
- hintMessage: Em.I18n.t('admin.kerberos.credentials.store.hint.supported')
- },
- message: 'Persistent store available, config should be editable, and appropriate hint shown'
- },
- {
- isStorePersisted: false,
- e: {
- isEditable: false,
- hintMessage: Em.I18n.t('admin.kerberos.credentials.store.hint.not.supported')
- },
- message: 'Only temporary store available, config should be disabled, and appropriate hint shown'
- }
- ].forEach(function(test) {
- describe(test.message, function() {
- var config;
- beforeEach(function () {
- var configs = [];
- mixedObject.reopen({
- isStorePersisted: function() {
- return test.isStorePersisted;
- }.property()
- });
- mixedObject.initilizeKDCStoreProperties(configs);
- config = configs.findProperty('name', 'persist_credentials');
- });
- Object.keys(test.e).forEach(function(key) {
- it(key, function () {
- assert.equal(Em.get(config, key), test.e[key], 'validate attribute: ' + key);
- });
- });
- });
- });
- });
- describe('#createKDCCredentials', function() {
- function createConfig (name, value) {
- return App.ServiceConfigProperty.create({
- name: name,
- value: value
- });
- }
- function resolveWith (data) {
- return $.Deferred().resolve(data).promise();
- }
- function rejectWith (data) {
- return $.Deferred().reject(data).promise();
- }
- beforeEach(function () {
- sinon.stub(App, 'get').withArgs('clusterName').returns('testName');
- sinon.stub(credentialsUtils, 'createCredentials', function() {
- return resolveWith();
- });
- sinon.stub(credentialsUtils, 'updateCredentials', function() {
- return resolveWith();
- });
- mixedObject.reopen({
- isStorePersisted: true
- });
- });
- afterEach(function () {
- App.get.restore();
- credentialsUtils.createCredentials.restore();
- credentialsUtils.updateCredentials.restore();
- });
- [
- {
- configs: [
- createConfig('admin_password', 'admin'),
- createConfig('admin_principal', 'admin/admin'),
- createConfig('persist_credentials', 'true')
- ],
- credentialsExists: false,
- createCredentialFnCalled: true,
- updateCredentialFnCalled: false,
- e: [
- 'testName',
- 'kdc.admin.credential',
- {
- type: 'persisted',
- key: 'admin',
- principal: 'admin/admin'
- }
- ],
- message: 'Save Admin credentials checkbox checked, credentials already stored and should be updated as `persisted`'
- },
- {
- configs: [
- createConfig('admin_password', 'admin'),
- createConfig('admin_principal', 'admin/admin'),
- createConfig('persist_credentials', 'true')
- ],
- credentialsExists: true,
- createCredentialFnCalled: false,
- updateCredentialFnCalled: true,
- e: [
- 'testName',
- 'kdc.admin.credential',
- {
- type: 'persisted',
- key: 'admin',
- principal: 'admin/admin'
- }
- ],
- message: 'Save Admin credentials checkbox checked, no stored credentials, should be created as `persisted`'
- },
- {
- configs: [
- createConfig('admin_password', 'admin'),
- createConfig('admin_principal', 'admin/admin'),
- createConfig('persist_credentials', 'false')
- ],
- credentialsExists: true,
- createCredentialFnCalled: false,
- updateCredentialFnCalled: true,
- e: [
- 'testName',
- 'kdc.admin.credential',
- {
- type: 'temporary',
- key: 'admin',
- principal: 'admin/admin'
- }
- ],
- message: 'Save Admin credentials checkbox unchecked, credentials already stored and should be updated as `temporary`'
- },
- {
- configs: [
- createConfig('admin_password', 'admin'),
- createConfig('admin_principal', 'admin/admin'),
- createConfig('persist_credentials', 'false')
- ],
- credentialsExists: false,
- createCredentialFnCalled: true,
- updateCredentialFnCalled: false,
- e: [
- 'testName',
- 'kdc.admin.credential',
- {
- type: 'temporary',
- key: 'admin',
- principal: 'admin/admin'
- }
- ],
- message: 'Save Admin credentials checkbox unchecked, credentials already stored and should be updated as `temporary`'
- }
- ].forEach(function(test) {
- describe(test.message, function() {
- beforeEach(function () {
- sinon.stub(credentialsUtils, 'getCredential', function() {
- return test.credentialsExists ? resolveWith() : rejectWith();
- });
- mixedObject.createKDCCredentials(test.configs);
- });
- afterEach(function () {
- credentialsUtils.getCredential.restore();
- });
- it('credentialsUtils#createCredentials called', function () {
- expect(credentialsUtils.createCredentials.calledOnce).to.equal(test.createCredentialFnCalled);
- });
- if (test.createCredentialFnCalled) {
- it('credentialsUtils#createCredentials called with correct arguments', function () {
- expect(credentialsUtils.createCredentials.args[0]).to.eql(test.e);
- });
- }
- it('credentialUtils#updateCredentials called', function () {
- expect(credentialsUtils.updateCredentials.calledOnce).to.equal(test.updateCredentialFnCalled);
- });
- if (test.updateCredentialFnCalled) {
- it('credentialUtils#updateCredentials called with correct arguments', function () {
- expect(credentialsUtils.updateCredentials.args[0]).to.eql(test.e);
- });
- }
- });
- });
- });
- });
|