kdc_credentials_controller_mixin_test.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. require('mixins/common/kdc_credentials_controller_mixin');
  19. var App = require('app');
  20. var credentialsUtils = require('utils/credentials');
  21. var mixedObject;
  22. describe('App.KDCCredentialsControllerMixin', function() {
  23. beforeEach(function() {
  24. mixedObject = Em.Object.create(App.KDCCredentialsControllerMixin);
  25. });
  26. afterEach(function() {
  27. mixedObject.destroy();
  28. });
  29. describe('#initilizeKDCStoreProperties', function() {
  30. [
  31. {
  32. isStorePersisted: true,
  33. e: {
  34. isEditable: true,
  35. hintMessage: Em.I18n.t('admin.kerberos.credentials.store.hint.supported')
  36. },
  37. message: 'Persistent store available, config should be editable, and appropriate hint shown'
  38. },
  39. {
  40. isStorePersisted: false,
  41. e: {
  42. isEditable: false,
  43. hintMessage: Em.I18n.t('admin.kerberos.credentials.store.hint.not.supported')
  44. },
  45. message: 'Only temporary store available, config should be disabled, and appropriate hint shown'
  46. }
  47. ].forEach(function(test) {
  48. it(test.message, function() {
  49. var configs = [],
  50. config;
  51. mixedObject.reopen({
  52. isStorePersisted: function() {
  53. return test.isStorePersisted;
  54. }.property()
  55. });
  56. mixedObject.initilizeKDCStoreProperties(configs);
  57. config = configs.findProperty('name', 'persist_credentials');
  58. Em.keys(test.e).forEach(function(key) {
  59. assert.equal(Em.get(config, key), test.e[key], 'validate attribute: ' + key);
  60. });
  61. });
  62. });
  63. });
  64. describe('#createKDCCredentials', function() {
  65. var createConfig = function(name, value) {
  66. return App.ServiceConfigProperty.create({
  67. name: name,
  68. value: value
  69. });
  70. };
  71. [
  72. {
  73. configs: [
  74. createConfig('admin_password', 'admin'),
  75. createConfig('admin_principal', 'admin/admin'),
  76. createConfig('persist_credentials', 'true')
  77. ],
  78. e: [
  79. 'testName',
  80. 'kdc.admin.credential',
  81. {
  82. type: 'persisted',
  83. key: 'admin',
  84. principal: 'admin/admin'
  85. }
  86. ],
  87. message: 'Save Admin credentials checkbox checked, credentials should be saved as `persisted`'
  88. },
  89. {
  90. configs: [
  91. createConfig('admin_password', 'admin'),
  92. createConfig('admin_principal', 'admin/admin'),
  93. createConfig('persist_credentials', 'false')
  94. ],
  95. e: [
  96. 'testName',
  97. 'kdc.admin.credential',
  98. {
  99. type: 'temporary',
  100. key: 'admin',
  101. principal: 'admin/admin'
  102. }
  103. ],
  104. message: 'Save Admin credentials checkbox un-checked, credentials should be saved as `temporary`'
  105. },
  106. {
  107. configs: [
  108. createConfig('admin_password', 'admin'),
  109. createConfig('admin_principal', 'admin/admin'),
  110. createConfig('persist_credentials', 'false')
  111. ],
  112. e: [
  113. 'testName',
  114. 'kdc.admin.credential',
  115. {
  116. type: 'temporary',
  117. key: 'admin',
  118. principal: 'admin/admin'
  119. }
  120. ],
  121. credentialWasSaved: true,
  122. message: 'Save Admin credentials checkbox checked, credential was saved, credentials should be saved as `temporary`, #updateKDCCredentials should be called'
  123. }
  124. ].forEach(function(test) {
  125. it(test.message, function() {
  126. sinon.stub(App, 'get').withArgs('clusterName').returns('testName');
  127. sinon.stub(credentialsUtils, 'createCredentials', function() {
  128. if (test.credentialWasSaved) {
  129. return $.Deferred().reject().promise();
  130. } else {
  131. return $.Deferred().resolve().promise();
  132. }
  133. });
  134. if (test.credentialWasSaved) {
  135. sinon.stub(credentialsUtils, 'updateCredentials', function() {
  136. return $.Deferred().resolve().promise();
  137. });
  138. }
  139. mixedObject.reopen({
  140. isStorePersisted: function() {
  141. return true;
  142. }.property()
  143. });
  144. mixedObject.createKDCCredentials(test.configs);
  145. assert.isTrue(credentialsUtils.createCredentials.calledOnce, 'credentialsUtils#createCredentials called');
  146. assert.deepEqual(credentialsUtils.createCredentials.args[0], test.e, 'credentialsUtils#createCredentials called with correct arguments');
  147. credentialsUtils.createCredentials.restore();
  148. if (test.credentialWasSaved) {
  149. assert.isTrue(credentialsUtils.updateCredentials.calledOnce, 'credentialUtils#updateCredentials called');
  150. assert.deepEqual(credentialsUtils.updateCredentials.args[0], test.e, 'credentialUtils#updateCredentials called with correct arguments');
  151. credentialsUtils.updateCredentials.restore();
  152. }
  153. App.get.restore();
  154. });
  155. });
  156. });
  157. });