foreman_rh_cloud 13.2.10 → 14.0.1
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 +4 -4
- data/app/assets/javascripts/foreman_rh_cloud/locale/fr/foreman_rh_cloud.js +61 -61
- data/app/assets/javascripts/foreman_rh_cloud/locale/ja/foreman_rh_cloud.js +68 -68
- data/app/assets/javascripts/foreman_rh_cloud/locale/ka/foreman_rh_cloud.js +9 -9
- data/app/assets/javascripts/foreman_rh_cloud/locale/ko/foreman_rh_cloud.js +60 -60
- data/app/assets/javascripts/foreman_rh_cloud/locale/zh_CN/foreman_rh_cloud.js +60 -60
- data/app/controllers/concerns/insights_cloud/package_profile_upload_extensions.rb +0 -9
- data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +10 -13
- data/app/controllers/insights_cloud/ui_requests_controller.rb +7 -3
- data/app/models/concerns/rh_cloud_host.rb +3 -35
- data/app/models/insights_client_report_status.rb +1 -9
- data/app/models/inventory_sync/inventory_status.rb +4 -16
- data/app/services/foreman_rh_cloud/insights_api_forwarder.rb +5 -12
- data/lib/foreman_inventory_upload/async/create_missing_insights_facets.rb +2 -8
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +4 -34
- data/lib/foreman_inventory_upload/generators/queries.rb +1 -1
- data/lib/foreman_inventory_upload/generators/slice.rb +1 -1
- data/lib/foreman_inventory_upload.rb +1 -8
- data/lib/foreman_rh_cloud/engine.rb +0 -1
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/foreman_rh_cloud.rb +9 -36
- data/lib/insights_cloud/async/insights_generate_notifications.rb +1 -10
- data/lib/insights_cloud/async/vmaas_reposcan_sync.rb +8 -23
- data/lib/inventory_sync/async/inventory_full_sync.rb +3 -39
- data/lib/inventory_sync/async/inventory_self_host_sync.rb +2 -12
- data/locale/fr/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
- data/locale/fr/foreman_rh_cloud.edit.po +1032 -0
- data/locale/fr/foreman_rh_cloud.po +65 -66
- data/locale/fr/foreman_rh_cloud.po.time_stamp +0 -0
- data/locale/ja/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
- data/locale/ja/foreman_rh_cloud.edit.po +1026 -0
- data/locale/ja/foreman_rh_cloud.po +70 -72
- data/locale/ja/foreman_rh_cloud.po.time_stamp +0 -0
- data/locale/ka/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
- data/locale/ka/foreman_rh_cloud.edit.po +1025 -0
- data/locale/ka/foreman_rh_cloud.po +10 -11
- data/locale/ka/foreman_rh_cloud.po.time_stamp +0 -0
- data/locale/ko/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
- data/locale/ko/foreman_rh_cloud.edit.po +1029 -0
- data/locale/ko/foreman_rh_cloud.po +63 -64
- data/locale/ko/foreman_rh_cloud.po.time_stamp +0 -0
- data/locale/zh_CN/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
- data/locale/zh_CN/foreman_rh_cloud.edit.po +1031 -0
- data/locale/zh_CN/foreman_rh_cloud.po +64 -65
- data/locale/zh_CN/foreman_rh_cloud.po.time_stamp +0 -0
- data/package.json +1 -1
- data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +3 -57
- data/test/controllers/insights_cloud/ui_requests_controller_test.rb +2 -16
- data/test/jobs/insights_client_status_aging_test.rb +0 -40
- data/test/jobs/inventory_full_sync_test.rb +4 -219
- data/test/jobs/inventory_hosts_sync_test.rb +5 -7
- data/test/jobs/inventory_self_host_sync_test.rb +1 -10
- data/test/models/insights_client_report_status_test.rb +0 -109
- data/test/unit/archived_report_generator_test.rb +1 -2
- data/test/unit/fact_helpers_test.rb +0 -16
- data/test/unit/foreman_rh_cloud_self_host_test.rb +2 -50
- data/test/unit/lib/insights_cloud/async/vmaas_reposcan_sync_test.rb +25 -80
- data/test/unit/metadata_generator_test.rb +1 -24
- data/test/unit/rh_cloud_host_test.rb +0 -214
- data/test/unit/services/foreman_rh_cloud/branch_info_test.rb +1 -1
- data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +1 -1
- data/test/unit/slice_generator_test.rb +2 -21
- data/webpack/CVEsHostDetailsTab/CVEsHostDetailsTab.js +3 -30
- data/webpack/CVEsHostDetailsTab/__tests__/CVEsHostDetailsTab.test.js +10 -112
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +1 -3
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +2 -8
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +0 -1
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/integrations.test.js +0 -1
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/Toast.js +17 -43
- data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +0 -7
- data/webpack/ForemanRhCloudHelpers.js +0 -22
- data/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +15 -71
- metadata +16 -18
- data/app/controllers/concerns/insights_cloud/candlepin_proxies_extensions.rb +0 -23
- data/test/controllers/insights_cloud/candlepin_proxies_extensions_test.rb +0 -70
- data/test/jobs/insights_generate_notifications_test.rb +0 -26
- data/test/models/inventory_sync/inventory_status_test.rb +0 -85
- data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/components/__tests__/Toast.test.js +0 -82
- data/webpack/InsightsHostDetailsTab/__tests__/NewHostDetailsTab.test.js +0 -266
|
@@ -5,17 +5,19 @@ class VmaasReposcanSyncTest < ActiveSupport::TestCase
|
|
|
5
5
|
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
|
6
6
|
|
|
7
7
|
setup do
|
|
8
|
-
@
|
|
9
|
-
|
|
10
|
-
@repo =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
@root = FactoryBot.build(:katello_root_repository, :fedora_17_x86_64_dev_root)
|
|
9
|
+
@root.save(validate: false)
|
|
10
|
+
@repo = FactoryBot.create(
|
|
11
|
+
:katello_repository,
|
|
12
|
+
:with_product,
|
|
13
|
+
distribution_family: 'Red Hat',
|
|
14
|
+
distribution_version: '7.5',
|
|
15
|
+
root: @root
|
|
16
|
+
)
|
|
14
17
|
@repo_payload = { id: @repo.id }
|
|
15
18
|
@expected_url = 'https://example.com/api/v1/vmaas/reposcan/sync'
|
|
16
19
|
InsightsCloud.stubs(:vmaas_reposcan_sync_url).returns(@expected_url)
|
|
17
20
|
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
|
|
18
|
-
Organization.stubs(:find).with(@organization.id).returns(@organization)
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
teardown do
|
|
@@ -81,7 +83,7 @@ class VmaasReposcanSyncTest < ActiveSupport::TestCase
|
|
|
81
83
|
params[:url] == @expected_url &&
|
|
82
84
|
params[:headers].is_a?(Hash) &&
|
|
83
85
|
params[:headers]['Content-Type'] == 'application/json' &&
|
|
84
|
-
params[:organization] == @organization
|
|
86
|
+
params[:organization] == @repo.organization
|
|
85
87
|
end
|
|
86
88
|
.returns(mock_response)
|
|
87
89
|
|
|
@@ -114,94 +116,37 @@ class VmaasReposcanSyncTest < ActiveSupport::TestCase
|
|
|
114
116
|
.stubs(:execute_cloud_request)
|
|
115
117
|
.raises(exception)
|
|
116
118
|
|
|
117
|
-
|
|
119
|
+
error = assert_raises(ForemanTasks::TaskError) do
|
|
120
|
+
ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
|
|
121
|
+
end
|
|
118
122
|
|
|
119
|
-
assert_equal 'VMaaS reposcan sync failed: 500 - Server Error', task.output[:message]
|
|
123
|
+
assert_equal 'VMaaS reposcan sync failed: 500 - Server Error', error.task.output[:message]
|
|
120
124
|
end
|
|
121
125
|
|
|
122
126
|
test 'run sets error message in task output for StandardError exception' do
|
|
123
|
-
mock_logger = mock('logger')
|
|
124
|
-
mock_logger.expects(:error).with('Error triggering VMaaS reposcan sync: Network timeout')
|
|
125
|
-
InsightsCloud::Async::VmaasReposcanSync.any_instance.stubs(:logger).returns(mock_logger)
|
|
126
|
-
|
|
127
127
|
InsightsCloud::Async::VmaasReposcanSync.any_instance
|
|
128
128
|
.stubs(:execute_cloud_request)
|
|
129
129
|
.raises(StandardError.new('Network timeout'))
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
test 'run logs and handles error response without raising' do
|
|
137
|
-
error_response = mock('error_response')
|
|
138
|
-
error_response.stubs(:code).returns(500)
|
|
139
|
-
error_response.stubs(:body).returns('error')
|
|
140
|
-
exception = RestClient::ExceptionWithResponse.new(error_response)
|
|
141
|
-
|
|
142
|
-
InsightsCloud::Async::VmaasReposcanSync.any_instance
|
|
143
|
-
.stubs(:execute_cloud_request)
|
|
144
|
-
.raises(exception)
|
|
145
|
-
|
|
146
|
-
task = ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
|
|
147
|
-
|
|
148
|
-
assert_equal 'VMaaS reposcan sync failed: 500 - error', task.output[:message]
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
test 'run handles 429 error with warning log level' do
|
|
152
|
-
error_response = mock('error_response')
|
|
153
|
-
error_response.stubs(:code).returns(429)
|
|
154
|
-
error_response.stubs(:body).returns('{"msg": "Another task already in progress"}')
|
|
155
|
-
exception = RestClient::ExceptionWithResponse.new(error_response)
|
|
156
|
-
|
|
157
|
-
mock_logger = mock('logger')
|
|
158
|
-
mock_logger.expects(:warn).with('VMaaS reposcan sync skipped: another sync already in progress (429)')
|
|
159
|
-
InsightsCloud::Async::VmaasReposcanSync.any_instance.stubs(:logger).returns(mock_logger)
|
|
160
|
-
|
|
161
|
-
InsightsCloud::Async::VmaasReposcanSync.any_instance
|
|
162
|
-
.stubs(:execute_cloud_request)
|
|
163
|
-
.raises(exception)
|
|
164
|
-
|
|
165
|
-
task = ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
|
|
131
|
+
error = assert_raises(ForemanTasks::TaskError) do
|
|
132
|
+
ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
|
|
133
|
+
end
|
|
166
134
|
|
|
167
|
-
|
|
168
|
-
|
|
135
|
+
# The task is available via main_action
|
|
136
|
+
assert_match(/Error triggering VMaaS reposcan sync: Network timeout, response: /,
|
|
137
|
+
error.task.main_action.output[:message])
|
|
169
138
|
end
|
|
170
139
|
|
|
171
|
-
test 'run
|
|
172
|
-
error_response = mock('error_response')
|
|
173
|
-
error_response.stubs(:code).returns(500)
|
|
174
|
-
error_response.stubs(:body).returns('Internal Server Error')
|
|
140
|
+
test 'run logs and re-raises when cloud request returns error response' do
|
|
141
|
+
error_response = mock('error_response', code: 500, body: 'error')
|
|
175
142
|
exception = RestClient::ExceptionWithResponse.new(error_response)
|
|
176
143
|
|
|
177
|
-
mock_logger = mock('logger')
|
|
178
|
-
mock_logger.expects(:error).with('VMaaS reposcan sync failed: 500 - Internal Server Error')
|
|
179
|
-
InsightsCloud::Async::VmaasReposcanSync.any_instance.stubs(:logger).returns(mock_logger)
|
|
180
|
-
|
|
181
144
|
InsightsCloud::Async::VmaasReposcanSync.any_instance
|
|
182
145
|
.stubs(:execute_cloud_request)
|
|
183
146
|
.raises(exception)
|
|
184
147
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
task.output[:message]
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
test 'run handles RestClient::ExceptionWithResponse with nil response' do
|
|
192
|
-
exception = RestClient::ExceptionWithResponse.new(nil)
|
|
193
|
-
|
|
194
|
-
mock_logger = mock('logger')
|
|
195
|
-
mock_logger.expects(:error).with('VMaaS reposcan sync failed: - ')
|
|
196
|
-
InsightsCloud::Async::VmaasReposcanSync.any_instance.stubs(:logger).returns(mock_logger)
|
|
197
|
-
|
|
198
|
-
InsightsCloud::Async::VmaasReposcanSync.any_instance
|
|
199
|
-
.stubs(:execute_cloud_request)
|
|
200
|
-
.raises(exception)
|
|
201
|
-
|
|
202
|
-
task = ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
|
|
203
|
-
|
|
204
|
-
refute_nil task.output[:message]
|
|
205
|
-
assert_equal 'VMaaS reposcan sync failed: - ', task.output[:message]
|
|
148
|
+
assert_raises(ForemanTasks::TaskError) do
|
|
149
|
+
ForemanTasks.sync_task(InsightsCloud::Async::VmaasReposcanSync, @repo_payload)
|
|
150
|
+
end
|
|
206
151
|
end
|
|
207
152
|
end
|
|
@@ -2,8 +2,7 @@ require 'test_plugin_helper'
|
|
|
2
2
|
|
|
3
3
|
class MetadataGeneratorTest < ActiveSupport::TestCase
|
|
4
4
|
setup do
|
|
5
|
-
|
|
6
|
-
ForemanRhCloud.remove_instance_variable(:@foreman_host) if ForemanRhCloud.instance_variable_defined?(:@foreman_host)
|
|
5
|
+
ForemanRhCloud.instance_variable_set(:@foreman_host, nil)
|
|
7
6
|
end
|
|
8
7
|
|
|
9
8
|
test 'generates an empty report' do
|
|
@@ -65,26 +64,4 @@ class MetadataGeneratorTest < ActiveSupport::TestCase
|
|
|
65
64
|
assert_not_nil(slice = slices['test_12345'])
|
|
66
65
|
assert_equal 3, slice['number_hosts']
|
|
67
66
|
end
|
|
68
|
-
|
|
69
|
-
test 'generates metadata when foreman_host is nil' do
|
|
70
|
-
ForemanRhCloud.stubs(:foreman_host).returns(nil)
|
|
71
|
-
ForemanRhCloud.stubs(:foreman_host_name).returns('satellite.example.com')
|
|
72
|
-
|
|
73
|
-
generator = ForemanInventoryUpload::Generators::Metadata.new
|
|
74
|
-
|
|
75
|
-
# Should not raise an error
|
|
76
|
-
json_str = nil
|
|
77
|
-
assert_nothing_raised do
|
|
78
|
-
json_str = generator.render do
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# Verify hostname is from foreman_host_name
|
|
83
|
-
actual = JSON.parse(json_str.join("\n"))
|
|
84
|
-
assert_equal 'satellite.example.com', actual['reporting_host_name']
|
|
85
|
-
# Verify IP and BIOS UUID fields are nil when host is nil
|
|
86
|
-
# This is acceptable per SAT-25889 - cloud services don't rely on these fields
|
|
87
|
-
assert_nil actual['reporting_host_ips']
|
|
88
|
-
assert_nil actual['reporting_host_bios_uuid']
|
|
89
|
-
end
|
|
90
67
|
end
|
|
@@ -188,218 +188,4 @@ class RhCloudHostTest < ActiveSupport::TestCase
|
|
|
188
188
|
assert_equal local_uuid, @host.insights_uuid
|
|
189
189
|
end
|
|
190
190
|
end
|
|
191
|
-
|
|
192
|
-
context 'scoped search on insights_uuid' do
|
|
193
|
-
setup do
|
|
194
|
-
@org = FactoryBot.create(:organization)
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
teardown do
|
|
198
|
-
ForemanRhCloud.unstub(:with_iop_smart_proxy?)
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
test 'searches insights_facet.uuid in non-IoP mode with = operator' do
|
|
202
|
-
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(false)
|
|
203
|
-
host1 = FactoryBot.create(:host, :managed, organization: @org)
|
|
204
|
-
host1.insights = FactoryBot.create(:insights_facet, host_id: host1.id, uuid: 'insights-uuid-123')
|
|
205
|
-
host2 = FactoryBot.create(:host, :managed, organization: @org)
|
|
206
|
-
host2.insights = FactoryBot.create(:insights_facet, host_id: host2.id, uuid: 'insights-uuid-456')
|
|
207
|
-
|
|
208
|
-
results = Host::Managed.search_for('insights_uuid = insights-uuid-123')
|
|
209
|
-
|
|
210
|
-
assert_includes results, host1
|
|
211
|
-
assert_not_includes results, host2
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
test 'searches subscription_facet.uuid in IoP mode with = operator' do
|
|
215
|
-
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
|
|
216
|
-
host1 = FactoryBot.create(:host, :managed, :with_subscription, organization: @org)
|
|
217
|
-
host2 = FactoryBot.create(:host, :managed, :with_subscription, organization: @org)
|
|
218
|
-
|
|
219
|
-
# Even if insights_facet has different UUID, should use subscription_facet UUID
|
|
220
|
-
host1.insights = FactoryBot.create(:insights_facet, host_id: host1.id, uuid: 'stale-123')
|
|
221
|
-
|
|
222
|
-
results = Host::Managed.search_for("insights_uuid = #{host1.subscription_facet.uuid}")
|
|
223
|
-
|
|
224
|
-
assert_includes results, host1
|
|
225
|
-
assert_not_includes results, host2
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
test 'searches with ^ operator (IN) in non-IoP mode' do
|
|
229
|
-
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(false)
|
|
230
|
-
host1 = FactoryBot.create(:host, :managed, organization: @org)
|
|
231
|
-
host1.insights = FactoryBot.create(:insights_facet, host_id: host1.id, uuid: 'uuid-1')
|
|
232
|
-
host2 = FactoryBot.create(:host, :managed, organization: @org)
|
|
233
|
-
host2.insights = FactoryBot.create(:insights_facet, host_id: host2.id, uuid: 'uuid-2')
|
|
234
|
-
host3 = FactoryBot.create(:host, :managed, organization: @org)
|
|
235
|
-
host3.insights = FactoryBot.create(:insights_facet, host_id: host3.id, uuid: 'uuid-3')
|
|
236
|
-
|
|
237
|
-
results = Host::Managed.search_for('insights_uuid ^ (uuid-1,uuid-2)')
|
|
238
|
-
|
|
239
|
-
assert_includes results, host1
|
|
240
|
-
assert_includes results, host2
|
|
241
|
-
assert_not_includes results, host3
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
test 'searches with ^ operator (IN) in IoP mode - THE BUG FIX' do
|
|
245
|
-
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
|
|
246
|
-
host1 = FactoryBot.create(:host, :managed, :with_subscription, organization: @org)
|
|
247
|
-
host2 = FactoryBot.create(:host, :managed, :with_subscription, organization: @org)
|
|
248
|
-
host3 = FactoryBot.create(:host, :managed, :with_subscription, organization: @org)
|
|
249
|
-
|
|
250
|
-
# Create insights facets with stale UUIDs to verify we're using subscription_facet
|
|
251
|
-
host1.insights = FactoryBot.create(:insights_facet, host_id: host1.id, uuid: 'stale-1')
|
|
252
|
-
host2.insights = FactoryBot.create(:insights_facet, host_id: host2.id, uuid: 'stale-2')
|
|
253
|
-
host3.insights = FactoryBot.create(:insights_facet, host_id: host3.id, uuid: 'stale-3')
|
|
254
|
-
|
|
255
|
-
uuid1 = host1.subscription_facet.uuid
|
|
256
|
-
uuid2 = host2.subscription_facet.uuid
|
|
257
|
-
|
|
258
|
-
# This is the search query that remediation modal creates
|
|
259
|
-
results = Host::Managed.search_for("insights_uuid ^ (#{uuid1},#{uuid2})")
|
|
260
|
-
|
|
261
|
-
# Should find hosts by subscription_facet UUID, not insights_facet UUID
|
|
262
|
-
assert_includes results, host1
|
|
263
|
-
assert_includes results, host2
|
|
264
|
-
assert_not_includes results, host3
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
test 'searches with !^ operator (NOT IN) in non-IoP mode' do
|
|
268
|
-
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(false)
|
|
269
|
-
host1 = FactoryBot.create(:host, :managed, organization: @org)
|
|
270
|
-
host1.insights = FactoryBot.create(:insights_facet, host_id: host1.id, uuid: 'uuid-1')
|
|
271
|
-
host2 = FactoryBot.create(:host, :managed, organization: @org)
|
|
272
|
-
host2.insights = FactoryBot.create(:insights_facet, host_id: host2.id, uuid: 'uuid-2')
|
|
273
|
-
host3 = FactoryBot.create(:host, :managed, organization: @org)
|
|
274
|
-
host3.insights = FactoryBot.create(:insights_facet, host_id: host3.id, uuid: 'uuid-3')
|
|
275
|
-
|
|
276
|
-
results = Host::Managed.search_for('insights_uuid !^ (uuid-1,uuid-2)')
|
|
277
|
-
|
|
278
|
-
assert_not_includes results, host1
|
|
279
|
-
assert_not_includes results, host2
|
|
280
|
-
assert_includes results, host3
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
test 'searches with !^ operator (NOT IN) in IoP mode' do
|
|
284
|
-
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
|
|
285
|
-
host1 = FactoryBot.create(:host, :managed, :with_subscription, organization: @org)
|
|
286
|
-
host2 = FactoryBot.create(:host, :managed, :with_subscription, organization: @org)
|
|
287
|
-
host3 = FactoryBot.create(:host, :managed, :with_subscription, organization: @org)
|
|
288
|
-
|
|
289
|
-
uuid1 = host1.subscription_facet.uuid
|
|
290
|
-
uuid2 = host2.subscription_facet.uuid
|
|
291
|
-
|
|
292
|
-
results = Host::Managed.search_for("insights_uuid !^ (#{uuid1},#{uuid2})")
|
|
293
|
-
|
|
294
|
-
assert_not_includes results, host1
|
|
295
|
-
assert_not_includes results, host2
|
|
296
|
-
assert_includes results, host3
|
|
297
|
-
end
|
|
298
|
-
|
|
299
|
-
test 'handles hosts without facets in non-IoP mode' do
|
|
300
|
-
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(false)
|
|
301
|
-
host_without_facet = FactoryBot.create(:host, :managed, organization: @org)
|
|
302
|
-
host_with_facet = FactoryBot.create(:host, :managed, organization: @org)
|
|
303
|
-
host_with_facet.insights = FactoryBot.create(:insights_facet, host_id: host_with_facet.id, uuid: 'uuid-1')
|
|
304
|
-
|
|
305
|
-
results = Host::Managed.search_for('insights_uuid = uuid-1')
|
|
306
|
-
|
|
307
|
-
assert_includes results, host_with_facet
|
|
308
|
-
assert_not_includes results, host_without_facet
|
|
309
|
-
end
|
|
310
|
-
|
|
311
|
-
test 'handles hosts without subscription_facet in IoP mode' do
|
|
312
|
-
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
|
|
313
|
-
host_without_sub = FactoryBot.create(:host, :managed, organization: @org)
|
|
314
|
-
host_with_sub = FactoryBot.create(:host, :managed, :with_subscription, organization: @org)
|
|
315
|
-
|
|
316
|
-
uuid = host_with_sub.subscription_facet.uuid
|
|
317
|
-
|
|
318
|
-
results = Host::Managed.search_for("insights_uuid = #{uuid}")
|
|
319
|
-
|
|
320
|
-
assert_includes results, host_with_sub
|
|
321
|
-
assert_not_includes results, host_without_sub
|
|
322
|
-
end
|
|
323
|
-
|
|
324
|
-
test 'mode changes are reflected in searches' do
|
|
325
|
-
host1 = FactoryBot.create(:host, :managed, :with_subscription, organization: @org)
|
|
326
|
-
host1.insights = FactoryBot.create(:insights_facet, host_id: host1.id, uuid: 'insights-uuid-abc')
|
|
327
|
-
insights_uuid = 'insights-uuid-abc'
|
|
328
|
-
subscription_uuid = host1.subscription_facet.uuid
|
|
329
|
-
|
|
330
|
-
# Non-IoP mode: should find by insights_facet UUID
|
|
331
|
-
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(false)
|
|
332
|
-
results = Host::Managed.search_for("insights_uuid = #{insights_uuid}")
|
|
333
|
-
assert_includes results, host1
|
|
334
|
-
|
|
335
|
-
# IoP mode: should find by subscription_facet UUID
|
|
336
|
-
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
|
|
337
|
-
results = Host::Managed.search_for("insights_uuid = #{subscription_uuid}")
|
|
338
|
-
assert_includes results, host1
|
|
339
|
-
|
|
340
|
-
# Should NOT find by old insights_facet UUID in IoP mode
|
|
341
|
-
results = Host::Managed.search_for("insights_uuid = #{insights_uuid}")
|
|
342
|
-
assert_not_includes results, host1
|
|
343
|
-
end
|
|
344
|
-
end
|
|
345
|
-
|
|
346
|
-
test 'scoped search for user_omitted inventory status works' do
|
|
347
|
-
host1 = FactoryBot.create(:host, :managed)
|
|
348
|
-
host2 = FactoryBot.create(:host, :managed)
|
|
349
|
-
host3 = FactoryBot.create(:host, :managed)
|
|
350
|
-
|
|
351
|
-
# Create different inventory statuses
|
|
352
|
-
InventorySync::InventoryStatus.create!(
|
|
353
|
-
host_id: host1.id,
|
|
354
|
-
status: InventorySync::InventoryStatus::SYNC,
|
|
355
|
-
reported_at: Time.zone.now
|
|
356
|
-
)
|
|
357
|
-
|
|
358
|
-
InventorySync::InventoryStatus.create!(
|
|
359
|
-
host_id: host2.id,
|
|
360
|
-
status: InventorySync::InventoryStatus::DISCONNECT,
|
|
361
|
-
reported_at: Time.zone.now
|
|
362
|
-
)
|
|
363
|
-
|
|
364
|
-
InventorySync::InventoryStatus.create!(
|
|
365
|
-
host_id: host3.id,
|
|
366
|
-
status: InventorySync::InventoryStatus::USER_OMITTED,
|
|
367
|
-
reported_at: Time.zone.now
|
|
368
|
-
)
|
|
369
|
-
|
|
370
|
-
# Search for user_omitted status
|
|
371
|
-
results = Host.search_for('insights_inventory_sync_status = user_omitted')
|
|
372
|
-
result_ids = results.pluck(:id)
|
|
373
|
-
|
|
374
|
-
assert_includes result_ids, host3.id, 'Host with USER_OMITTED status should be in search results'
|
|
375
|
-
assert_not_includes result_ids, host1.id, 'Host with SYNC status should not be in search results'
|
|
376
|
-
assert_not_includes result_ids, host2.id, 'Host with DISCONNECT status should not be in search results'
|
|
377
|
-
end
|
|
378
|
-
|
|
379
|
-
test 'scoped search for user_omitted insights client report status works' do
|
|
380
|
-
host1 = FactoryBot.create(:host, :managed)
|
|
381
|
-
host2 = FactoryBot.create(:host, :managed)
|
|
382
|
-
host3 = FactoryBot.create(:host, :managed)
|
|
383
|
-
|
|
384
|
-
# Create different insights client report statuses
|
|
385
|
-
status1 = host1.get_status(InsightsClientReportStatus)
|
|
386
|
-
status1.status = InsightsClientReportStatus::REPORTING
|
|
387
|
-
status1.save!
|
|
388
|
-
|
|
389
|
-
status2 = host2.get_status(InsightsClientReportStatus)
|
|
390
|
-
status2.status = InsightsClientReportStatus::NO_REPORT
|
|
391
|
-
status2.save!
|
|
392
|
-
|
|
393
|
-
status3 = host3.get_status(InsightsClientReportStatus)
|
|
394
|
-
status3.status = InsightsClientReportStatus::USER_OMITTED
|
|
395
|
-
status3.save!
|
|
396
|
-
|
|
397
|
-
# Search for user_omitted status
|
|
398
|
-
results = Host.search_for('insights_client_report_status = user_omitted')
|
|
399
|
-
result_ids = results.pluck(:id)
|
|
400
|
-
|
|
401
|
-
assert_includes result_ids, host3.id, 'Host with USER_OMITTED status should be in search results'
|
|
402
|
-
assert_not_includes result_ids, host1.id, 'Host with REPORTING status should not be in search results'
|
|
403
|
-
assert_not_includes result_ids, host2.id, 'Host with NO_REPORT status should not be in search results'
|
|
404
|
-
end
|
|
405
191
|
end
|
|
@@ -19,7 +19,7 @@ class BranchInfoTest < ActiveSupport::TestCase
|
|
|
19
19
|
organization: env.organization
|
|
20
20
|
)
|
|
21
21
|
|
|
22
|
-
@host.
|
|
22
|
+
@host.organization.pools << FactoryBot.create(:katello_pool, account_number: '5678', cp_id: 1)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
test 'should generate branch info for host' do
|
|
@@ -29,7 +29,7 @@ class CloudRequestForwarderTest < ActiveSupport::TestCase
|
|
|
29
29
|
organization: env.organization
|
|
30
30
|
)
|
|
31
31
|
|
|
32
|
-
@host.
|
|
32
|
+
@host.organization.pools << FactoryBot.create(:katello_pool, account_number: '5678', cp_id: 1)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
test 'should prepare correct cloud url' do
|
|
@@ -641,6 +641,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
|
|
|
641
641
|
assert_tag('1', actual_host, 'int_param', 'satellite_parameter')
|
|
642
642
|
|
|
643
643
|
assert_equal false, satellite_facts['is_hostname_obfuscated']
|
|
644
|
+
assert_equal true, satellite_facts['is_simple_content_access']
|
|
644
645
|
|
|
645
646
|
version = satellite_facts['satellite_version']
|
|
646
647
|
if defined?(ForemanThemeSatellite)
|
|
@@ -702,22 +703,6 @@ class SliceGeneratorTest < ActiveSupport::TestCase
|
|
|
702
703
|
assert_equal 'test_sla', fact_values['system_purpose_sla']
|
|
703
704
|
end
|
|
704
705
|
|
|
705
|
-
test 'generates a report for a golden ticket' do
|
|
706
|
-
batch = Host.where(id: @host.id).in_batches.first
|
|
707
|
-
generator = create_generator(batch) do |generator|
|
|
708
|
-
generator.stubs(:golden_ticket?).returns(true)
|
|
709
|
-
end
|
|
710
|
-
|
|
711
|
-
json_str = generator.render
|
|
712
|
-
actual = JSON.parse(json_str.join("\n"))
|
|
713
|
-
|
|
714
|
-
assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
|
|
715
|
-
assert_not_nil(actual_host = actual['hosts'].first)
|
|
716
|
-
assert_equal @host.fqdn, actual_host['fqdn']
|
|
717
|
-
assert_equal '1234', actual_host['account']
|
|
718
|
-
assert_equal 1, generator.hosts_count
|
|
719
|
-
end
|
|
720
|
-
|
|
721
706
|
test 'skips hosts without subscription' do
|
|
722
707
|
a_host = FactoryBot.create(
|
|
723
708
|
:host,
|
|
@@ -1131,11 +1116,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
|
|
|
1131
1116
|
|
|
1132
1117
|
def create_generator(batch, name = '00000000-0000-0000-0000-000000000000')
|
|
1133
1118
|
generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], name)
|
|
1134
|
-
if block_given?
|
|
1135
|
-
yield(generator)
|
|
1136
|
-
else
|
|
1137
|
-
generator.stubs(:golden_ticket?).returns(false)
|
|
1138
|
-
end
|
|
1119
|
+
yield(generator) if block_given?
|
|
1139
1120
|
generator
|
|
1140
1121
|
end
|
|
1141
1122
|
|
|
@@ -3,10 +3,6 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import { ScalprumComponent, ScalprumProvider } from '@scalprum/react-core';
|
|
4
4
|
import { createProviderOptions } from '../common/ScalprumModule/ScalprumContext';
|
|
5
5
|
import { useInsightsPermissions } from '../common/Hooks/PermissionsHooks';
|
|
6
|
-
import {
|
|
7
|
-
vulnerabilityDisabled,
|
|
8
|
-
useTabRedirect,
|
|
9
|
-
} from '../ForemanRhCloudHelpers';
|
|
10
6
|
import './CVEsHostDetailsTab.scss';
|
|
11
7
|
|
|
12
8
|
const CVEsHostDetailsTab = ({ systemId }) => {
|
|
@@ -14,12 +10,7 @@ const CVEsHostDetailsTab = ({ systemId }) => {
|
|
|
14
10
|
const module = './SystemDetailTable';
|
|
15
11
|
return (
|
|
16
12
|
<div className="rh-cloud-insights-vulnerability-host-details-component vulnerability">
|
|
17
|
-
<ScalprumComponent
|
|
18
|
-
key={systemId}
|
|
19
|
-
scope={scope}
|
|
20
|
-
module={module}
|
|
21
|
-
systemId={systemId}
|
|
22
|
-
/>
|
|
13
|
+
<ScalprumComponent scope={scope} module={module} systemId={systemId} />
|
|
23
14
|
</div>
|
|
24
15
|
);
|
|
25
16
|
};
|
|
@@ -30,15 +21,6 @@ CVEsHostDetailsTab.propTypes = {
|
|
|
30
21
|
|
|
31
22
|
const CVEsHostDetailsTabWrapper = ({ response }) => {
|
|
32
23
|
const permissions = useInsightsPermissions();
|
|
33
|
-
const isHostDataLoaded = Boolean(response?.id);
|
|
34
|
-
const shouldHideTab = useTabRedirect(
|
|
35
|
-
isHostDataLoaded && vulnerabilityDisabled({ hostDetails: response })
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
if (shouldHideTab) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
24
|
return (
|
|
43
25
|
<ScalprumProvider {...createProviderOptions(permissions)}>
|
|
44
26
|
<CVEsHostDetailsTab
|
|
@@ -51,19 +33,10 @@ const CVEsHostDetailsTabWrapper = ({ response }) => {
|
|
|
51
33
|
|
|
52
34
|
CVEsHostDetailsTabWrapper.propTypes = {
|
|
53
35
|
response: PropTypes.shape({
|
|
54
|
-
id: PropTypes.number,
|
|
55
|
-
operatingsystem_name: PropTypes.string,
|
|
56
|
-
vulnerability: PropTypes.shape({
|
|
57
|
-
enabled: PropTypes.bool,
|
|
58
|
-
}),
|
|
59
36
|
subscription_facet_attributes: PropTypes.shape({
|
|
60
|
-
uuid: PropTypes.string,
|
|
37
|
+
uuid: PropTypes.string.isRequired,
|
|
61
38
|
}),
|
|
62
|
-
}),
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
CVEsHostDetailsTabWrapper.defaultProps = {
|
|
66
|
-
response: {},
|
|
39
|
+
}).isRequired,
|
|
67
40
|
};
|
|
68
41
|
|
|
69
42
|
export default CVEsHostDetailsTabWrapper;
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
|
-
import { MemoryRouter } from 'react-router-dom';
|
|
4
3
|
import CVEsHostDetailsTabWrapper from '../CVEsHostDetailsTab';
|
|
5
|
-
import { OVERVIEW_TAB_PATH } from '../../ForemanRhCloudHelpers';
|
|
6
|
-
|
|
7
|
-
const mockHistoryReplace = jest.fn();
|
|
8
|
-
|
|
9
|
-
jest.mock('react-router-dom', () => ({
|
|
10
|
-
...jest.requireActual('react-router-dom'),
|
|
11
|
-
useHistory: () => ({
|
|
12
|
-
replace: mockHistoryReplace,
|
|
13
|
-
}),
|
|
14
|
-
}));
|
|
15
4
|
|
|
16
5
|
jest.mock('foremanReact/Root/Context/ForemanContext', () => ({
|
|
17
6
|
useForemanContext: () => ({
|
|
@@ -22,115 +11,24 @@ jest.mock('foremanReact/Root/Context/ForemanContext', () => ({
|
|
|
22
11
|
useForemanPermissions: () => new Set(['view_vulnerability']),
|
|
23
12
|
}));
|
|
24
13
|
|
|
25
|
-
|
|
26
|
-
jest.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<div data-testid="mock-scalprum-component">{JSON.stringify(props)}</div>
|
|
33
|
-
);
|
|
34
|
-
}),
|
|
35
|
-
ScalprumProvider: jest.fn(({ children }) => <div>{children}</div>),
|
|
36
|
-
};
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const defaultResponse = {
|
|
40
|
-
id: 1,
|
|
41
|
-
operatingsystem_name: 'Red Hat Enterprise Linux 8',
|
|
42
|
-
vulnerability: { enabled: true },
|
|
43
|
-
subscription_facet_attributes: { uuid: '1-2-3' },
|
|
44
|
-
};
|
|
14
|
+
jest.mock('@scalprum/react-core', () => ({
|
|
15
|
+
ScalprumComponent: jest.fn(props => (
|
|
16
|
+
<div data-testid="mock-scalprum-component">{JSON.stringify(props)}</div>
|
|
17
|
+
)),
|
|
18
|
+
ScalprumProvider: jest.fn(({ children }) => <div>{children}</div>),
|
|
19
|
+
}));
|
|
45
20
|
|
|
46
21
|
describe('CVEsHostDetailsTabWrapper', () => {
|
|
47
|
-
|
|
48
|
-
jest.clearAllMocks();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('renders without crashing and does not redirect for valid host', () => {
|
|
22
|
+
it('renders without crashing', () => {
|
|
52
23
|
const { container } = render(
|
|
53
|
-
<
|
|
54
|
-
|
|
55
|
-
|
|
24
|
+
<CVEsHostDetailsTabWrapper
|
|
25
|
+
response={{ subscription_facet_attributes: { uuid: '1-2-3' } }}
|
|
26
|
+
/>
|
|
56
27
|
);
|
|
57
28
|
expect(
|
|
58
29
|
container.querySelector(
|
|
59
30
|
'.rh-cloud-insights-vulnerability-host-details-component'
|
|
60
31
|
)
|
|
61
32
|
).toBeTruthy();
|
|
62
|
-
expect(mockHistoryReplace).not.toHaveBeenCalled();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('remounts ScalprumComponent when systemId changes', () => {
|
|
66
|
-
const { ScalprumComponent } = require('@scalprum/react-core');
|
|
67
|
-
|
|
68
|
-
const responseHostA = {
|
|
69
|
-
...defaultResponse,
|
|
70
|
-
subscription_facet_attributes: { uuid: 'uuid-host-A' },
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const { rerender } = render(
|
|
74
|
-
<MemoryRouter>
|
|
75
|
-
<CVEsHostDetailsTabWrapper response={responseHostA} />
|
|
76
|
-
</MemoryRouter>
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
expect(mockUnmountTracker).not.toHaveBeenCalled();
|
|
80
|
-
expect(ScalprumComponent).toHaveBeenLastCalledWith(
|
|
81
|
-
expect.objectContaining({ systemId: 'uuid-host-A' }),
|
|
82
|
-
expect.anything()
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
const responseHostB = {
|
|
86
|
-
...defaultResponse,
|
|
87
|
-
subscription_facet_attributes: { uuid: 'uuid-host-B' },
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
rerender(
|
|
91
|
-
<MemoryRouter>
|
|
92
|
-
<CVEsHostDetailsTabWrapper response={responseHostB} />
|
|
93
|
-
</MemoryRouter>
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
expect(mockUnmountTracker).toHaveBeenCalledTimes(1);
|
|
97
|
-
expect(ScalprumComponent).toHaveBeenLastCalledWith(
|
|
98
|
-
expect.objectContaining({ systemId: 'uuid-host-B' }),
|
|
99
|
-
expect.anything()
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('redirects to Overview when tab should be hidden', () => {
|
|
104
|
-
const nonRhelResponse = {
|
|
105
|
-
id: 2,
|
|
106
|
-
operatingsystem_name: 'Ubuntu 20.04',
|
|
107
|
-
vulnerability: { enabled: false },
|
|
108
|
-
subscription_facet_attributes: { uuid: '1-2-3' },
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const { container } = render(
|
|
112
|
-
<MemoryRouter>
|
|
113
|
-
<CVEsHostDetailsTabWrapper response={nonRhelResponse} />
|
|
114
|
-
</MemoryRouter>
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
expect(mockHistoryReplace).toHaveBeenCalledWith(OVERVIEW_TAB_PATH);
|
|
118
|
-
expect(
|
|
119
|
-
container.querySelector(
|
|
120
|
-
'.rh-cloud-insights-vulnerability-host-details-component'
|
|
121
|
-
)
|
|
122
|
-
).toBeNull();
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('does not redirect when host data is not yet loaded', () => {
|
|
126
|
-
const emptyResponse = { subscription_facet_attributes: { uuid: '1-2-3' } };
|
|
127
|
-
|
|
128
|
-
render(
|
|
129
|
-
<MemoryRouter>
|
|
130
|
-
<CVEsHostDetailsTabWrapper response={emptyResponse} />
|
|
131
|
-
</MemoryRouter>
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
expect(mockHistoryReplace).not.toHaveBeenCalled();
|
|
135
33
|
});
|
|
136
34
|
});
|