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,29 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ class PuppetSmartProxiesControllerTest < ActionController::TestCase
5
+ setup do
6
+ @routes = ForemanPuppet::Engine.routes
7
+ stub_smart_proxy_v2_features
8
+ end
9
+
10
+ test '#environments' do
11
+ proxy = smart_proxies(:puppetmaster)
12
+ fake_data = { 'env1' => 1, 'special_environment' => 4 }
13
+ ForemanPuppet::ProxyStatus::Puppet.any_instance.expects(:environment_stats).returns(fake_data)
14
+ get :environments, params: { id: proxy.id }, session: set_session_user, xhr: true
15
+ assert_response :success
16
+ assert_template 'foreman_puppet/puppet_smart_proxies/_environments'
17
+ assert_includes @response.body, 'special_environment'
18
+ assert_includes @response.body, '5' # the total is correct
19
+ end
20
+
21
+ test '#dashboard' do
22
+ proxy = smart_proxies(:puppetmaster)
23
+ get :dashboard, params: { id: proxy.id }, session: set_session_user, xhr: true
24
+ assert_response :success
25
+ assert_template 'foreman_puppet/puppet_smart_proxies/_dashboard'
26
+ assert_includes @response.body, 'Latest Events'
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,59 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ class PuppetclassLookupKeysControllerTest < ActionController::TestCase
5
+ setup do
6
+ @routes = ForemanPuppet::Engine.routes
7
+ @factory_options = [{ puppetclass: puppetclasses(:one), override: true, default_value: 'test' }]
8
+ end
9
+
10
+ let(:lookup_key) { FactoryBot.create(:puppetclass_lookup_key, puppetclass: puppetclasses(:one), override: true) }
11
+
12
+ basic_pagination_rendered_test
13
+ basic_pagination_per_page_test
14
+
15
+ test 'should get index' do
16
+ lookup_key # we dont want to render welcome
17
+ get :index, session: set_session_user
18
+ assert_response :success
19
+ assert_not_nil assigns(:lookup_keys)
20
+ end
21
+
22
+ test 'should get edit' do
23
+ get :edit, params: { id: lookup_key.to_param }, session: set_session_user
24
+ assert_response :success
25
+ end
26
+
27
+ test 'should update lookup_keys' do
28
+ put :update, params: { id: lookup_key.to_param, puppetclass_lookup_key: { description: 'test that' } }, session: set_session_user
29
+ assert_equal 'test that', lookup_key.reload.description
30
+ assert_redirected_to puppetclass_lookup_keys_path
31
+ end
32
+
33
+ test 'should destroy lookup_keys' do
34
+ lookup_key
35
+ assert_difference(-> { ForemanPuppet::PuppetclassLookupKey.count }, -1) do
36
+ delete :destroy, params: { id: lookup_key.to_param }, session: set_session_user
37
+ end
38
+ assert_redirected_to puppetclass_lookup_keys_path
39
+ end
40
+
41
+ test 'user with viewer rights should fail to edit an external variable' do
42
+ setup_user
43
+ get :edit, params: { id: lookup_key.id }, session: set_session_user(:one)
44
+ assert_equal(403, response.status)
45
+ end
46
+
47
+ test 'user with viewer rights should succeed in viewing external variables' do
48
+ setup_user
49
+ get :index, session: set_session_user(:one)
50
+ assert_response :success
51
+ end
52
+
53
+ private
54
+
55
+ def setup_user
56
+ users(:one).roles = [Role.default, Role.find_by(name: 'Viewer')]
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,235 @@
1
+ require 'test_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ class PuppetclassesControllerTest < ActionController::TestCase
5
+ include PuppetclassLookupKeysHelper
6
+
7
+ setup do
8
+ @routes = ForemanPuppet::Engine.routes
9
+ end
10
+
11
+ let(:org) { users(:one).organizations.first }
12
+ let(:loc) { users(:one).locations.first }
13
+ let(:environment) { FactoryBot.create(:environment, organizations: [org], locations: [loc]) }
14
+ let(:puppetclass) { FactoryBot.create(:puppetclass, :with_parameters, environments: [environment]) }
15
+
16
+ basic_pagination_rendered_test
17
+ basic_pagination_per_page_test
18
+
19
+ def test_index
20
+ get :index, session: set_session_user
21
+ assert_template 'index'
22
+ end
23
+
24
+ def test_edit
25
+ get :edit, params: { id: puppetclass.to_param }, session: set_session_user
26
+ assert_template 'edit'
27
+ end
28
+
29
+ def test_update_invalid
30
+ put :update, params: { id: puppetclass.to_param, puppetclass: { name: nil } }, session: set_session_user
31
+ assert_template 'edit'
32
+ end
33
+
34
+ def test_update_valid
35
+ put :update, params: { id: puppetclass, puppetclass: { name: 'foo' } }, session: set_session_user
36
+ assert_equal 'foo', puppetclass.reload.name
37
+ assert_redirected_to puppetclasses_url
38
+ end
39
+
40
+ def test_destroy
41
+ delete :destroy, params: { id: puppetclass.to_param }, session: set_session_user
42
+ assert_redirected_to puppetclasses_url
43
+ assert_not Puppetclass.exists?(puppetclass.id)
44
+ end
45
+
46
+ test 'user with viewer rights should fail to edit a puppetclass' do
47
+ setup_user
48
+ get :edit, params: { id: puppetclass.to_param }, session: set_session_user(:one)
49
+ assert_equal(403, @response.status)
50
+ end
51
+
52
+ test 'user with viewer rights should succeed in viewing puppetclasses' do
53
+ setup_user
54
+ get :index, session: set_session_user
55
+ assert_response :success
56
+ end
57
+
58
+ describe '#parameters' do
59
+ setup { puppetclass.class_params.each { |plk| plk.update(override: true) } }
60
+
61
+ test 'new db rows are not added to HostClass when POST to parameters' do
62
+ host = FactoryBot.create(:host, :with_puppet_enc, :with_puppetclass)
63
+ host_puppetclass_ids = host.host_classes.pluck(:puppetclass_id)
64
+ params = { id: puppetclass.id,
65
+ host_id: host.id,
66
+ host: { puppetclass_ids: (host_puppetclass_ids + [puppetclass.id]) } }
67
+ assert_difference('HostClass.count', 0) do
68
+ post :parameters, params: params, session: set_session_user
69
+ end
70
+ end
71
+
72
+ test 'new db rows are not added to HostgroupClass when POST to parameters' do
73
+ skip 'dont know how to achieve for now' unless ForemanPuppet.extracted_from_core?
74
+ hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, :with_puppetclass)
75
+ hostgroup_puppetclass_ids = hostgroup.puppet.hostgroup_classes.pluck(:puppetclass_id)
76
+ params = { id: puppetclass.id,
77
+ host_id: hostgroup.id,
78
+ hostgroup: { puppetclass_ids: (hostgroup_puppetclass_ids + [puppetclass.id]) } }
79
+ assert_difference('ForemanPuppet::HostgroupClass.count', 0) do
80
+ post :parameters, params: params, session: set_session_user
81
+ end
82
+ end
83
+
84
+ # NOTES: for tests below testing ajax POST to method parameters
85
+ # puppetclass(:two) has an overridable lookup key custom_class_param.
86
+ # custom_class_param is a smart_class_param for production environment only AND is marked as :override => TRUE
87
+ test 'puppetclass lookup keys are added to partial _class_parameters on EXISTING host form through ajax POST to parameters' do
88
+ host = FactoryBot.create(:host, :with_puppet_enc, environment: environment)
89
+ existing_host_attributes = host_attributes(host)
90
+ post :parameters, params: { id: puppetclass.id, host_id: host.id,
91
+ host: existing_host_attributes }, session: set_session_user
92
+ assert_response :success
93
+ lookup_keys_added = overridable_puppet_lookup_keys(puppetclass, host)
94
+ assert_equal 1, lookup_keys_added.count
95
+ assert_includes lookup_keys_added.map(&:key), puppetclass.class_params.first.key
96
+ end
97
+
98
+ test 'puppetclass smart class parameters are NOT added if environment does not match' do
99
+ # below is the same test as above, except environment is changed from production to global_puppetmaster, so custom_class_param is NOT added
100
+ host = FactoryBot.create(:host, :with_puppet_enc, environment: environment)
101
+ existing_host_attributes = host_attributes(host)
102
+ existing_host_attributes['puppet_attributes'] = { 'environment_id' => FactoryBot.create(:environment).id }
103
+ post :parameters, params: { id: puppetclass.id, host_id: host.id,
104
+ host: existing_host_attributes }, session: set_session_user
105
+ assert_response :success
106
+ as_admin do
107
+ lookup_keys_added = overridable_puppet_lookup_keys(puppetclass, assigns(:obj))
108
+ assert_equal 0, lookup_keys_added.count
109
+ assert_not lookup_keys_added.map(&:key).include?(puppetclass.class_params.first.key)
110
+ end
111
+ end
112
+
113
+ test 'puppetclass lookup keys are added to partial _class_parameters on EXISTING hostgroup form through ajax POST to parameters' do
114
+ hostgroup = FactoryBot.create(:hostgroup, :with_puppet_enc, environment: environment)
115
+ existing_hostgroup_attributes = hostgroup_attributes(hostgroup)
116
+ # host_id is posted instead of hostgroup_id per host_edit.js#load_puppet_class_parameters
117
+ post :parameters, params: { id: puppetclass.id, host_id: hostgroup.id,
118
+ hostgroup: existing_hostgroup_attributes }, session: set_session_user
119
+ assert_response :success
120
+ as_admin do
121
+ lookup_keys_added = overridable_puppet_lookup_keys(puppetclass, hostgroup)
122
+ assert_equal 1, lookup_keys_added.count
123
+ assert_includes lookup_keys_added.map(&:key), puppetclass.class_params.first.key
124
+ end
125
+ end
126
+
127
+ test 'puppetclass lookup keys are added to partial _class_parameters on NEW host form through ajax POST to parameters' do
128
+ host = Host::Managed.new(name: 'new_host', puppet_attributes: { environment_id: environment.id })
129
+ new_host_attributes = host_attributes(host)
130
+ post :parameters, params: { id: puppetclass.id, host_id: 'undefined',
131
+ host: new_host_attributes }, session: set_session_user
132
+ assert_response :success
133
+ as_admin do
134
+ lookup_keys_added = overridable_puppet_lookup_keys(puppetclass, host)
135
+ assert_equal 1, lookup_keys_added.count
136
+ assert_includes lookup_keys_added.map(&:key), puppetclass.class_params.first.key
137
+ end
138
+ end
139
+
140
+ test 'puppetclass lookup keys are added to partial _class_parameters on NEW hostgroup form through ajax POST to parameters' do
141
+ hostgroup = Hostgroup.new(name: 'new_hostgroup', puppet_attributes: { environment_id: environment.id })
142
+ new_hostgroup_attributes = hostgroup_attributes(hostgroup)
143
+ # host_id is posted instead of hostgroup_id per host_edit.js#load_puppet_class_parameters
144
+ post :parameters, params: { id: puppetclass.id, host_id: 'undefined',
145
+ hostgroup: new_hostgroup_attributes }, session: set_session_user
146
+ assert_response :success
147
+ as_admin do
148
+ lookup_keys_added = overridable_puppet_lookup_keys(puppetclass, hostgroup)
149
+ assert_equal 1, lookup_keys_added.count
150
+ assert_includes lookup_keys_added.map(&:key), puppetclass.class_params.first.key
151
+ end
152
+ end
153
+ end
154
+
155
+ test 'sorting by environment name on the index screen should work' do
156
+ setup_user
157
+ puppetclass
158
+ get :index, params: { order: 'environment ASC' }, session: set_session_user
159
+ assert_includes assigns(:puppetclasses), puppetclass
160
+ end
161
+
162
+ test 'text filtering on the index screen should work' do
163
+ setup_user
164
+ get :index, params: { search: puppetclass.name }, session: set_session_user
165
+ assert_includes assigns(:puppetclasses), puppetclass
166
+ end
167
+
168
+ test 'predicate filtering on the index screen should work' do
169
+ setup_user
170
+ puppetclass
171
+ get :index, params: { search: "environment = #{environment.name}" }, session: set_session_user
172
+ assert_includes assigns(:puppetclasses), puppetclass
173
+ end
174
+
175
+ def test_override_enable
176
+ puppetclass.class_params.first.update(override: false)
177
+ assert_changes -> { puppetclass.class_params.first.reload.override }, from: false, to: true do
178
+ post :override, params: { id: puppetclass.to_param, enable: 'true' }, session: set_session_user
179
+ end
180
+ assert_match(/overridden all parameters/, flash[:success])
181
+ assert_redirected_to puppetclasses_url
182
+ end
183
+
184
+ def test_override_disable
185
+ puppetclass.class_params.first.update(override: true)
186
+ post :override, params: { id: puppetclass.to_param, enable: 'false' }, session: set_session_user
187
+ assert_not puppetclass.class_params.reload.first.override
188
+ assert_match(/reset all parameters/, flash[:success])
189
+ assert_redirected_to puppetclasses_url
190
+ end
191
+
192
+ def test_override_none
193
+ puppetclass = FactoryBot.create(:puppetclass)
194
+ post :override, params: { id: puppetclass.to_param }, session: set_session_user
195
+ assert_match(/No parameters to override/, flash[:error])
196
+ assert_redirected_to puppetclasses_url
197
+ end
198
+
199
+ test 'user with edit_puppetclasses permission should succeed in overriding all parameters' do
200
+ puppetclass.class_params.first.update(override: false)
201
+ setup_user 'edit', 'puppetclasses'
202
+ post :override, params: { id: puppetclass.to_param, enable: 'true' }, session: set_session_user(:one)
203
+ assert_match(/overridden all parameters/, flash[:success])
204
+ assert_redirected_to puppetclasses_url
205
+ end
206
+
207
+ test 'user without edit_puppetclasses permission should fail in overriding all parameters' do
208
+ puppetclass.class_params.first.update(override: false)
209
+ setup_user 'view', 'puppetclasses'
210
+ post :override, params: { id: puppetclass.to_param, enable: 'true' }, session: set_session_user(:one)
211
+ assert_match(/You are not authorized to perform this action/, response.body)
212
+ end
213
+
214
+ private
215
+
216
+ def host_attributes(host)
217
+ known_attrs = HostsController.host_params_filter.accessible_attributes(HostsController.parameter_filter_context)
218
+ host.attributes.except('id', 'created_at', 'updated_at').slice(*known_attrs)
219
+ end
220
+
221
+ def hostgroup_attributes(hostgroup)
222
+ known_attrs = HostgroupsController.hostgroup_params_filter.accessible_attributes(HostgroupsController.parameter_filter_context)
223
+ hostgroup.attributes.except('id', 'created_at', 'updated_at', 'hosts_count', 'ancestry').slice(*known_attrs)
224
+ end
225
+
226
+ def setup_user(operation = nil, type = '', search = nil, user = :one)
227
+ if operation.nil?
228
+ @request.session[:user] = users(:one).id
229
+ users(:one).roles = [Role.default, Role.find_by(name: 'Viewer')]
230
+ else
231
+ super
232
+ end
233
+ end
234
+ end
235
+ end
@@ -0,0 +1,70 @@
1
+ require 'test_puppet_helper'
2
+
3
+ class ProvisioningTemplatesControllerTest < ActionController::TestCase
4
+ let(:environment) { FactoryBot.create(:environment) }
5
+ let(:template_combination) { FactoryBot.create(:template_combination, environment: environment) }
6
+
7
+ context 'templates combinations' do
8
+ test 'can be added on template creation' do
9
+ template_combination = { environment_id: environment.id,
10
+ hostgroup_id: hostgroups(:db).id }
11
+ provisioning_template = {
12
+ name: 'foo',
13
+ template: '#nocontent',
14
+ template_kind_id: TemplateKind.find_by(name: 'iPXE').id,
15
+ template_combinations_attributes: { '3923' => template_combination },
16
+ }
17
+ assert_difference('TemplateCombination.unscoped.count', 1) do
18
+ assert_difference('ProvisioningTemplate.unscoped.count', 1) do
19
+ post :create, params: {
20
+ provisioning_template: provisioning_template,
21
+ }, session: set_session_user
22
+ end
23
+ end
24
+ end
25
+
26
+ context 'for already existing templates' do
27
+ test 'can be edited' do
28
+ new_environment = FactoryBot.create(:environment)
29
+ template = template_combination.provisioning_template
30
+ assert_not_equal new_environment, template_combination.environment
31
+ put :update, params: {
32
+ id: template.to_param,
33
+ provisioning_template: {
34
+ template_combinations_attributes: {
35
+ '0' => {
36
+ id: template_combination.id,
37
+ environment_id: new_environment.id,
38
+ hostgroup_id: template_combination.hostgroup.id,
39
+ },
40
+ },
41
+ },
42
+ }, session: set_session_user
43
+ assert_response :found
44
+ as_admin do
45
+ template_combination.reload
46
+ assert_equal new_environment, template_combination.environment
47
+ end
48
+ end
49
+
50
+ test 'can be destroyed' do
51
+ # create prior the request
52
+ template_combination
53
+ assert_difference('TemplateCombination.count', -1) do
54
+ put :update, params: {
55
+ id: template_combination.provisioning_template.to_param,
56
+ provisioning_template: {
57
+ template_combinations_attributes: {
58
+ '0' => {
59
+ id: template_combination.id,
60
+ _destroy: 1,
61
+ },
62
+ },
63
+ },
64
+ }, session: set_session_user
65
+ end
66
+ assert_response :found
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,134 @@
1
+ FactoryBot.factories.instance_variable_get('@items').delete(:config_group) if FactoryBot.factories.registered?(:config_group)
2
+ FactoryBot.factories.instance_variable_get('@items').delete(:environment) if FactoryBot.factories.registered?(:environment)
3
+ FactoryBot.factories.instance_variable_get('@items').delete(:environment_class) if FactoryBot.factories.registered?(:environment_class)
4
+ FactoryBot.factories.instance_variable_get('@items').delete(:puppetclass) if FactoryBot.factories.registered?(:puppetclass)
5
+ FactoryBot.factories.instance_variable_get('@items').delete(:puppetclass_lookup_key) if FactoryBot.factories.registered?(:puppetclass_lookup_key)
6
+
7
+ def factory_set_environment_taxonomies(puppet_facet, environment = puppet_facet.environment)
8
+ if puppet_facet.is_a? ForemanPuppet::HostgroupPuppetFacet
9
+ organizations = puppet_facet.hostgroup.organizations
10
+ locations = puppet_facet.hostgroup.locations
11
+ else
12
+ organizations = [puppet_facet.host.organization].compact
13
+ locations = [puppet_facet.host.location].compact
14
+ end
15
+ return if environment.nil? || (organizations.empty? && locations.empty?)
16
+ environment.organizations = (environment.organizations + organizations).uniq
17
+ environment.locations = (environment.locations + locations).uniq
18
+ environment.save unless environment.new_record?
19
+ end
20
+
21
+ FactoryBot.define do
22
+ factory :common_puppet_facet do
23
+ environment
24
+ end
25
+
26
+ factory :host_puppet_facet, parent: :common_puppet_facet, class: 'ForemanPuppet::HostPuppetFacet' do
27
+ host
28
+
29
+ trait :with_config_group do
30
+ config_groups { [FactoryBot.create(:config_group, :with_puppetclass, class_environments: [environment])] }
31
+ end
32
+
33
+ after(:build) do |facet|
34
+ factory_set_environment_taxonomies(facet)
35
+ end
36
+ end
37
+
38
+ factory :hostgroup_puppet_facet, parent: :common_puppet_facet, class: 'ForemanPuppet::HostgroupPuppetFacet' do
39
+ hostgroup
40
+
41
+ trait :with_config_group do
42
+ config_groups { [FactoryBot.create(:config_group, :with_puppetclass, class_environments: [environment])] }
43
+ end
44
+
45
+ after(:build) do |facet|
46
+ factory_set_environment_taxonomies(facet)
47
+ end
48
+ end
49
+
50
+ factory :config_group, class: 'ForemanPuppet::ConfigGroup' do
51
+ sequence(:name) { |n| "config_group#{n}" }
52
+ transient do
53
+ class_environments { [] }
54
+ end
55
+
56
+ trait :with_puppetclass do
57
+ puppetclasses { [FactoryBot.create(:puppetclass, environments: class_environments)] }
58
+ end
59
+ end
60
+
61
+ factory :environment, class: 'ForemanPuppet::Environment' do
62
+ sequence(:name) { |n| "environment#{n}" }
63
+ organizations { [Organization.first || create(:organization)] }
64
+ locations { [Location.first || create(:location)] }
65
+
66
+ transient do
67
+ puppetclasses { [] }
68
+ end
69
+
70
+ trait :with_puppetclass do
71
+ transient do
72
+ puppetclasses { [create(:puppetclass)] }
73
+ end
74
+ end
75
+
76
+ after(:create) do |environment, evaluator|
77
+ evaluator.puppetclasses.each do |pc|
78
+ create(:environment_class, environment: environment, puppetclass: pc)
79
+ end
80
+ end
81
+ end
82
+
83
+ factory :environment_class, class: 'ForemanPuppet::EnvironmentClass' do
84
+ environment
85
+ puppetclass
86
+ end
87
+
88
+ factory :puppetclass, class: 'ForemanPuppet::Puppetclass' do
89
+ sequence(:name) { |n| "class#{n}" }
90
+
91
+ transient do
92
+ environments { [] }
93
+ parameter_count { 0 }
94
+ end
95
+
96
+ trait :with_parameters do
97
+ transient do
98
+ environments { [create(:environment)] }
99
+ parameter_count { 1 }
100
+ end
101
+ end
102
+
103
+ after(:create) do |pc, evaluator|
104
+ if evaluator.parameter_count.positive?
105
+ evaluator.parameter_count.times do
106
+ evaluator.environments.each do |env|
107
+ FactoryBot.create :puppetclass_lookup_key, override: false, puppetclass: pc, environment: env
108
+ end
109
+ end
110
+ else
111
+ evaluator.environments.each do |env|
112
+ FactoryBot.create :environment_class, puppetclass: pc, environment: env unless env.nil?
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ factory :puppetclass_lookup_key, parent: :lookup_key, class: 'ForemanPuppet::PuppetclassLookupKey' do
119
+ override { true }
120
+
121
+ transient do
122
+ puppetclass { create(:puppetclass) }
123
+ environment { nil }
124
+ end
125
+
126
+ after(:create) do |lkey, evaluator|
127
+ environments = evaluator.puppetclass.environments.to_a + [evaluator.environment].compact
128
+ environments = [FactoryBot.create(:environment)] unless environments.any?
129
+ environments.each do |env|
130
+ FactoryBot.create :environment_class, puppetclass: evaluator.puppetclass, environment: env, puppetclass_lookup_key_id: lkey.id
131
+ end
132
+ end
133
+ end
134
+ end