security_test.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. require('controllers/main/admin/security');
  20. describe('App.MainAdminSecurityController', function () {
  21. var controller = App.MainAdminSecurityController.create({
  22. getServiceConfigsFromServer: function () {
  23. } ,
  24. services: [{serviceName: 'HDFS'}]
  25. });
  26. describe('#setServiceTagNames()', function () {
  27. var testCases = [
  28. {
  29. title: 'configs is empty object',
  30. content: {
  31. secureService: {},
  32. configs: {}
  33. },
  34. result: undefined
  35. },
  36. {
  37. title: 'secureService.sites is null',
  38. content: {
  39. secureService: {
  40. sites: null
  41. },
  42. configs: {
  43. site1: {}
  44. }
  45. },
  46. result: undefined
  47. },
  48. {
  49. title: 'secureService.sites doesn\'t contain required config tag',
  50. content: {
  51. secureService: {
  52. sites: []
  53. },
  54. configs: {
  55. site1: {}
  56. }
  57. },
  58. result: undefined
  59. },
  60. {
  61. title: 'secureService.sites contains required config tag',
  62. content: {
  63. secureService: {
  64. sites: ['site1']
  65. },
  66. configs: {
  67. site1: {
  68. tag: 'tag1'
  69. }
  70. }
  71. },
  72. result: {
  73. siteName: 'site1',
  74. tagName: 'tag1',
  75. newTagName: null,
  76. configs: {}
  77. }
  78. }
  79. ];
  80. testCases.forEach(function (test) {
  81. it(test.title, function () {
  82. expect(controller.setServiceTagNames(test.content.secureService, test.content.configs)).to.eql(test.result);
  83. });
  84. });
  85. });
  86. describe('#getSecurityStatusFromServerSuccessCallback()', function () {
  87. beforeEach(function () {
  88. sinon.spy(controller, 'showSecurityErrorPopup');
  89. sinon.spy(controller, 'getServiceConfigsFromServer');
  90. });
  91. afterEach(function () {
  92. controller.showSecurityErrorPopup.restore();
  93. controller.getServiceConfigsFromServer.restore();
  94. });
  95. it('desired_configs is empty', function () {
  96. var data = {Clusters: {
  97. desired_configs: {}
  98. }};
  99. controller.getSecurityStatusFromServerSuccessCallback(data);
  100. expect(controller.showSecurityErrorPopup.called).to.equal(true);
  101. });
  102. it('cluster-env is missing', function () {
  103. var data = {Clusters: {
  104. desired_configs: {
  105. 'hdfs-site': {}
  106. }
  107. }};
  108. controller.getSecurityStatusFromServerSuccessCallback(data);
  109. expect(controller.showSecurityErrorPopup.called).to.equal(true);
  110. });
  111. it('cluster-env and hdfs-site are correct', function () {
  112. var data = {Clusters: {
  113. desired_configs: {
  114. 'hdfs-site': {
  115. tag: 1
  116. },
  117. 'cluster-env': {
  118. tag: 2
  119. },
  120. 'hadoop-env': {
  121. tag: 3
  122. }
  123. }
  124. }};
  125. controller.getSecurityStatusFromServerSuccessCallback(data);
  126. expect(controller.get('tag.cluster-env')).to.equal(2);
  127. expect(controller.get('tag.hdfs-site')).to.equal(1);
  128. expect(controller.getServiceConfigsFromServer.called).to.equal(true);
  129. });
  130. });
  131. describe('#setNnHaStatus()', function () {
  132. beforeEach(function () {
  133. sinon.stub(App.db, "setIsNameNodeHa", Em.K);
  134. });
  135. afterEach(function () {
  136. App.db.setIsNameNodeHa.restore();
  137. });
  138. it('hdfsConfigs is null', function () {
  139. var hdfsConfigs = null;
  140. controller.setNnHaStatus(hdfsConfigs);
  141. expect(App.db.setIsNameNodeHa.withArgs('false').called).to.equal(true);
  142. });
  143. it('"dfs.nameservices" is absent in hdfsConfigs', function () {
  144. var hdfsConfigs = {};
  145. controller.setNnHaStatus(hdfsConfigs);
  146. expect(App.db.setIsNameNodeHa.withArgs('false').called).to.equal(true);
  147. });
  148. it('namenodesKey is absent in hdfsConfigs', function () {
  149. var hdfsConfigs = {
  150. 'dfs.nameservices': 'key'
  151. };
  152. controller.setNnHaStatus(hdfsConfigs);
  153. expect(App.db.setIsNameNodeHa.withArgs('false').called).to.equal(true);
  154. });
  155. it('namenodesKey is present in hdfsConfigs', function () {
  156. var hdfsConfigs = {
  157. 'dfs.nameservices': 'key',
  158. 'dfs.ha.namenodes.key': 'true'
  159. };
  160. controller.setNnHaStatus(hdfsConfigs);
  161. expect(App.db.setIsNameNodeHa.withArgs('true').called).to.equal(true);
  162. });
  163. });
  164. describe('#loadUsers()', function () {
  165. beforeEach(function () {
  166. sinon.stub(App.db, "setSecureUserInfo", Em.K);
  167. });
  168. afterEach(function () {
  169. App.db.setSecureUserInfo.restore();
  170. });
  171. it('if defaultUserNameMap is empty then serviceUsers stays the same', function () {
  172. var configs = {};
  173. controller.set('serviceUsers', []);
  174. controller.set('userNameMap', {});
  175. controller.loadUsers(configs);
  176. expect(controller.get('serviceUsers')).to.be.empty;
  177. });
  178. it('if user config value is missing then use default', function () {
  179. var configs = {};
  180. controller.set('serviceUsers', []);
  181. controller.set('userNameMap', {
  182. test_user: {defaultValue: 'test', siteName: 'test-env', serviceName: 'TEST'
  183. }});
  184. controller.loadUsers(configs);
  185. expect(controller.get('serviceUsers')).to.eql([
  186. {
  187. "id": "puppet var",
  188. "name": "test_user",
  189. "value": "test"
  190. }
  191. ]);
  192. });
  193. it('user config value has value', function () {
  194. var configs = {
  195. 'test_user': 'config-value'
  196. };
  197. controller.set('serviceUsers', []);
  198. controller.set('defaultUserNameMap', {
  199. test_user: {defaultValue: 'test', siteName: 'test-env', serviceName: 'TEST'
  200. }});
  201. controller.loadUsers(configs);
  202. expect(controller.get('serviceUsers')).to.eql([
  203. {
  204. "id": "puppet var",
  205. "name": "test_user",
  206. "value": "config-value"
  207. }
  208. ]);
  209. });
  210. });
  211. });