foreman_puppet 11.3.0 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79831ddc74b8dd19b92504b30672177d03a555fe0706de935b66bbc8346f1e81
4
- data.tar.gz: c32242bb3a5a5f796976755ccce35bc4a1a8bdbfc77c6f6534e984d8b68580e8
3
+ metadata.gz: 924e6090a5121b071624ff6360c173bf9686d89284dff6928f64f10f5002c122
4
+ data.tar.gz: d1db44c9e6b3e6bea9866575e8deb2e01f788fb4919237c9a613a5459274f20a
5
5
  SHA512:
6
- metadata.gz: 295d5d3cab2df086b6bf756a43215cc0b8369b3fd954cc89f690a26911ff357846ad0d8cfe2b1916ee629abe118a12cf55b4d35c0bcf0a26decd59d96eb11c01
7
- data.tar.gz: 1667f24cf88f09b8eaf28873dec051813ff3d1862a389ed64dbf19d9639f2d5c97ef08d8a23e256abf9118041a87ca44f4e588d5abe6a0f45e08626d6c262bd2
6
+ metadata.gz: 0dde77a63c2f142687bdfd2dfcf1e4007aca227b4a37b72fc77b6dfa76ae3e7e5b1918177a28fad89f941704865e1676bbced7a1fa04b5fb98c2d102fdd50d6e
7
+ data.tar.gz: f511df9dd2656985af72a4ece27ebc348a4390c0ff764bdbbf31d042c4e7650cc3defa58b142f001d6e7ae4678e171eaa855e3d63081ad665236b3c2a2fc1914
data/README.md CHANGED
@@ -78,6 +78,20 @@ if you encounter any bugs/issues using this plugin.
78
78
 
79
79
  Fork and send a Pull Request. Thanks!
80
80
 
81
+ ### JavaScript lint and tests
82
+
83
+ Plugin JavaScript is linted and tested through [Foreman](https://github.com/theforeman/foreman) core (not `tfm-test` / `tfm-lint` in this repository).
84
+
85
+ From the Foreman application directory (with this plugin linked, e.g. via `bundler.d/foreman_puppet.local.rb`):
86
+
87
+ ```bash
88
+ cd /path/to/foreman
89
+ npm run lint:plugins foreman_puppet
90
+ npm run test:plugins foreman_puppet
91
+ npm run test:plugins foreman_puppet -- --watchAll
92
+ npm run test:plugins foreman_puppet -- path/to/test.js
93
+ ```
94
+
81
95
  ## Copyright
82
96
 
83
97
  Copyright (c) *2020-2024* *The Foreman developers*
@@ -1,5 +1,5 @@
1
1
  Foreman::Plugin.register :foreman_puppet do
2
- requires_foreman '>= 5.0'
2
+ requires_foreman '>= 5.1'
3
3
  register_gettext
4
4
 
5
5
  # Add Global JS file for extending foreman-core components and routes
@@ -1,3 +1,3 @@
1
1
  module ForemanPuppet
2
- VERSION = '11.3.0'.freeze
2
+ VERSION = '12.0.0'.freeze
3
3
  end
data/package.json CHANGED
@@ -4,11 +4,6 @@
4
4
  "description": "DESCRIPTION",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "lint": "tfm-lint --plugin -d /webpack",
8
- "test": "tfm-test --plugin",
9
- "test:watch": "tfm-test --plugin --watchAll",
10
- "test:current": "tfm-test --plugin --watch",
11
- "publish-coverage": "tfm-publish-coverage",
12
7
  "create-react-component": "yo react-domain"
13
8
  },
14
9
  "repository": {
@@ -18,22 +13,17 @@
18
13
  "bugs": {
19
14
  "url": "http://projects.theforeman.org/projects/foreman_puppet/issues"
20
15
  },
21
- "peerDependencies": {
22
- "@theforeman/vendor": ">= 10.1.0"
23
- },
24
16
  "devDependencies": {
25
17
  "@babel/core": "^7.7.0",
26
18
  "@sheerun/mutationobserver-shim": "^0.3.3",
27
- "@theforeman/builder": ">= 10.1.0",
28
- "@theforeman/eslint-plugin-foreman": ">= 10.1.0",
29
- "@theforeman/find-foreman": ">= 10.1.0",
30
- "@theforeman/test": ">= 10.1.0",
31
- "@theforeman/vendor-dev": ">= 10.1.0",
32
- "babel-eslint": "^10.0.3",
33
- "eslint": "^6.7.2",
19
+ "babel-eslint": "^10.0.0",
20
+ "eslint": "^6.8.0",
21
+ "eslint-plugin-jquery": "~1.5.1",
22
+ "eslint-plugin-spellcheck": "^0.0.17",
34
23
  "jed": "^1.1.1",
24
+ "jquery": "~3.7.1",
35
25
  "prettier": "^1.19.1",
36
- "stylelint-config-standard": "^18.0.0",
37
- "stylelint": "^9.3.0"
26
+ "stylelint": "^9.3.0",
27
+ "stylelint-config-standard": "^18.0.0"
38
28
  }
39
29
  }
@@ -0,0 +1,37 @@
1
+ require 'integration_puppet_helper'
2
+
3
+ module ForemanPuppet
4
+ class PuppetclassLookupKeysIntegrationTest < ActionDispatch::IntegrationTest
5
+ include ForemanPuppet::Engine.routes.url_helpers
6
+
7
+ test 'saves overrides whose nested form exceeds 4096 parameters' do
8
+ lookup_key = FactoryBot.create(:puppetclass_lookup_key, :integer, path: 'comment')
9
+ values = Array.new(1400) do |index|
10
+ { 'match' => "comment=override#{index}", 'value' => index.to_s, 'omit' => '0' }
11
+ end
12
+ nested_values = values.each_with_index.to_h { |value, index| [index.to_s, value] }
13
+ nested_body = Rack::Utils.build_nested_query(
14
+ 'puppetclass_lookup_key' => { 'lookup_values_attributes' => nested_values },
15
+ '_method' => 'patch'
16
+ )
17
+ assert_operator nested_body.split('&').size, :>, 4096
18
+
19
+ body = Rack::Utils.build_nested_query(
20
+ 'puppetclass_lookup_key' => { 'lookup_values_json' => values.to_json },
21
+ '_method' => 'patch'
22
+ )
23
+
24
+ # An encoded body exercises Rack parsing and method override before routing.
25
+ cookies[:test_user] = users(:admin).login
26
+ post puppetclass_lookup_key_path(lookup_key), params: body,
27
+ headers: { 'CONTENT_TYPE' => 'application/x-www-form-urlencoded' }
28
+
29
+ assert_redirected_to puppetclass_lookup_keys_path
30
+ assert_equal 'PATCH', request.request_method
31
+ overrides = lookup_key.reload.lookup_values
32
+ assert_equal values.size, overrides.count
33
+ assert_equal values.map { |value| [value['match'], value['value'].to_i, false] }.sort,
34
+ overrides.pluck(:match, :value, :omit).sort
35
+ end
36
+ end
37
+ end
@@ -68,6 +68,36 @@ module ForemanPuppet
68
68
  assert page.find('#puppetclass_lookup_key_hidden_value').checked?
69
69
  end
70
70
 
71
+ test 'creates updates removes and omits matcher overrides on the standalone edit page' do
72
+ lookup_key = FactoryBot.create(:puppetclass_lookup_key, :integer, path: 'comment',
73
+ overrides: { 'comment=updated' => 2, 'comment=removed' => 3, 'comment=omitted' => 4 })
74
+ visit edit_puppetclass_lookup_key_path(lookup_key)
75
+ work_around_selenium_file_detector_bug
76
+
77
+ within_matcher('comment=updated') { fill_in 'Value', with: '8' }
78
+ within_matcher('comment=removed') { click_link 'Remove Matcher' }
79
+ within_matcher('comment=omitted') { check }
80
+
81
+ click_link '+ Add Matcher'
82
+ within_matcher('') do
83
+ select 'comment'
84
+ fill_in type: 'text', with: 'added'
85
+ fill_in 'Value', with: '5'
86
+ end
87
+ assert_submit_button(puppetclass_lookup_keys_path)
88
+
89
+ overrides = lookup_key.reload.lookup_values
90
+ assert_equal [['comment=added', 5, false], ['comment=omitted', 4, true], ['comment=updated', 8, false]],
91
+ overrides.pluck(:match, :value, :omit).sort
92
+
93
+ visit edit_puppetclass_lookup_key_path(lookup_key)
94
+ within_matcher('comment=updated') { assert_field 'Value', with: '8' }
95
+ within_matcher('comment=omitted') do
96
+ assert_checked_field
97
+ assert_field 'Value', with: '4', disabled: true
98
+ end
99
+ end
100
+
71
101
  test 'edit page' do
72
102
  FactoryBot.create(:puppetclass_lookup_key, key: 'ssl')
73
103
  visit puppetclass_lookup_keys_path
@@ -81,5 +111,14 @@ module ForemanPuppet
81
111
  assert_submit_button(puppetclass_lookup_keys_path)
82
112
  assert page.has_link? 'ssl'
83
113
  end
114
+
115
+ private
116
+
117
+ def within_matcher(match, &block)
118
+ row = find('tr.matchers') do |candidate|
119
+ candidate.find('input.match', visible: false).value == match
120
+ end
121
+ within(row, &block)
122
+ end
84
123
  end
85
124
  end
@@ -1,69 +1,182 @@
1
1
  import React from 'react';
2
- import { mount } from '@theforeman/test';
2
+ import { act, screen, waitFor } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import '@testing-library/jest-dom';
3
5
 
4
6
  import { openBulkModal } from 'foremanReact/common/BulkModalStateHelper';
5
7
  import { ForemanActionsBarContext } from 'foremanReact/components/HostDetails/ActionsBar';
8
+ import { rtlHelpers } from 'foremanReact/common/rtlTestHelpers';
9
+ import { APIActions } from 'foremanReact/redux/API';
10
+ import API from 'foremanReact/redux/API/API';
6
11
 
7
12
  import BulkChangePuppetCAProxyScene from '../index';
8
- import BulkChangeProxyCommon from '../../BulkChangeProxyCommon';
13
+ import { BULK_CHANGE_PUPPET_CA_PROXY_KEY } from '../../BulkChangeProxyCommon/actions';
9
14
 
10
- jest.mock('foremanReact/components/HostDetails/ActionsBar', () => ({
11
- ForemanActionsBarContext: jest.requireActual('react').createContext(),
12
- }));
15
+ jest.mock('foremanReact/redux/API', () => {
16
+ const actual = jest.requireActual('foremanReact/redux/API');
13
17
 
14
- jest.mock('../../BulkChangeProxyCommon', () => ({
15
- __esModule: true,
16
- default: jest.fn(() => null),
17
- }));
18
-
19
- describe('BulkChangePuppetCAProxyScene', () => {
20
- const fetchBulkParams = jest.fn();
21
- const refreshTableData = jest.fn();
22
- const contextValue = {
23
- selectAllHostsMode: false,
24
- selectedCount: 2,
25
- selectedResults: [1, 2],
26
- fetchBulkParams,
27
- refreshTableData,
18
+ return {
19
+ ...actual,
20
+ APIActions: {
21
+ ...actual.APIActions,
22
+ put: jest.fn(params => ({ type: 'MOCK_API_PUT', payload: params })),
23
+ },
28
24
  };
25
+ });
26
+
27
+ jest.mock('foremanReact/redux/API/APISelectors', () =>
28
+ jest.requireActual('foremanReact/redux/API/APISelectors')
29
+ );
30
+
31
+ const { renderWithStoreAndI18n } = rtlHelpers;
32
+
33
+ const MODAL_ID = 'bulk-change-puppet-ca-proxy';
34
+
35
+ const fetchBulkParams = jest.fn(() => 'id ^ (1,2)');
36
+ const refreshTableData = jest.fn();
37
+
38
+ const defaultContextValue = {
39
+ selectAllHostsMode: false,
40
+ selectedCount: 2,
41
+ selectedResults: [1, 2],
42
+ fetchBulkParams,
43
+ refreshTableData,
44
+ };
45
+
46
+ const smartProxiesResponse = {
47
+ data: {
48
+ results: [{ id: 1, name: 'ca-proxy1.example.com' }],
49
+ },
50
+ };
29
51
 
52
+ const renderScene = ({ contextValue = defaultContextValue } = {}) =>
53
+ renderWithStoreAndI18n(
54
+ <ForemanActionsBarContext.Provider value={contextValue}>
55
+ <BulkChangePuppetCAProxyScene />
56
+ </ForemanActionsBarContext.Provider>
57
+ );
58
+
59
+ const selectPuppetCAProxy = async () => {
60
+ await act(async () => {
61
+ await userEvent.click(await screen.findByText('Select a Puppet CA Proxy'));
62
+ });
63
+ await act(async () => {
64
+ await userEvent.click(screen.getByText('ca-proxy1.example.com'));
65
+ });
66
+ };
67
+
68
+ describe('BulkChangePuppetCAProxyScene', () => {
30
69
  beforeEach(() => {
70
+ openBulkModal(MODAL_ID, false);
71
+ API.get.mockImplementation(() => Promise.resolve(smartProxiesResponse));
72
+ });
73
+
74
+ afterEach(() => {
31
75
  jest.clearAllMocks();
32
- openBulkModal('bulk-change-puppet-ca-proxy', false);
33
76
  });
34
77
 
35
- it('opens with bulk modal state and passes expected CA proxy props', () => {
36
- openBulkModal('bulk-change-puppet-ca-proxy', true);
37
- const wrapper = mount(
38
- <ForemanActionsBarContext.Provider value={contextValue}>
39
- <BulkChangePuppetCAProxyScene />
40
- </ForemanActionsBarContext.Provider>
41
- );
78
+ it('does not show the modal when bulk modal state is closed', () => {
79
+ renderScene();
42
80
 
43
- const componentType =
44
- BulkChangeProxyCommon.default || BulkChangeProxyCommon;
45
- const props = wrapper.find(componentType).props();
81
+ expect(
82
+ screen.queryByRole('dialog', { name: 'Change Puppet CA Proxy' })
83
+ ).not.toBeInTheDocument();
84
+ });
46
85
 
47
- expect(props).toEqual(
86
+ it('opens the modal with Puppet CA Proxy content when bulk modal is open', async () => {
87
+ openBulkModal(MODAL_ID, true);
88
+ renderScene();
89
+
90
+ expect(
91
+ await screen.findByRole('dialog', { name: 'Change Puppet CA Proxy' })
92
+ ).toBeInTheDocument();
93
+ expect(
94
+ screen.getByText(/Changing the Puppet CA proxy will affect/)
95
+ ).toBeInTheDocument();
96
+ expect(screen.getByText('2')).toBeInTheDocument();
97
+ expect(
98
+ await screen.findByText('Select a Puppet CA Proxy')
99
+ ).toBeInTheDocument();
100
+ expect(screen.queryByText('Select a Puppet Proxy')).not.toBeInTheDocument();
101
+ expect(screen.queryByText('Change Puppet Proxy')).not.toBeInTheDocument();
102
+ expect(
103
+ await screen.findByRole('button', { name: 'Change Puppet CA Proxy' })
104
+ ).toBeDisabled();
105
+ expect(screen.getByRole('button', { name: 'Cancel' })).toBeInTheDocument();
106
+ });
107
+
108
+ it('shows the all-hosts warning when select all hosts mode is enabled', async () => {
109
+ openBulkModal(MODAL_ID, true);
110
+ renderScene({
111
+ contextValue: { ...defaultContextValue, selectAllHostsMode: true },
112
+ });
113
+
114
+ await screen.findByRole('dialog', { name: 'Change Puppet CA Proxy' });
115
+ expect(screen.getByText('All')).toBeInTheDocument();
116
+ });
117
+
118
+ it('closes the modal when Cancel is clicked', async () => {
119
+ openBulkModal(MODAL_ID, true);
120
+ renderScene();
121
+
122
+ await screen.findByRole('dialog', { name: 'Change Puppet CA Proxy' });
123
+ await userEvent.click(screen.getByRole('button', { name: 'Cancel' }));
124
+
125
+ await waitFor(() => {
126
+ expect(
127
+ screen.queryByRole('dialog', { name: 'Change Puppet CA Proxy' })
128
+ ).not.toBeInTheDocument();
129
+ });
130
+ });
131
+
132
+ it('submits puppet CA proxy change request when confirm is clicked', async () => {
133
+ openBulkModal(MODAL_ID, true);
134
+ renderScene();
135
+
136
+ await screen.findByRole('dialog', { name: 'Change Puppet CA Proxy' });
137
+ await selectPuppetCAProxy();
138
+ await act(async () => {
139
+ await userEvent.click(
140
+ screen.getByRole('button', { name: 'Change Puppet CA Proxy' })
141
+ );
142
+ });
143
+
144
+ expect(fetchBulkParams).toHaveBeenCalledTimes(1);
145
+ expect(APIActions.put).toHaveBeenCalledWith(
48
146
  expect.objectContaining({
49
- isCAProxy: true,
50
- fetchBulkParams,
51
- selectedCount: 2,
52
- selectedResults: [1, 2],
53
- selectAllHostsMode: false,
54
- isOpen: true,
55
- closeModal: expect.any(Function),
56
- onSuccess: refreshTableData,
57
- selectMessage: 'Select a Puppet CA Proxy',
58
- handleErrorMessage: 'Failed to change Puppet CA Proxy',
59
- changeMessage: 'Change Puppet CA Proxy',
60
- allHostsMessage:
61
- 'Changing the Puppet CA proxy will affect {boldCount} selected hosts. Some hosts may already have been associated with the selected Puppet CA proxy.',
62
- someHostsMessage:
63
- 'Changing the Puppet CA proxy will affect {boldCount} selected {count, plural, one {host} other {hosts}}. Some hosts may already have been associated with the selected Puppet CA proxy.',
147
+ key: BULK_CHANGE_PUPPET_CA_PROXY_KEY,
148
+ params: {
149
+ included: {
150
+ search: 'id ^ (1,2)',
151
+ },
152
+ proxy_id: '1',
153
+ ca_proxy: true,
154
+ },
64
155
  })
65
156
  );
157
+ });
158
+
159
+ it('refreshes table data after successful change', async () => {
160
+ openBulkModal(MODAL_ID, true);
161
+ renderScene();
162
+
163
+ await screen.findByRole('dialog', { name: 'Change Puppet CA Proxy' });
164
+ await selectPuppetCAProxy();
165
+ await act(async () => {
166
+ await userEvent.click(
167
+ screen.getByRole('button', { name: 'Change Puppet CA Proxy' })
168
+ );
169
+ });
170
+
171
+ const { handleSuccess } = APIActions.put.mock.calls[0][0];
172
+
173
+ act(() => {
174
+ handleSuccess({ data: { message: 'Change started' } });
175
+ });
66
176
 
67
- wrapper.unmount();
177
+ expect(refreshTableData).toHaveBeenCalledTimes(1);
178
+ expect(
179
+ screen.queryByRole('dialog', { name: 'Change Puppet CA Proxy' })
180
+ ).not.toBeInTheDocument();
68
181
  });
69
182
  });
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 11.3.0
4
+ version: 12.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondřej Ezr
@@ -321,6 +321,7 @@ files:
321
321
  - test/integration/foreman_puppet/host_js_test.rb
322
322
  - test/integration/foreman_puppet/hostgroup_js_test.rb
323
323
  - test/integration/foreman_puppet/puppetclass_js_test.rb
324
+ - test/integration/foreman_puppet/puppetclass_lookup_keys_test.rb
324
325
  - test/integration/foreman_puppet/smartclass_parameter_js_test.rb
325
326
  - test/integration_puppet_helper.rb
326
327
  - test/models/foreman_puppet/config_group_class_test.rb
@@ -483,6 +484,7 @@ test_files:
483
484
  - test/integration/foreman_puppet/host_js_test.rb
484
485
  - test/integration/foreman_puppet/hostgroup_js_test.rb
485
486
  - test/integration/foreman_puppet/puppetclass_js_test.rb
487
+ - test/integration/foreman_puppet/puppetclass_lookup_keys_test.rb
486
488
  - test/integration/foreman_puppet/smartclass_parameter_js_test.rb
487
489
  - test/integration_puppet_helper.rb
488
490
  - test/models/foreman_puppet/config_group_class_test.rb