foreman_puppet 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +619 -0
  3. data/README.md +38 -0
  4. data/Rakefile +31 -0
  5. data/app/assets/stylesheets/foreman_puppet.scss +117 -0
  6. data/app/controllers/concerns/foreman_puppet/api/import_puppetclasses_common_controller.rb +139 -0
  7. data/app/controllers/concerns/foreman_puppet/environments_import.rb +61 -0
  8. data/app/controllers/concerns/foreman_puppet/extensions/api_hostgroups_controller.rb +40 -0
  9. data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb +23 -0
  10. data/app/controllers/concerns/foreman_puppet/extensions/api_v2_hosts_controller.rb +48 -0
  11. data/app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb +58 -0
  12. data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +228 -0
  13. data/app/controllers/concerns/foreman_puppet/extensions/operatingsystems_controller.rb +11 -0
  14. data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +75 -0
  15. data/app/controllers/concerns/foreman_puppet/extensions/parameters_hostgroup.rb +70 -0
  16. data/app/controllers/concerns/foreman_puppet/extensions/parameters_template_combination.rb +21 -0
  17. data/app/controllers/concerns/foreman_puppet/parameters/config_group.rb +17 -0
  18. data/app/controllers/concerns/foreman_puppet/parameters/environment.rb +21 -0
  19. data/app/controllers/concerns/foreman_puppet/parameters/puppetclass.rb +24 -0
  20. data/app/controllers/concerns/foreman_puppet/parameters/puppetclass_lookup_key.rb +24 -0
  21. data/app/controllers/foreman_puppet/api/v2/base_controller.rb +26 -0
  22. data/app/controllers/foreman_puppet/api/v2/config_groups_controller.rb +57 -0
  23. data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +91 -0
  24. data/app/controllers/foreman_puppet/api/v2/host_classes_controller.rb +59 -0
  25. data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +46 -0
  26. data/app/controllers/foreman_puppet/api/v2/lookups_common_controller.rb +114 -0
  27. data/app/controllers/foreman_puppet/api/v2/override_values_controller.rb +99 -0
  28. data/app/controllers/foreman_puppet/api/v2/puppetclasses_controller.rb +99 -0
  29. data/app/controllers/foreman_puppet/api/v2/smart_class_parameters_controller.rb +76 -0
  30. data/app/controllers/foreman_puppet/config_groups_controller.rb +46 -0
  31. data/app/controllers/foreman_puppet/environments_controller.rb +51 -0
  32. data/app/controllers/foreman_puppet/puppet_smart_proxies_controller.rb +39 -0
  33. data/app/controllers/foreman_puppet/puppetclass_lookup_keys_controller.rb +33 -0
  34. data/app/controllers/foreman_puppet/puppetclasses_controller.rb +113 -0
  35. data/app/controllers/foreman_puppet/react_controller.rb +19 -0
  36. data/app/helpers/concerns/foreman_puppet/template_renderer_scope.rb +14 -0
  37. data/app/helpers/foreman_puppet/environments_helper.rb +17 -0
  38. data/app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb +96 -0
  39. data/app/helpers/foreman_puppet/hosts_helper.rb +32 -0
  40. data/app/helpers/foreman_puppet/puppet_smart_proxies_helper.rb +8 -0
  41. data/app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb +135 -0
  42. data/app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb +55 -0
  43. data/app/helpers/foreman_puppet/puppetclasses_helper.rb +59 -0
  44. data/app/helpers/foreman_puppet/template_combinations_helper.rb +33 -0
  45. data/app/models/concerns/foreman_puppet/extensions/host.rb +88 -0
  46. data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +40 -0
  47. data/app/models/concerns/foreman_puppet/extensions/nic_managed.rb +11 -0
  48. data/app/models/concerns/foreman_puppet/extensions/operatingsystem.rb +11 -0
  49. data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +64 -0
  50. data/app/models/concerns/foreman_puppet/extensions/report.rb +11 -0
  51. data/app/models/concerns/foreman_puppet/extensions/taxonomy.rb +19 -0
  52. data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +23 -0
  53. data/app/models/concerns/foreman_puppet/extensions/user.rb +22 -0
  54. data/app/models/concerns/foreman_puppet/host_common.rb +90 -0
  55. data/app/models/concerns/foreman_puppet/puppet_lookup_value_extensions.rb +13 -0
  56. data/app/models/foreman_puppet/config_group.rb +45 -0
  57. data/app/models/foreman_puppet/config_group_class.rb +19 -0
  58. data/app/models/foreman_puppet/environment.rb +63 -0
  59. data/app/models/foreman_puppet/environment_class.rb +40 -0
  60. data/app/models/foreman_puppet/host_class.rb +23 -0
  61. data/app/models/foreman_puppet/host_config_group.rb +15 -0
  62. data/app/models/foreman_puppet/host_puppet_facet.rb +130 -0
  63. data/app/models/foreman_puppet/hostgroup_class.rb +23 -0
  64. data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +98 -0
  65. data/app/models/foreman_puppet/puppetclass.rb +132 -0
  66. data/app/models/foreman_puppet/puppetclass_lookup_key.rb +58 -0
  67. data/app/services/foreman_puppet/host_info_providers/config_groups_info.rb +10 -0
  68. data/app/services/foreman_puppet/host_info_providers/puppet_info.rb +92 -0
  69. data/app/services/foreman_puppet/input_type/puppet_parameter_input.rb +35 -0
  70. data/app/services/foreman_puppet/proxy_status/puppet.rb +17 -0
  71. data/app/services/foreman_puppet/puppet_class_importer.rb +355 -0
  72. data/app/views/api/v2/template_combinations/base.json.erb +9 -0
  73. data/app/views/foreman_puppet/api/v2/config_groups/base.json.rabl +3 -0
  74. data/app/views/foreman_puppet/api/v2/config_groups/create.json.rabl +3 -0
  75. data/app/views/foreman_puppet/api/v2/config_groups/index.json.rabl +3 -0
  76. data/app/views/foreman_puppet/api/v2/config_groups/main.json.rabl +8 -0
  77. data/app/views/foreman_puppet/api/v2/config_groups/show.json.rabl +3 -0
  78. data/app/views/foreman_puppet/api/v2/config_groups/update.json.rabl +3 -0
  79. data/app/views/foreman_puppet/api/v2/environments/base.json.rabl +3 -0
  80. data/app/views/foreman_puppet/api/v2/environments/create.json.rabl +3 -0
  81. data/app/views/foreman_puppet/api/v2/environments/index.json.rabl +3 -0
  82. data/app/views/foreman_puppet/api/v2/environments/main.json.rabl +5 -0
  83. data/app/views/foreman_puppet/api/v2/environments/show.json.rabl +15 -0
  84. data/app/views/foreman_puppet/api/v2/environments/update.json.rabl +3 -0
  85. data/app/views/foreman_puppet/api/v2/host_puppet_facets/base.json.rabl +1 -0
  86. data/app/views/foreman_puppet/api/v2/host_puppet_facets/host_single.json.rabl +17 -0
  87. data/app/views/foreman_puppet/api/v2/host_puppet_facets/show.json.rabl +11 -0
  88. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/base.json.rabl +5 -0
  89. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/hostgroup_single.json.rabl +16 -0
  90. data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/show.json.rabl +11 -0
  91. data/app/views/foreman_puppet/api/v2/import_puppetclasses/index.json.rabl +3 -0
  92. data/app/views/foreman_puppet/api/v2/import_puppetclasses/show.json.rabl +36 -0
  93. data/app/views/foreman_puppet/api/v2/override_values/create.json.rabl +3 -0
  94. data/app/views/foreman_puppet/api/v2/override_values/index.json.rabl +3 -0
  95. data/app/views/foreman_puppet/api/v2/override_values/show.json.rabl +3 -0
  96. data/app/views/foreman_puppet/api/v2/override_values/update.json.rabl +3 -0
  97. data/app/views/foreman_puppet/api/v2/puppetclasses/base.json.rabl +3 -0
  98. data/app/views/foreman_puppet/api/v2/puppetclasses/create.json.rabl +3 -0
  99. data/app/views/foreman_puppet/api/v2/puppetclasses/index.json.rabl +4 -0
  100. data/app/views/foreman_puppet/api/v2/puppetclasses/list.json.rabl +3 -0
  101. data/app/views/foreman_puppet/api/v2/puppetclasses/main.json.rabl +5 -0
  102. data/app/views/foreman_puppet/api/v2/puppetclasses/show.json.rabl +15 -0
  103. data/app/views/foreman_puppet/api/v2/puppetclasses/update.json.rabl +3 -0
  104. data/app/views/foreman_puppet/api/v2/smart_class_parameters/base.json.rabl +4 -0
  105. data/app/views/foreman_puppet/api/v2/smart_class_parameters/create.json.rabl +3 -0
  106. data/app/views/foreman_puppet/api/v2/smart_class_parameters/destroy.json.rabl +3 -0
  107. data/app/views/foreman_puppet/api/v2/smart_class_parameters/index.json.rabl +3 -0
  108. data/app/views/foreman_puppet/api/v2/smart_class_parameters/main.json.rabl +23 -0
  109. data/app/views/foreman_puppet/api/v2/smart_class_parameters/show.json.rabl +19 -0
  110. data/app/views/foreman_puppet/api/v2/smart_class_parameters/update.json.rabl +3 -0
  111. data/app/views/foreman_puppet/config_groups/_config_group.html.erb +34 -0
  112. data/app/views/foreman_puppet/config_groups/_config_groups_selection.html.erb +36 -0
  113. data/app/views/foreman_puppet/config_groups/_form.html.erb +9 -0
  114. data/app/views/foreman_puppet/config_groups/edit.html.erb +3 -0
  115. data/app/views/foreman_puppet/config_groups/index.html.erb +31 -0
  116. data/app/views/foreman_puppet/config_groups/new.html.erb +3 -0
  117. data/app/views/foreman_puppet/config_groups/welcome.html.erb +12 -0
  118. data/app/views/foreman_puppet/environments/_form.html.erb +20 -0
  119. data/app/views/foreman_puppet/environments/edit.html.erb +8 -0
  120. data/app/views/foreman_puppet/environments/index.html.erb +32 -0
  121. data/app/views/foreman_puppet/environments/new.html.erb +7 -0
  122. data/app/views/foreman_puppet/environments/welcome.html.erb +16 -0
  123. data/app/views/foreman_puppet/layouts/application_react.html.erb +15 -0
  124. data/app/views/foreman_puppet/puppet_smart_proxies/_dashboard.html.erb +9 -0
  125. data/app/views/foreman_puppet/puppet_smart_proxies/_environments.html.erb +30 -0
  126. data/app/views/foreman_puppet/puppetclass_lookup_keys/edit.html.erb +3 -0
  127. data/app/views/foreman_puppet/puppetclass_lookup_keys/index.html.erb +22 -0
  128. data/app/views/foreman_puppet/puppetclass_lookup_keys/welcome.html.erb +9 -0
  129. data/app/views/foreman_puppet/puppetclasses/_class_parameters.html.erb +37 -0
  130. data/app/views/foreman_puppet/puppetclasses/_class_selection.html.erb +70 -0
  131. data/app/views/foreman_puppet/puppetclasses/_classes.html.erb +22 -0
  132. data/app/views/foreman_puppet/puppetclasses/_classes_in_groups.html.erb +5 -0
  133. data/app/views/foreman_puppet/puppetclasses/_classes_parameters.html.erb +16 -0
  134. data/app/views/foreman_puppet/puppetclasses/_form.html.erb +62 -0
  135. data/app/views/foreman_puppet/puppetclasses/_selected_classes.html.erb +4 -0
  136. data/app/views/foreman_puppet/puppetclasses/edit.html.erb +4 -0
  137. data/app/views/foreman_puppet/puppetclasses/index.html.erb +47 -0
  138. data/app/views/hosts/_form_puppet_enc_tab.html.erb +24 -0
  139. data/app/views/hosts/foreman_puppet/_form_main_tab_fields.html.erb +1 -0
  140. data/app/views/hosts/select_multiple_environment.html.erb +8 -0
  141. data/app/views/provisioning_templates/_combination.html.erb +5 -0
  142. data/app/views/provisioning_templates/_combinations.html.erb +6 -0
  143. data/app/views/smart_proxies/plugins/_puppet.html.erb +24 -0
  144. data/config/api_routes.rb +81 -0
  145. data/config/routes.rb +89 -0
  146. data/db/migrate/20101121140000_add_environment_to_template_combinations.foreman_puppet.rb +9 -0
  147. data/db/migrate/20200720123005_migrate_puppet_core_types.foreman_puppet.rb +19 -0
  148. data/db/migrate/20200722171017_create_host_puppet_facet.foreman_puppet.rb +10 -0
  149. data/db/migrate/20200803113531_create_hostgroup_puppet_facet.foreman_puppet.rb +10 -0
  150. data/db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb +22 -0
  151. data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +29 -0
  152. data/db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb +47 -0
  153. data/db/migrate_foreman/20090722141107_create_environments.rb +17 -0
  154. data/db/migrate_foreman/20120905095532_create_environment_classes.rb +15 -0
  155. data/db/migrate_foreman/20140407161817_create_config_groups.rb +9 -0
  156. data/db/migrate_foreman/20140407162007_create_config_group_classes.rb +10 -0
  157. data/db/migrate_foreman/20140407162059_create_host_config_groups.rb +11 -0
  158. data/db/migrate_foreman/20161205142618_delete_orphaned_smart_class_parameters.rb +10 -0
  159. data/db/migrate_foreman/20170109115157_fix_lookup_key_auditable_type.rb +15 -0
  160. data/db/migrate_foreman/20180816134832_cast_lookup_key_values.rb +35 -0
  161. data/db/migrate_foreman/20181023112532_add_environment_puppetclass_id.rb +7 -0
  162. data/db/migrate_foreman/20181224174419_add_index_to_environment_class_by_lookup_key_and_puppetclass.rb +6 -0
  163. data/db/seeds.d/111_puppet_proxy_feature.rb +8 -0
  164. data/lib/foreman_puppet.rb +10 -0
  165. data/lib/foreman_puppet/engine.rb +82 -0
  166. data/lib/foreman_puppet/register.rb +218 -0
  167. data/lib/foreman_puppet/version.rb +3 -0
  168. data/lib/tasks/foreman_puppet_tasks.rake +31 -0
  169. data/locale/Makefile +60 -0
  170. data/locale/action_names.rb +5 -0
  171. data/locale/en/foreman_puppet.edit.po +911 -0
  172. data/locale/en/foreman_puppet.po +690 -0
  173. data/locale/en/foreman_puppet.po.time_stamp +0 -0
  174. data/locale/foreman_puppet.pot +1076 -0
  175. data/locale/gemspec.rb +2 -0
  176. data/test/controllers/foreman_puppet/api/v2/config_groups_controller_test.rb +28 -0
  177. data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +346 -0
  178. data/test/controllers/foreman_puppet/api/v2/host_classes_controller_test.rb +48 -0
  179. data/test/controllers/foreman_puppet/api/v2/hostgroup_classes_controller_test.rb +41 -0
  180. data/test/controllers/foreman_puppet/api/v2/hostgroups_controller_test.rb +79 -0
  181. data/test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb +101 -0
  182. data/test/controllers/foreman_puppet/api/v2/lookups_common_controller_test.rb +29 -0
  183. data/test/controllers/foreman_puppet/api/v2/override_values_controller_test.rb +169 -0
  184. data/test/controllers/foreman_puppet/api/v2/puppetclasses_controller_test.rb +144 -0
  185. data/test/controllers/foreman_puppet/api/v2/smart_class_parameters_controller_test.rb +557 -0
  186. data/test/controllers/foreman_puppet/api/v2/template_combinations_controller_test.rb +81 -0
  187. data/test/controllers/foreman_puppet/config_groups_controller_test.rb +47 -0
  188. data/test/controllers/foreman_puppet/environments_controller_test.rb +230 -0
  189. data/test/controllers/foreman_puppet/hostgroups_controller_test.rb +72 -0
  190. data/test/controllers/foreman_puppet/hosts_controller_test.rb +346 -0
  191. data/test/controllers/foreman_puppet/puppet_smart_proxies_controller_test.rb +29 -0
  192. data/test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb +59 -0
  193. data/test/controllers/foreman_puppet/puppetclasses_controller_test.rb +235 -0
  194. data/test/controllers/provisioning_templates_controller_test.rb +70 -0
  195. data/test/factories/foreman_puppet_factories.rb +134 -0
  196. data/test/factories/host_puppet_enhancements.rb +61 -0
  197. data/test/factories/proxy_puppet_enhancements.rb +33 -0
  198. data/test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb +65 -0
  199. data/test/helpers/foreman_puppet/puppetclasses_helper_test.rb +33 -0
  200. data/test/integration/foreman_puppet/environment_js_test.rb +27 -0
  201. data/test/integration/foreman_puppet/host_js_test.rb +371 -0
  202. data/test/integration/foreman_puppet/hostgroup_js_test.rb +100 -0
  203. data/test/integration/foreman_puppet/puppetclass_js_test.rb +37 -0
  204. data/test/integration/foreman_puppet/smartclass_parameter_js_test.rb +84 -0
  205. data/test/models/foreman_puppet/config_group_class_test.rb +9 -0
  206. data/test/models/foreman_puppet/config_group_test.rb +8 -0
  207. data/test/models/foreman_puppet/environment_test.rb +92 -0
  208. data/test/models/foreman_puppet/host_config_group_test.rb +39 -0
  209. data/test/models/foreman_puppet/host_puppet_facet_test.rb +116 -0
  210. data/test/models/foreman_puppet/host_test.rb +288 -0
  211. data/test/models/foreman_puppet/hostgroup_puppet_facet_test.rb +200 -0
  212. data/test/models/foreman_puppet/hostgroup_test.rb +14 -0
  213. data/test/models/foreman_puppet/lookup_value_test.rb +69 -0
  214. data/test/models/foreman_puppet/provisioning_template_test.rb +124 -0
  215. data/test/models/foreman_puppet/puppetclass_lookup_key_test.rb +81 -0
  216. data/test/models/foreman_puppet/puppetclass_test.rb +144 -0
  217. data/test/models/foreman_puppet/smart_proxy_test.rb +28 -0
  218. data/test/qraphql/queries/host_puppet_query_test.rb +36 -0
  219. data/test/qraphql/queries/hostgroup_puppet_query_test.rb +36 -0
  220. data/test/services/foreman_puppet/host_info_providers/puppet_info_test.rb +791 -0
  221. data/test/services/foreman_puppet/input_type/puppet_parameter_input_test.rb +14 -0
  222. data/test/test_puppet_helper.rb +30 -0
  223. data/test/unit/foreman_puppet/access_permissions_test.rb +16 -0
  224. data/test/unit/foreman_puppet/puppet_class_importer_test.rb +247 -0
  225. data/test/unit/foreman_puppet/template_rendering_test.rb +20 -0
  226. data/test/unit/foreman_puppet_test.rb +11 -0
  227. data/webpack/__mocks__/foremanReact/common/I18n.js +7 -0
  228. data/webpack/__mocks__/foremanReact/components/Layout/LayoutActions.js +2 -0
  229. data/webpack/__mocks__/foremanReact/readme.md +11 -0
  230. data/webpack/__mocks__/foremanReact/redux/API/APISelectors.js +10 -0
  231. data/webpack/__mocks__/foremanReact/redux/API/index.js +10 -0
  232. data/webpack/__mocks__/foremanReact/redux/actions/toasts.js +8 -0
  233. data/webpack/__mocks__/foremanReact/redux/index.js +1 -0
  234. data/webpack/__mocks__/foremanReact/redux/middlewares/IntervalMiddleware.js +5 -0
  235. data/webpack/fills_index.js +30 -0
  236. data/webpack/index.js +18 -0
  237. data/webpack/src/ForemanPuppet.js +11 -0
  238. data/webpack/src/Router/__snapshots__/routes.test.js.snap +3 -0
  239. data/webpack/src/Router/index.js +14 -0
  240. data/webpack/src/Router/routes.js +3 -0
  241. data/webpack/src/Router/routes.test.js +16 -0
  242. data/webpack/src/foreman_class_edit.js +224 -0
  243. data/webpack/src/foreman_puppet_host_form.js +140 -0
  244. data/webpack/src/foreman_puppet_host_form.test.js +65 -0
  245. data/webpack/src/index.js +1 -0
  246. data/webpack/src/reducers.js +7 -0
  247. metadata +340 -0
@@ -0,0 +1,557 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ module Api
5
+ module V2
6
+ class SmartClassParametersControllerTest < ActionController::TestCase
7
+ setup do
8
+ @routes = ForemanPuppet::Engine.routes
9
+ lookup_key
10
+ end
11
+
12
+ let(:environment) { FactoryBot.create(:environment) }
13
+ let(:puppetclass) { FactoryBot.create(:puppetclass) }
14
+ let(:extra_lookup_key_attrs) { {} }
15
+ let(:lookup_key_attrs) { { environment: environment, puppetclass: puppetclass }.merge(extra_lookup_key_attrs) }
16
+ let(:lookup_key) { FactoryBot.create(:puppetclass_lookup_key, lookup_key_attrs) }
17
+
18
+ test 'should get all smart class parameters' do
19
+ FactoryBot.create_list(:puppetclass_lookup_key, 3, environment: environment)
20
+ get :index
21
+ assert_response :success
22
+ assert_not_nil assigns(:smart_class_parameters)
23
+ results = ActiveSupport::JSON.decode(@response.body)
24
+ assert_not results['results'].empty?
25
+ assert_equal 4, results['results'].length
26
+ end
27
+
28
+ test 'should get same smart class parameters in multiple environments once' do
29
+ FactoryBot.create(:environment_class, puppetclass_lookup_key: lookup_key)
30
+ get :index
31
+ assert_response :success
32
+ assert_not_nil assigns(:smart_class_parameters)
33
+ results = ActiveSupport::JSON.decode(@response.body)
34
+ assert_not results['results'].empty?
35
+ assert_equal 1, results['results'].length
36
+ end
37
+
38
+ test 'should get smart class parameters for a specific host' do
39
+ host = FactoryBot.create(:host, :with_puppet_enc, puppetclasses: [puppetclass], environment: environment)
40
+ get :index, params: { host_id: host.to_param }
41
+ assert_response :success
42
+ assert_not_nil assigns(:smart_class_parameters)
43
+ results = ActiveSupport::JSON.decode(@response.body)
44
+ assert_not results['results'].empty?
45
+ assert_equal 1, results['results'].count
46
+ assert_equal lookup_key.key, results['results'][0]['parameter']
47
+ end
48
+
49
+ test 'should get :not_found for a non-existing host' do
50
+ non_existing_id = 100_000
51
+ get :index, params: { host_id: non_existing_id }
52
+ assert_response :not_found
53
+ assert_error_message("Host with id '#{non_existing_id}' was not found")
54
+ end
55
+
56
+ test 'should get smart class parameters for a specific hostgroup' do
57
+ hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, puppetclasses: [puppetclass], environment: environment)
58
+ get :index, params: { hostgroup_id: hostgroup.to_param }
59
+ assert_response :success
60
+ assert_not_nil assigns(:smart_class_parameters)
61
+ results = ActiveSupport::JSON.decode(@response.body)
62
+ assert_not results['results'].empty?
63
+ assert_equal 1, results['results'].count
64
+ assert_equal lookup_key.key, results['results'][0]['parameter']
65
+ end
66
+
67
+ test 'should get :not_found for a non-existing hostgroup' do
68
+ non_existing_id = 100_000
69
+ get :index, params: { hostgroup_id: non_existing_id }
70
+ assert_response :not_found
71
+ assert_error_message("Hostgroup with id '#{non_existing_id}' was not found")
72
+ end
73
+
74
+ test_attributes pid: 'c0378f1e-c215-4f85-892c-d21a8b5a7060'
75
+ test 'should get smart class parameters for a specific puppetclass' do
76
+ get :index, params: { puppetclass_id: puppetclass.id }
77
+ assert_response :success
78
+ assert_not_nil assigns(:smart_class_parameters)
79
+ results = ActiveSupport::JSON.decode(@response.body)
80
+ assert_not results['results'].empty?
81
+ assert_equal 1, results['results'].count
82
+ assert_equal lookup_key.key, results['results'][0]['parameter']
83
+ end
84
+
85
+ test_attributes pid: 'e8b140c0-5c6a-404f-870c-8ebb128830ef'
86
+ test 'list parameters as non admin user' do
87
+ filter1 = FactoryBot.build(:filter)
88
+ filter1.permissions = Permission.where(name: 'view_puppetclasses')
89
+ filter2 = FactoryBot.build(:filter)
90
+ filter2.permissions = Permission.where(name: 'view_external_parameters')
91
+ role = FactoryBot.build(:role)
92
+ role.filters = [filter1, filter2]
93
+ role.save!
94
+ user = FactoryBot.create(:user)
95
+ user.update(roles: [role])
96
+
97
+ as_user user do
98
+ get :index, params: { puppetclass_id: puppetclass.id }
99
+ assert_response :success
100
+ assert_not_nil assigns(:smart_class_parameters)
101
+ results = ActiveSupport::JSON.decode(@response.body)
102
+ assert_not results['results'].empty?
103
+ assert_equal 1, results['results'].count
104
+ assert_equal lookup_key.key, results['results'][0]['parameter']
105
+ end
106
+ end
107
+
108
+ test 'should get same smart class parameters in multiple environments once for a specific puppetclass' do
109
+ FactoryBot.create(:environment_class, puppetclass: puppetclass, puppetclass_lookup_key: lookup_key)
110
+ get :index, params: { puppetclass_id: puppetclass.id }
111
+ assert_response :success
112
+ assert_not_nil assigns(:smart_class_parameters)
113
+ results = ActiveSupport::JSON.decode(@response.body)
114
+ assert_not results['results'].empty?
115
+ assert_equal 1, results['results'].count
116
+ assert_equal lookup_key.key, results['results'][0]['parameter']
117
+ end
118
+
119
+ test 'should get :not_found for a non-existing puppetclass' do
120
+ non_existing_id = 100_000
121
+ get :index, params: { puppetclass_id: non_existing_id }
122
+ assert_response :not_found
123
+ assert_error_message("Puppetclass with id '#{non_existing_id}' was not found")
124
+ end
125
+
126
+ test 'should get smart class parameters for a specific environment' do
127
+ get :index, params: { environment_id: environment.id }
128
+ assert_response :success
129
+ assert_not_nil assigns(:smart_class_parameters)
130
+ results = ActiveSupport::JSON.decode(@response.body)
131
+ assert_not results['results'].empty?
132
+ assert_equal 1, results['results'].count
133
+ assert_equal lookup_key.key, results['results'][0]['parameter']
134
+ end
135
+
136
+ test 'should get :not_found for a non-existing environment' do
137
+ non_existing_id = 100_000
138
+ get :index, params: { environment_id: non_existing_id }
139
+ assert_response :not_found
140
+ assert_error_message("Environment with id '#{non_existing_id}' was not found")
141
+ end
142
+
143
+ test 'should get smart class parameters for a specific environment and puppetclass combination' do
144
+ get :index, params: { environment_id: environment.id, puppetclass_id: puppetclass.id }
145
+ assert_response :success
146
+ assert_not_nil assigns(:smart_class_parameters)
147
+ results = ActiveSupport::JSON.decode(@response.body)
148
+ assert_not results['results'].empty?
149
+ assert_equal 1, results['results'].count
150
+ assert_equal lookup_key.key, results['results'][0]['parameter']
151
+ end
152
+
153
+ test 'should show specific smart class parameter by id' do
154
+ get :show, params: { id: lookup_key.to_param, puppetclass_id: puppetclass.id }
155
+ assert_response :success
156
+ show_response = ActiveSupport::JSON.decode(@response.body)
157
+ assert_not show_response.empty?
158
+ end
159
+
160
+ test 'should show specific smart class parameter by parameter name when it is unique' do
161
+ get :show, params: { id: lookup_key.key }
162
+ assert_response :success
163
+ show_response = ActiveSupport::JSON.decode(@response.body)
164
+ assert_not show_response.empty?
165
+ end
166
+
167
+ test 'should show specific smart class parameter by parameter name even if it is not unique' do
168
+ same_key = FactoryBot.create(:puppetclass_lookup_key, key: lookup_key.key, puppetclass: puppetclass)
169
+ get :show, params: { id: same_key.key, puppetclass_id: puppetclass.id }
170
+ assert_response :success
171
+ show_response = ActiveSupport::JSON.decode(@response.body)
172
+ assert_not show_response.empty?
173
+ end
174
+
175
+ test 'should show puppetclass name and id' do
176
+ get :show, params: { id: lookup_key.key, puppetclass_id: puppetclass.id }
177
+ assert_response :success
178
+ results = ActiveSupport::JSON.decode(@response.body)
179
+ assert_equal puppetclass.name, results['puppetclass_name']
180
+ assert_equal puppetclass.id, results['puppetclass_id']
181
+ end
182
+
183
+ test_attributes pid: '1140c3bf-ab3b-4da6-99fb-9c508cefbbd1'
184
+ test 'should update smart class parameter' do
185
+ orig_value = lookup_key.default_value
186
+ orig_parameter_type = lookup_key.parameter_type
187
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { parameter_type: 'integer',
188
+ default_value: 33_333 } }
189
+ assert_response :success
190
+ lookup_key.reload
191
+ assert_not_equal orig_value, lookup_key.default_value
192
+ assert_not_equal orig_parameter_type, lookup_key.parameter_type
193
+ end
194
+
195
+ context 'without override' do
196
+ let(:extra_lookup_key_attrs) { { override: false } }
197
+
198
+ test_attributes pid: '11d75f6d-7105-4ee8-b147-b8329cae4156'
199
+ test 'should not set avoid duplicates for non supported types' do
200
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
201
+ default_value: RFauxFactory.gen_alpha,
202
+ avoid_duplicates: true } }
203
+ assert_response :internal_server_error, 'Can set avoid duplicated for non supported types'
204
+ assert_error_message('Validation failed: Avoid duplicates can only be set for arrays that have merge_overrides set to true')
205
+ assert_not(lookup_key.reload.avoid_duplicates)
206
+ end
207
+
208
+ test_attributes pid: 'd7b1c336-bd9f-40a3-a573-939f2a021cdc'
209
+ test 'should not set merge overrides for non supported types' do
210
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
211
+ default_value: RFauxFactory.gen_alpha,
212
+ merge_overrides: true } }
213
+ assert_response :internal_server_error, 'Can set merge overrides for non supported types'
214
+ assert_error_message('Validation failed: Merge overrides can only be set for array or hash')
215
+ assert_not(lookup_key.reload.merge_overrides)
216
+ end
217
+
218
+ test_attributes pid: 'fc1ab905-b213-4b67-b886-b10c9cc0379f'
219
+ test 'should not set merge default if merge overrides is not set' do
220
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
221
+ default_value: RFauxFactory.gen_alpha,
222
+ merge_default: true } }
223
+ assert_response :internal_server_error, 'Can set merge default if merge overrides is not set'
224
+ assert_error_message('Validation failed: Merge default can only be set when merge overrides is set')
225
+ assert_not(lookup_key.reload.merge_default)
226
+ end
227
+
228
+ test_attributes pid: 'f4d56d31-ac48-495f-9e56-545f274a060f'
229
+ test 'should not set default value if override is false' do
230
+ assert_not(lookup_key.override)
231
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { default_value: RFauxFactory.gen_alpha } }
232
+ assert_response :internal_server_error, 'Can set default value if override is not set'
233
+ assert_error_message('Validation failed: Override must be true to edit the parameter')
234
+ end
235
+
236
+ test_attributes pid: '7f0ab885-5520-4431-a916-f739c0498a5b'
237
+ test 'should not update parameter data with invalid values' do
238
+ default_value = RFauxFactory.gen_alphanumeric
239
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
240
+ parameter_type: 'boolean',
241
+ default_value: default_value } }
242
+ assert_response :internal_server_error, 'Can set invalid parameter type / default value'
243
+ assert_error_message('Validation failed: Default value is invalid')
244
+ assert_not_equal lookup_key.reload.default_value, default_value
245
+ end
246
+
247
+ test_attributes pid: '75b1dc0b-2287-4b99-b8dc-e50b83355819'
248
+ test 'should not update default value if not in list' do
249
+ default_value = RFauxFactory.gen_alphanumeric
250
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
251
+ default_value: default_value,
252
+ validator_type: 'list',
253
+ validator_rule: '5, test' } }
254
+ assert_response :internal_server_error, 'Can set default value if value not in validator list'
255
+ assert_error_message("Validation failed: Default value #{default_value} is not one of")
256
+ assert_not_equal lookup_key.reload.default_value, default_value
257
+ end
258
+
259
+ test_attributes pid: '99628b78-3037-4c20-95f0-7ce5455093ac'
260
+ test 'should not update default value if not match regexp' do
261
+ default_value = RFauxFactory.gen_alpha
262
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
263
+ default_value: default_value,
264
+ validator_type: 'regexp',
265
+ validator_rule: '[0-9]' } }
266
+ assert_response :internal_server_error, 'Can set default value if value not in validator regexp'
267
+ assert_error_message('Validation failed: Default value is invalid')
268
+ assert_not_equal lookup_key.reload.default_value, default_value
269
+ end
270
+
271
+ test_attributes pid: 'eaa11546-79df-452e-9552-5b2507a27b48'
272
+ test 'should set override' do
273
+ value = RFauxFactory.gen_alpha
274
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true, default_value: value } }
275
+ assert_response :success
276
+ assert(JSON.parse(response.body)['override'])
277
+ assert_equal JSON.parse(response.body)['default_value'], value
278
+ end
279
+ end
280
+
281
+ test_attributes pid: 'e46a12cb-b3ea-42eb-b1bb-b750655b6a4a'
282
+ test 'should not update default type with invalid value' do
283
+ default_value = RFauxFactory.gen_alpha
284
+ FactoryBot.create(:lookup_value, lookup_key: lookup_key, value: RFauxFactory.gen_alpha, match: 'domain=example.com')
285
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { parameter_type: 'boolean',
286
+ default_value: default_value } }
287
+ assert_response :internal_server_error, 'Can set default type with invalid value'
288
+ assert_error_message('Validation failed: Default value is invalid, Lookup values is invalid')
289
+ lookup_key.reload
290
+ assert_not_equal lookup_key.default_value, default_value
291
+ assert_not_equal lookup_key.parameter_type, 'boolean'
292
+ end
293
+
294
+ test_attributes pid: 'a5e89e86-253f-4254-9ebb-eefb3dc2c2ab'
295
+ test 'should not update matcher with value not in list' do
296
+ FactoryBot.create(:lookup_value, lookup_key: lookup_key, value: 'myexample', match: 'domain=example.com')
297
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
298
+ default_value: 50,
299
+ validator_type: 'list',
300
+ validator_rule: '25, example, 50' } }
301
+ assert_error_message('Validation failed: Lookup values is invalid')
302
+ end
303
+
304
+ test_attributes pid: '08820c89-2b93-40f1-be17-0bd38c519e90'
305
+ test 'should not update matcher with value not matching regex' do
306
+ FactoryBot.create(:lookup_value, lookup_key: lookup_key, value: 'myexample', match: 'domain=test.com')
307
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
308
+ default_value: RFauxFactory.gen_numeric_string,
309
+ validator_type: 'regexp',
310
+ validator_rule: '[0-9]' } }
311
+ assert_error_message('Validation failed: Lookup values is invalid')
312
+ end
313
+
314
+ test_attributes pid: '80bf52df-e678-4384-a4d5-7a88928620ce'
315
+ test 'should set avoid duplicates for supported types' do
316
+ put :update, params: { id: lookup_key.id,
317
+ smart_class_parameter: {
318
+ override: true,
319
+ parameter_type: 'array',
320
+ default_value: "[#{RFauxFactory.gen_alpha}, #{RFauxFactory.gen_alpha}]",
321
+ avoid_duplicates: true,
322
+ merge_overrides: true,
323
+ } }
324
+ assert_response :success
325
+ assert(JSON.parse(response.body)['avoid_duplicates'], "Can't set avoid duplicates")
326
+ end
327
+
328
+ test_attributes pid: 'ae1c8e2d-c15d-4325-9aa6-cc6b091fb95a'
329
+ test 'should set merge overrides for supported types' do
330
+ put :update, params: { id: lookup_key.id,
331
+ smart_class_parameter: {
332
+ override: true,
333
+ parameter_type: 'array',
334
+ default_value: "[#{RFauxFactory.gen_alpha}, #{RFauxFactory.gen_alpha}]",
335
+ merge_overrides: true,
336
+ merge_default: true,
337
+ } }
338
+ assert_response :success
339
+ assert(JSON.parse(response.body)['merge_overrides'], "Can't set merge overrides")
340
+ assert(JSON.parse(response.body)['merge_default'], "Can't set merge default")
341
+ end
342
+
343
+ test_attributes pid: 'b6882658-9201-4e87-978a-0195a99ec07d'
344
+ test 'should hide empty default value' do
345
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
346
+ default_value: '',
347
+ hidden_value: true } }
348
+ assert_response :success
349
+ assert(JSON.parse(response.body)['hidden_value?'])
350
+ assert_equal('*****', JSON.parse(response.body)['default_value'])
351
+ get :show, params: { id: lookup_key.id, show_hidden: true }
352
+ assert_equal('', JSON.parse(response.body)['default_value'])
353
+ end
354
+
355
+ test_attributes pid: '0cb8ab59-7910-4573-9dea-2e489d1578d4'
356
+ test 'should hide default value' do
357
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
358
+ default_value: RFauxFactory.gen_alpha,
359
+ hidden_value: true } }
360
+ assert_response :success
361
+ assert(JSON.parse(response.body)['hidden_value?'])
362
+ assert_equal('*****', JSON.parse(response.body)['default_value'])
363
+ end
364
+
365
+ test_attributes pid: '7261b409-b482-41ba-934d-4b724e8113ac'
366
+ test 'should set puppet default' do
367
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true, omit: true } }
368
+ assert_response :success
369
+ assert(JSON.parse(response.body)['omit'])
370
+ end
371
+
372
+ test_attributes pid: '9018d624-07f2-4fb2-b421-8888c7d324a7'
373
+ test 'should remove matcher' do
374
+ lookup_key = FactoryBot.create(:puppetclass_lookup_key, override_value_order: 'is_virtual', puppetclass: puppetclass)
375
+ lookup_value = FactoryBot.create(:lookup_value, lookup_key: lookup_key, value: RFauxFactory.gen_alpha, match: 'is_virtual=true')
376
+ get :show, params: { id: lookup_key.id }
377
+ assert_equal(1, JSON.parse(response.body)['override_values_count'])
378
+ lookup_value.destroy
379
+ get :show, params: { id: lookup_key.id }
380
+ assert_equal(0, JSON.parse(response.body)['override_values_count'])
381
+ end
382
+
383
+ test_attributes pid: '73151830-e902-4b9e-888e-149570869530'
384
+ test 'should unhide default value' do
385
+ value = RFauxFactory.gen_alpha
386
+ lookup_key = FactoryBot.create(:puppetclass_lookup_key, default_value: value, hidden_value: true, puppetclass: puppetclass)
387
+ get :show, params: { id: lookup_key.id }
388
+ assert(JSON.parse(response.body)['hidden_value?'])
389
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { hidden_value: false } }
390
+ assert_response :success
391
+ assert_not(JSON.parse(response.body)['hidden_value?'])
392
+ end
393
+
394
+ test_attributes pid: '6f7ad3c4-7745-45bf-a9f9-697f049556da'
395
+ test 'update hidden value in parameter' do
396
+ old_value = RFauxFactory.gen_alpha
397
+ new_value = RFauxFactory.gen_alpha
398
+ lookup_key = FactoryBot.create(:puppetclass_lookup_key, default_value: old_value, hidden_value: true, puppetclass: puppetclass)
399
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { default_value: new_value } }
400
+ lookup_key.reload
401
+ assert(lookup_key.hidden_value?)
402
+ assert_equal lookup_key.default_value, new_value
403
+ end
404
+
405
+ test_attributes pid: '92977eb0-92c2-4734-84d9-6fda8ff9d2d8'
406
+ test 'validate default value requires check' do
407
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
408
+ required: true,
409
+ parameter_type: 'boolean',
410
+ default_value: true } }
411
+ lookup_key.reload
412
+ assert(lookup_key.required)
413
+ assert(lookup_key.default_value)
414
+ end
415
+
416
+ test_attributes pid: 'd5d5f084-fa62-4ec3-90ea-9fcabd7bda4f'
417
+ test 'validate default value with list' do
418
+ values_list = [RFauxFactory.gen_alpha, RFauxFactory.gen_alphanumeric, rand(100..1 << 64), [true, false].sample]
419
+ values_list_str = values_list.join(', ')
420
+ value = values_list.sample
421
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
422
+ default_value: value,
423
+ validator_type: 'list',
424
+ validator_rule: values_list_str } }
425
+ assert_response :success
426
+ response = JSON.parse(@response.body)
427
+ assert_equal value.to_s, response['default_value']
428
+ assert_equal 'list', response['validator_type']
429
+ assert_equal values_list_str, response['validator_rule']
430
+ end
431
+
432
+ test_attributes pid: 'd5df7804-9633-4ef8-a065-10807351d230'
433
+ test 'validate default value with regexp' do
434
+ value = rand(1..1 << 64)
435
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
436
+ default_value: value,
437
+ validator_type: 'regexp',
438
+ validator_rule: '[0-9]' } }
439
+ assert_response :success
440
+ response = JSON.parse(@response.body)
441
+ assert_equal value.to_s, response['default_value']
442
+ assert_equal 'regexp', response['validator_type']
443
+ assert_equal '[0-9]', response['validator_rule']
444
+ end
445
+
446
+ test_attributes pid: 'bf620cef-c7ab-4a32-9050-bd06040dc8d1'
447
+ test 'should validate matcher required check' do
448
+ value = RFauxFactory.gen_alpha
449
+ lookup_key = FactoryBot.create(:puppetclass_lookup_key, puppetclass: puppetclass)
450
+ FactoryBot.create(:lookup_value, lookup_key: lookup_key, value: value, match: 'domain=example.com')
451
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true, required: true } }
452
+ get :show, params: { id: lookup_key.id }
453
+ assert(JSON.parse(@response.body)['required'])
454
+ assert_equal JSON.parse(@response.body)['override_values'][0]['value'], value
455
+ end
456
+
457
+ test_attributes pid: '77b6e90d-e38a-4973-98e3-c698eae5c534'
458
+ test 'should validate matcher with default type' do
459
+ lookup_key = FactoryBot.create(:puppetclass_lookup_key, :boolean, puppetclass: puppetclass)
460
+ FactoryBot.create(:lookup_value, lookup_key: lookup_key, value: false, match: 'domain=example.com')
461
+ get :show, params: { id: lookup_key.id }
462
+ assert_equal('domain=example.com', JSON.parse(@response.body)['override_values'][0]['match'])
463
+ assert_not(JSON.parse(@response.body)['override_values'][0]['value'])
464
+ end
465
+
466
+ test_attributes pid: '05c1a0bb-ba27-4842-bb6a-8420114cffe7'
467
+ test 'should validate matcher value with list' do
468
+ lookup_key = FactoryBot.create(:puppetclass_lookup_key, puppetclass: puppetclass)
469
+ FactoryBot.create(:lookup_value, lookup_key: lookup_key, value: 30, match: 'domain=example.com')
470
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
471
+ default_value: 'example',
472
+ validator_type: 'list',
473
+ validator_rule: 'test, example, 30' } }
474
+ assert_equal('example', JSON.parse(@response.body)['default_value'])
475
+ end
476
+
477
+ test_attributes pid: '74164406-885b-4f5b-8ea0-06738314310f'
478
+ test 'should validate matcher value with regexp' do
479
+ value = RFauxFactory.gen_numeric_string
480
+ lookup_key = FactoryBot.create(:puppetclass_lookup_key, puppetclass: puppetclass)
481
+ FactoryBot.create(:lookup_value, lookup_key: lookup_key, value: RFauxFactory.gen_numeric_string, match: 'domain=test.com')
482
+ put :update, params: { id: lookup_key.id, smart_class_parameter: { override: true,
483
+ default_value: value,
484
+ validator_type: 'regexp',
485
+ validator_rule: '[0-9]' } }
486
+ assert_equal JSON.parse(@response.body)['default_value'], value
487
+ end
488
+
489
+ test 'should return error if smart class parameter if it does not belong to specified puppetclass' do
490
+ get :show, params: { id: lookup_key.id, puppetclass_id: FactoryBot.create(:puppetclass).id }
491
+ assert_response 404
492
+ # show_response = ActiveSupport::JSON.decode(@response.body)
493
+ # assert !show_response.empty?
494
+ end
495
+
496
+ test 'should get smart parameters with non admin user' do
497
+ setup_user 'view', 'external_parameters'
498
+ get :show, params: { id: lookup_key.id }, session: set_session_user(:one)
499
+ assert_response :success
500
+ end
501
+
502
+ context 'hidden' do
503
+ let(:lookup_key) { FactoryBot.create(:puppetclass_lookup_key, hidden_value: true, default_value: 'hidden', puppetclass: puppetclass) }
504
+
505
+ test 'should show a smart class parameter as hidden unless show_hidden is true' do
506
+ get :show, params: { id: lookup_key.id, puppetclass_id: puppetclass.id }
507
+ show_response = ActiveSupport::JSON.decode(@response.body)
508
+ assert_equal lookup_key.hidden_value, show_response['default_value']
509
+ end
510
+
511
+ test 'should show a smart class parameter unhidden when show_hidden is true' do
512
+ setup_user 'view', 'puppetclasses'
513
+ setup_user 'view', 'external_parameters'
514
+ setup_user 'edit', 'external_parameters'
515
+ get :show, params: { id: lookup_key.id, puppetclass_id: puppetclass.id, show_hidden: 'true' }, session: set_session_user(:one)
516
+ show_response = ActiveSupport::JSON.decode(@response.body)
517
+ assert_equal lookup_key.default_value, show_response['default_value']
518
+ end
519
+
520
+ test 'should show a smart class parameter parameter as hidden when show_hidden is true if user is not authorized' do
521
+ setup_user 'view', 'puppetclasses'
522
+ setup_user 'view', 'external_parameters'
523
+ get :show, params: { id: lookup_key.id, puppetclass_id: puppetclass.id, show_hidden: 'true' }, session: set_session_user(:one)
524
+ show_response = ActiveSupport::JSON.decode(@response.body)
525
+ assert_equal lookup_key.hidden_value, show_response['default_value']
526
+ end
527
+
528
+ test "should show a smart class parameter's overrides unhidden when show_hidden is true" do
529
+ lookup_value = FactoryBot.create(:lookup_value, lookup_key: lookup_key, value: 'abc', match: 'os=fake')
530
+ setup_user 'view', 'puppetclasses'
531
+ setup_user 'view', 'external_parameters'
532
+ setup_user 'edit', 'external_parameters'
533
+ get :show, params: { id: lookup_key.id, puppetclass_id: puppetclass.id, show_hidden: 'true' }, session: set_session_user(:one)
534
+ show_response = ActiveSupport::JSON.decode(@response.body)
535
+ assert_equal lookup_value.value, show_response['override_values'][0]['value']
536
+ end
537
+
538
+ test "should show a smart class parameter's overrides hidden when show_hidden is false" do
539
+ lookup_value = FactoryBot.create(:lookup_value, lookup_key: lookup_key, value: 'abc', match: 'os=fake')
540
+ setup_user 'view', 'puppetclasses'
541
+ setup_user 'view', 'external_parameters'
542
+ setup_user 'edit', 'external_parameters'
543
+ get :show, params: { id: lookup_key.id, puppetclass_id: puppetclass.id, show_hidden: 'false' }, session: set_session_user(:one)
544
+ show_response = ActiveSupport::JSON.decode(@response.body)
545
+ assert_equal lookup_value.hidden_value, show_response['override_values'][0]['value']
546
+ end
547
+ end
548
+
549
+ private
550
+
551
+ def assert_error_message(message)
552
+ assert_includes JSON.parse(response.body)['error']['message'], message
553
+ end
554
+ end
555
+ end
556
+ end
557
+ end