foreman_rh_cloud 12.2.13 → 13.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 +4 -4
- data/app/assets/javascripts/foreman_rh_cloud/locale/fr/foreman_rh_cloud.js +24 -78
- data/app/assets/javascripts/foreman_rh_cloud/locale/ja/foreman_rh_cloud.js +24 -78
- data/app/assets/javascripts/foreman_rh_cloud/locale/ka/foreman_rh_cloud.js +23 -77
- data/app/assets/javascripts/foreman_rh_cloud/locale/ko/foreman_rh_cloud.js +23 -77
- data/app/assets/javascripts/foreman_rh_cloud/locale/zh_CN/foreman_rh_cloud.js +23 -77
- data/app/controllers/concerns/insights_cloud/package_profile_upload_extensions.rb +3 -2
- data/app/models/insights_hit.rb +1 -1
- data/app/services/foreman_rh_cloud/cert_auth.rb +3 -13
- data/app/services/foreman_rh_cloud/gateway_request.rb +26 -0
- data/app/services/foreman_rh_cloud/insights_api_forwarder.rb +1 -3
- data/app/services/foreman_rh_cloud/tags_auth.rb +1 -2
- data/lib/foreman_inventory_upload/async/generate_report_job.rb +8 -13
- data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +4 -4
- data/lib/foreman_inventory_upload/async/upload_report_job.rb +5 -6
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +2 -2
- data/lib/foreman_inventory_upload/generators/slice.rb +3 -3
- data/lib/foreman_inventory_upload/scripts/uploader.sh.erb +1 -7
- data/lib/foreman_inventory_upload.rb +2 -6
- data/lib/foreman_rh_cloud/engine.rb +15 -34
- data/lib/foreman_rh_cloud/plugin.rb +9 -9
- data/lib/foreman_rh_cloud/version.rb +1 -1
- data/lib/tasks/rh_cloud_inventory.rake +31 -14
- data/locale/foreman_rh_cloud.pot +157 -261
- data/locale/fr/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
- data/locale/fr/foreman_rh_cloud.po +26 -79
- data/locale/ja/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
- data/locale/ja/foreman_rh_cloud.po +26 -79
- data/locale/ka/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
- data/locale/ka/foreman_rh_cloud.po +24 -77
- data/locale/ko/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
- data/locale/ko/foreman_rh_cloud.po +25 -78
- data/locale/zh_CN/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
- data/locale/zh_CN/foreman_rh_cloud.po +25 -78
- data/package.json +1 -1
- data/test/jobs/cloud_connector_announce_task_test.rb +2 -3
- data/test/jobs/connector_playbook_execution_reporter_task_test.rb +20 -32
- data/test/jobs/exponential_backoff_test.rb +8 -9
- data/test/jobs/insights_client_status_aging_test.rb +2 -3
- data/test/jobs/insights_full_sync_test.rb +7 -13
- data/test/jobs/insights_resolutions_sync_test.rb +5 -9
- data/test/jobs/insights_rules_sync_test.rb +3 -5
- data/test/jobs/inventory_full_sync_test.rb +5 -9
- data/test/jobs/inventory_hosts_sync_test.rb +6 -11
- data/test/jobs/inventory_scheduled_sync_test.rb +6 -10
- data/test/jobs/inventory_self_host_sync_test.rb +1 -1
- data/test/jobs/remove_insights_hosts_job_test.rb +15 -14
- data/test/jobs/upload_report_job_test.rb +5 -7
- data/test/unit/fact_helpers_test.rb +0 -47
- data/test/unit/slice_generator_test.rb +0 -57
- data/webpack/ForemanRhCloudFills.js +2 -6
- data/webpack/ForemanRhCloudHelpers.js +0 -4
- data/webpack/InsightsHostDetailsTab/InsightsTab.scss +0 -4
- data/webpack/InsightsHostDetailsTab/InsightsTotalRiskChart.js +23 -59
- data/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +16 -3
- data/webpack/InsightsVulnerabilityHostIndexExtensions/CVECountCell.js +2 -8
- data/webpack/InsightsVulnerabilityHostIndexExtensions/__tests__/CVECountCell.test.js +2 -48
- data/webpack/__tests__/ForemanRhCloudHelpers.test.js +1 -16
- data/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap +0 -6
- metadata +4 -23
- data/app/controllers/concerns/foreman_rh_cloud/registration_manager_extensions.rb +0 -39
- data/lib/foreman_inventory_upload/async/create_missing_insights_facets.rb +0 -30
- data/lib/foreman_inventory_upload/async/generate_host_report.rb +0 -20
- data/lib/foreman_inventory_upload/async/host_inventory_report_job.rb +0 -39
- data/lib/foreman_inventory_upload/async/single_host_report_job.rb +0 -20
- data/test/jobs/create_missing_insights_facets_test.rb +0 -151
- data/test/jobs/generate_host_report_test.rb +0 -100
- data/test/jobs/generate_report_job_test.rb +0 -146
- data/test/jobs/host_inventory_report_job_test.rb +0 -244
- data/test/jobs/queue_for_upload_job_test.rb +0 -65
- data/test/jobs/single_host_report_job_test.rb +0 -155
- data/test/unit/lib/foreman_rh_cloud/registration_manager_extensions_test.rb +0 -192
- data/webpack/InsightsHostDetailsTab/__tests__/InsightsTotalRiskChart.test.js +0 -194
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
require 'test_plugin_helper'
|
|
2
|
-
require 'foreman_tasks/test_helpers'
|
|
3
|
-
|
|
4
|
-
class GenerateReportJobTest < ActiveSupport::TestCase
|
|
5
|
-
include Dynflow::Testing::Factories
|
|
6
|
-
include Dynflow::Testing::Assertions
|
|
7
|
-
|
|
8
|
-
let(:organization) { FactoryBot.create(:organization) }
|
|
9
|
-
let(:base_folder) { Dir.mktmpdir }
|
|
10
|
-
|
|
11
|
-
setup do
|
|
12
|
-
# Stub settings
|
|
13
|
-
Setting.stubs(:[]).with(:subscription_connection_enabled).returns(true)
|
|
14
|
-
Setting.stubs(:[]).with("foreman_tasks_sync_task_timeout").returns(120)
|
|
15
|
-
Setting.stubs(:[]).with(:content_default_http_proxy).returns(nil)
|
|
16
|
-
Setting.stubs(:[]).with(:http_proxy).returns(nil)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
teardown do
|
|
20
|
-
FileUtils.remove_entry base_folder if Dir.exist?(base_folder)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
test 'disconnected parameter defaults to false' do
|
|
24
|
-
# When disconnected defaults to false and subscription_connection is enabled,
|
|
25
|
-
# QueueForUploadJob should be scheduled
|
|
26
|
-
action = create_and_plan_action(
|
|
27
|
-
ForemanInventoryUpload::Async::GenerateReportJob,
|
|
28
|
-
base_folder,
|
|
29
|
-
organization.id
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
assert_action_planned(action, ForemanInventoryUpload::Async::QueueForUploadJob)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
test 'disconnected parameter can be set to true explicitly' do
|
|
36
|
-
# When disconnected is explicitly true, QueueForUploadJob should NOT be scheduled
|
|
37
|
-
action = create_and_plan_action(
|
|
38
|
-
ForemanInventoryUpload::Async::GenerateReportJob,
|
|
39
|
-
base_folder,
|
|
40
|
-
organization.id,
|
|
41
|
-
true
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
refute_action_planned(action, ForemanInventoryUpload::Async::QueueForUploadJob)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
test 'disconnected parameter can be set to false explicitly' do
|
|
48
|
-
# When disconnected is explicitly false and subscription_connection is enabled,
|
|
49
|
-
# QueueForUploadJob should be scheduled
|
|
50
|
-
action = create_and_plan_action(
|
|
51
|
-
ForemanInventoryUpload::Async::GenerateReportJob,
|
|
52
|
-
base_folder,
|
|
53
|
-
organization.id,
|
|
54
|
-
false
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
assert_action_planned(action, ForemanInventoryUpload::Async::QueueForUploadJob)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
test 'skips upload when subscription_connection_enabled is false' do
|
|
61
|
-
Setting.stubs(:[]).with(:subscription_connection_enabled).returns(false)
|
|
62
|
-
|
|
63
|
-
action = create_and_plan_action(
|
|
64
|
-
ForemanInventoryUpload::Async::GenerateReportJob,
|
|
65
|
-
base_folder,
|
|
66
|
-
organization.id,
|
|
67
|
-
false
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
refute_action_planned(action, ForemanInventoryUpload::Async::QueueForUploadJob)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
test 'schedules upload when disconnected is false and subscription_connection is enabled' do
|
|
74
|
-
Setting.stubs(:[]).with(:subscription_connection_enabled).returns(true)
|
|
75
|
-
|
|
76
|
-
expected_archive_name = ForemanInventoryUpload.facts_archive_name(organization.id, nil)
|
|
77
|
-
action = create_and_plan_action(
|
|
78
|
-
ForemanInventoryUpload::Async::GenerateReportJob,
|
|
79
|
-
base_folder,
|
|
80
|
-
organization.id,
|
|
81
|
-
false
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
assert_action_planned_with(
|
|
85
|
-
action,
|
|
86
|
-
ForemanInventoryUpload::Async::QueueForUploadJob,
|
|
87
|
-
base_folder,
|
|
88
|
-
expected_archive_name,
|
|
89
|
-
organization.id
|
|
90
|
-
)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
test 'handles hosts_filter parameter' do
|
|
94
|
-
hosts_filter = 'name~test'
|
|
95
|
-
expected_archive_name = ForemanInventoryUpload.facts_archive_name(organization.id, hosts_filter)
|
|
96
|
-
|
|
97
|
-
action = create_and_plan_action(
|
|
98
|
-
ForemanInventoryUpload::Async::GenerateReportJob,
|
|
99
|
-
base_folder,
|
|
100
|
-
organization.id,
|
|
101
|
-
false,
|
|
102
|
-
hosts_filter
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
assert_action_planned_with(
|
|
106
|
-
action,
|
|
107
|
-
ForemanInventoryUpload::Async::QueueForUploadJob,
|
|
108
|
-
base_folder,
|
|
109
|
-
expected_archive_name,
|
|
110
|
-
organization.id
|
|
111
|
-
)
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
test 'output_label generates correct label' do
|
|
115
|
-
label = ForemanInventoryUpload::Async::GenerateReportJob.output_label('test_org')
|
|
116
|
-
assert_equal 'report_for_test_org', label
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
test 'output_label with filter includes parameterized filter' do
|
|
120
|
-
action = create_and_plan_action(
|
|
121
|
-
ForemanInventoryUpload::Async::GenerateReportJob,
|
|
122
|
-
base_folder,
|
|
123
|
-
organization.id,
|
|
124
|
-
false,
|
|
125
|
-
'name~production'
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
# The output label should include organization id and parameterized filter
|
|
129
|
-
expected_label = "report_for_#{organization.id}[name-production]"
|
|
130
|
-
assert_equal expected_label, action.input[:instance_label]
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
test 'output_label without filter includes only organization id' do
|
|
134
|
-
action = create_and_plan_action(
|
|
135
|
-
ForemanInventoryUpload::Async::GenerateReportJob,
|
|
136
|
-
base_folder,
|
|
137
|
-
organization.id,
|
|
138
|
-
false,
|
|
139
|
-
''
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
# The output label should include only organization id when filter is empty
|
|
143
|
-
expected_label = "report_for_#{organization.id}"
|
|
144
|
-
assert_equal expected_label, action.input[:instance_label]
|
|
145
|
-
end
|
|
146
|
-
end
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
require 'test_plugin_helper'
|
|
2
|
-
require 'foreman_tasks/test_helpers'
|
|
3
|
-
|
|
4
|
-
class HostInventoryReportJobTest < ActiveSupport::TestCase
|
|
5
|
-
include Dynflow::Testing::Factories
|
|
6
|
-
include Dynflow::Testing::Assertions
|
|
7
|
-
|
|
8
|
-
let(:organization) { FactoryBot.create(:organization) }
|
|
9
|
-
let(:base_folder) { Dir.mktmpdir }
|
|
10
|
-
let(:hosts_filter) { '' }
|
|
11
|
-
let(:upload) { true }
|
|
12
|
-
|
|
13
|
-
teardown do
|
|
14
|
-
FileUtils.remove_entry base_folder if Dir.exist?(base_folder)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
test 'plan schedules GenerateHostReport action' do
|
|
18
|
-
action = create_and_plan_action(
|
|
19
|
-
ForemanInventoryUpload::Async::HostInventoryReportJob,
|
|
20
|
-
base_folder,
|
|
21
|
-
organization.id,
|
|
22
|
-
hosts_filter,
|
|
23
|
-
upload
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
assert_action_planned_with(
|
|
27
|
-
action,
|
|
28
|
-
ForemanInventoryUpload::Async::GenerateHostReport,
|
|
29
|
-
base_folder,
|
|
30
|
-
organization.id,
|
|
31
|
-
hosts_filter
|
|
32
|
-
)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
test 'plan schedules QueueForUploadJob when upload is true' do
|
|
36
|
-
expected_archive_name = ForemanInventoryUpload.facts_archive_name(organization.id, hosts_filter)
|
|
37
|
-
|
|
38
|
-
action = create_and_plan_action(
|
|
39
|
-
ForemanInventoryUpload::Async::HostInventoryReportJob,
|
|
40
|
-
base_folder,
|
|
41
|
-
organization.id,
|
|
42
|
-
hosts_filter,
|
|
43
|
-
true
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
assert_action_planned_with(
|
|
47
|
-
action,
|
|
48
|
-
ForemanInventoryUpload::Async::QueueForUploadJob,
|
|
49
|
-
base_folder,
|
|
50
|
-
expected_archive_name,
|
|
51
|
-
organization.id
|
|
52
|
-
)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
test 'plan skips QueueForUploadJob when upload is false' do
|
|
56
|
-
action = create_and_plan_action(
|
|
57
|
-
ForemanInventoryUpload::Async::HostInventoryReportJob,
|
|
58
|
-
base_folder,
|
|
59
|
-
organization.id,
|
|
60
|
-
hosts_filter,
|
|
61
|
-
false
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
refute_action_planned(action, ForemanInventoryUpload::Async::QueueForUploadJob)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
test 'plan defaults upload to true when not specified' do
|
|
68
|
-
action = create_and_plan_action(
|
|
69
|
-
ForemanInventoryUpload::Async::HostInventoryReportJob,
|
|
70
|
-
base_folder,
|
|
71
|
-
organization.id,
|
|
72
|
-
hosts_filter
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
assert_action_planned(action, ForemanInventoryUpload::Async::QueueForUploadJob)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
test 'plan schedules CreateMissingInsightsFacets when IoP is enabled' do
|
|
79
|
-
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
|
|
80
|
-
|
|
81
|
-
action = create_and_plan_action(
|
|
82
|
-
ForemanInventoryUpload::Async::HostInventoryReportJob,
|
|
83
|
-
base_folder,
|
|
84
|
-
organization.id,
|
|
85
|
-
hosts_filter,
|
|
86
|
-
upload
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
assert_action_planned_with(
|
|
90
|
-
action,
|
|
91
|
-
ForemanInventoryUpload::Async::CreateMissingInsightsFacets,
|
|
92
|
-
organization.id
|
|
93
|
-
)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
test 'plan skips CreateMissingInsightsFacets when IoP is disabled' do
|
|
97
|
-
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(false)
|
|
98
|
-
|
|
99
|
-
action = create_and_plan_action(
|
|
100
|
-
ForemanInventoryUpload::Async::HostInventoryReportJob,
|
|
101
|
-
base_folder,
|
|
102
|
-
organization.id,
|
|
103
|
-
hosts_filter,
|
|
104
|
-
upload
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
refute_action_planned(action, ForemanInventoryUpload::Async::CreateMissingInsightsFacets)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
test 'plan schedules all three actions with IoP enabled and upload true' do
|
|
111
|
-
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
|
|
112
|
-
|
|
113
|
-
action = create_and_plan_action(
|
|
114
|
-
ForemanInventoryUpload::Async::HostInventoryReportJob,
|
|
115
|
-
base_folder,
|
|
116
|
-
organization.id,
|
|
117
|
-
hosts_filter,
|
|
118
|
-
true
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
assert_action_planned(action, ForemanInventoryUpload::Async::GenerateHostReport)
|
|
122
|
-
assert_action_planned(action, ForemanInventoryUpload::Async::QueueForUploadJob)
|
|
123
|
-
assert_action_planned(action, ForemanInventoryUpload::Async::CreateMissingInsightsFacets)
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
test 'plan schedules only generation and facets with IoP enabled and upload false' do
|
|
127
|
-
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
|
|
128
|
-
|
|
129
|
-
action = create_and_plan_action(
|
|
130
|
-
ForemanInventoryUpload::Async::HostInventoryReportJob,
|
|
131
|
-
base_folder,
|
|
132
|
-
organization.id,
|
|
133
|
-
hosts_filter,
|
|
134
|
-
false
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
assert_action_planned(action, ForemanInventoryUpload::Async::GenerateHostReport)
|
|
138
|
-
refute_action_planned(action, ForemanInventoryUpload::Async::QueueForUploadJob)
|
|
139
|
-
assert_action_planned(action, ForemanInventoryUpload::Async::CreateMissingInsightsFacets)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
test 'humanized_name returns correct string' do
|
|
143
|
-
action = create_and_plan_action(
|
|
144
|
-
ForemanInventoryUpload::Async::HostInventoryReportJob,
|
|
145
|
-
base_folder,
|
|
146
|
-
organization.id,
|
|
147
|
-
hosts_filter,
|
|
148
|
-
upload
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
assert_equal 'Host inventory report job', action.humanized_name
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
test 'handles empty hosts_filter parameter' do
|
|
155
|
-
action = create_and_plan_action(
|
|
156
|
-
ForemanInventoryUpload::Async::HostInventoryReportJob,
|
|
157
|
-
base_folder,
|
|
158
|
-
organization.id,
|
|
159
|
-
'',
|
|
160
|
-
upload
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
assert_action_planned_with(
|
|
164
|
-
action,
|
|
165
|
-
ForemanInventoryUpload::Async::GenerateHostReport,
|
|
166
|
-
base_folder,
|
|
167
|
-
organization.id,
|
|
168
|
-
''
|
|
169
|
-
)
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
test 'handles custom hosts_filter parameter' do
|
|
173
|
-
custom_filter = 'name~production'
|
|
174
|
-
expected_archive_name = ForemanInventoryUpload.facts_archive_name(organization.id, custom_filter)
|
|
175
|
-
|
|
176
|
-
action = create_and_plan_action(
|
|
177
|
-
ForemanInventoryUpload::Async::HostInventoryReportJob,
|
|
178
|
-
base_folder,
|
|
179
|
-
organization.id,
|
|
180
|
-
custom_filter,
|
|
181
|
-
upload
|
|
182
|
-
)
|
|
183
|
-
|
|
184
|
-
assert_action_planned_with(
|
|
185
|
-
action,
|
|
186
|
-
ForemanInventoryUpload::Async::GenerateHostReport,
|
|
187
|
-
base_folder,
|
|
188
|
-
organization.id,
|
|
189
|
-
custom_filter
|
|
190
|
-
)
|
|
191
|
-
assert_action_planned_with(
|
|
192
|
-
action,
|
|
193
|
-
ForemanInventoryUpload::Async::QueueForUploadJob,
|
|
194
|
-
base_folder,
|
|
195
|
-
expected_archive_name,
|
|
196
|
-
organization.id
|
|
197
|
-
)
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
test 'handles invalid hosts_filter parameter' do
|
|
201
|
-
invalid_filter = 'name~~'
|
|
202
|
-
|
|
203
|
-
action = create_and_plan_action(
|
|
204
|
-
ForemanInventoryUpload::Async::HostInventoryReportJob,
|
|
205
|
-
base_folder,
|
|
206
|
-
organization.id,
|
|
207
|
-
invalid_filter,
|
|
208
|
-
upload
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
# Job should still plan even with invalid filter syntax
|
|
212
|
-
assert_action_planned(action, ForemanInventoryUpload::Async::GenerateHostReport)
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
test 'handles potentially malicious hosts_filter parameter' do
|
|
216
|
-
malicious_filter = "'; DROP TABLE hosts; --"
|
|
217
|
-
|
|
218
|
-
action = create_and_plan_action(
|
|
219
|
-
ForemanInventoryUpload::Async::HostInventoryReportJob,
|
|
220
|
-
base_folder,
|
|
221
|
-
organization.id,
|
|
222
|
-
malicious_filter,
|
|
223
|
-
upload
|
|
224
|
-
)
|
|
225
|
-
|
|
226
|
-
# Job should handle malicious input safely (filter is parameterized)
|
|
227
|
-
assert_action_planned(action, ForemanInventoryUpload::Async::GenerateHostReport)
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
test 'handles non-matching hosts_filter parameter' do
|
|
231
|
-
non_matching_filter = 'name~doesnotexist'
|
|
232
|
-
|
|
233
|
-
action = create_and_plan_action(
|
|
234
|
-
ForemanInventoryUpload::Async::HostInventoryReportJob,
|
|
235
|
-
base_folder,
|
|
236
|
-
organization.id,
|
|
237
|
-
non_matching_filter,
|
|
238
|
-
upload
|
|
239
|
-
)
|
|
240
|
-
|
|
241
|
-
# Job should plan successfully even if filter matches no hosts
|
|
242
|
-
assert_action_planned(action, ForemanInventoryUpload::Async::GenerateHostReport)
|
|
243
|
-
end
|
|
244
|
-
end
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
require 'test_plugin_helper'
|
|
2
|
-
require 'foreman_tasks/test_helpers'
|
|
3
|
-
|
|
4
|
-
class QueueForUploadJobTest < ActiveSupport::TestCase
|
|
5
|
-
include Dynflow::Testing::Factories
|
|
6
|
-
|
|
7
|
-
let(:organization) { FactoryBot.create(:organization) }
|
|
8
|
-
let(:base_folder) { Dir.mktmpdir }
|
|
9
|
-
let(:report_file) { 'test_report.tar.xz' }
|
|
10
|
-
let(:report_path) { File.join(base_folder, report_file) }
|
|
11
|
-
let(:uploads_folder) { ForemanInventoryUpload.uploads_folder }
|
|
12
|
-
|
|
13
|
-
setup do
|
|
14
|
-
# Stub the script template source
|
|
15
|
-
script_source = File.join(ForemanRhCloud::Engine.root, 'lib/foreman_inventory_upload/scripts/uploader.sh.erb')
|
|
16
|
-
File.stubs(:read).with(script_source).returns('#!/bin/bash\necho "Test script"')
|
|
17
|
-
|
|
18
|
-
# Stub template rendering
|
|
19
|
-
Foreman::Renderer.stubs(:render).returns('#!/bin/bash\necho "Rendered script"')
|
|
20
|
-
|
|
21
|
-
# Stub additional settings that are accessed
|
|
22
|
-
Setting.stubs(:[]).with(:content_default_http_proxy).returns(nil)
|
|
23
|
-
Setting.stubs(:[]).with(:http_proxy).returns(nil)
|
|
24
|
-
Setting.stubs(:[]).with("foreman_tasks_sync_task_timeout").returns(120)
|
|
25
|
-
FileUtils.touch(report_path)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
teardown do
|
|
29
|
-
FileUtils.rm_rf(uploads_folder) if Dir.exist?(uploads_folder)
|
|
30
|
-
FileUtils.remove_entry base_folder if Dir.exist?(base_folder)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
test 'plan method sets up the job correctly and calls plan_upload_report' do
|
|
34
|
-
# Mock plan_upload_report to verify it's called
|
|
35
|
-
ForemanInventoryUpload::Async::QueueForUploadJob.any_instance.expects(:plan_upload_report).once
|
|
36
|
-
|
|
37
|
-
action = create_and_plan_action(ForemanInventoryUpload::Async::QueueForUploadJob, base_folder, report_file, organization.id)
|
|
38
|
-
run_action(action)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
test 'run method processes file and moves it to uploads folder' do
|
|
42
|
-
ForemanInventoryUpload::Async::QueueForUploadJob.any_instance.stubs(:plan_upload_report)
|
|
43
|
-
|
|
44
|
-
action = create_and_plan_action(ForemanInventoryUpload::Async::QueueForUploadJob, base_folder, report_file, organization.id)
|
|
45
|
-
run_action(action)
|
|
46
|
-
|
|
47
|
-
# Verify the file was moved
|
|
48
|
-
refute File.exist?(report_path), "Original file should be moved"
|
|
49
|
-
assert File.exist?(File.join(uploads_folder, report_file)), "File should exist in uploads folder"
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
test 'creates necessary folders and scripts' do
|
|
53
|
-
ForemanInventoryUpload::Async::QueueForUploadJob.any_instance.stubs(:plan_upload_report)
|
|
54
|
-
|
|
55
|
-
action = create_and_plan_action(ForemanInventoryUpload::Async::QueueForUploadJob, base_folder, report_file, organization.id)
|
|
56
|
-
run_action(action)
|
|
57
|
-
|
|
58
|
-
# Verify the uploads folder was created
|
|
59
|
-
assert Dir.exist?(uploads_folder), "Uploads folder should be created"
|
|
60
|
-
|
|
61
|
-
# Verify the script file was created
|
|
62
|
-
script_path = File.join(uploads_folder, ForemanInventoryUpload.upload_script_file)
|
|
63
|
-
assert File.exist?(script_path), "Upload script should be created"
|
|
64
|
-
end
|
|
65
|
-
end
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
require 'test_plugin_helper'
|
|
2
|
-
require 'foreman_tasks/test_helpers'
|
|
3
|
-
|
|
4
|
-
class SingleHostReportJobTest < ActiveSupport::TestCase
|
|
5
|
-
include Dynflow::Testing::Factories
|
|
6
|
-
include Dynflow::Testing::Assertions
|
|
7
|
-
include KatelloCVEHelper
|
|
8
|
-
|
|
9
|
-
let(:base_folder) { Dir.mktmpdir }
|
|
10
|
-
|
|
11
|
-
setup do
|
|
12
|
-
User.current = User.find_by(login: 'secret_admin')
|
|
13
|
-
cve = make_cve
|
|
14
|
-
env = cve.lifecycle_environment
|
|
15
|
-
|
|
16
|
-
@host = FactoryBot.create(
|
|
17
|
-
:host,
|
|
18
|
-
:with_subscription,
|
|
19
|
-
:with_content,
|
|
20
|
-
content_view: cve.content_view,
|
|
21
|
-
lifecycle_environment: env,
|
|
22
|
-
organization: env.organization
|
|
23
|
-
)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
teardown do
|
|
27
|
-
FileUtils.remove_entry base_folder if Dir.exist?(base_folder)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
test 'plan sets host_id in input' do
|
|
31
|
-
action = create_and_plan_action(
|
|
32
|
-
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
33
|
-
base_folder,
|
|
34
|
-
@host.organization_id,
|
|
35
|
-
@host.id
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
assert_equal @host.id, action.input[:host_id]
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
test 'plan calls super with id filter' do
|
|
42
|
-
expected_filter = "id=#{@host.id}"
|
|
43
|
-
|
|
44
|
-
action = create_and_plan_action(
|
|
45
|
-
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
46
|
-
base_folder,
|
|
47
|
-
@host.organization_id,
|
|
48
|
-
@host.id
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
assert_action_planned_with(
|
|
52
|
-
action,
|
|
53
|
-
ForemanInventoryUpload::Async::GenerateHostReport,
|
|
54
|
-
base_folder,
|
|
55
|
-
@host.organization_id,
|
|
56
|
-
expected_filter
|
|
57
|
-
)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
test 'inherits behavior from HostInventoryReportJob' do
|
|
61
|
-
action = create_and_plan_action(
|
|
62
|
-
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
63
|
-
base_folder,
|
|
64
|
-
@host.organization_id,
|
|
65
|
-
@host.id
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
# Should schedule all parent actions
|
|
69
|
-
assert_action_planned(action, ForemanInventoryUpload::Async::GenerateHostReport)
|
|
70
|
-
assert_action_planned(action, ForemanInventoryUpload::Async::QueueForUploadJob)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
test 'humanized_name includes hostname' do
|
|
74
|
-
action = create_and_plan_action(
|
|
75
|
-
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
76
|
-
base_folder,
|
|
77
|
-
@host.organization_id,
|
|
78
|
-
@host.id
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
assert_equal "Single-host report job for host #{@host.name}", action.humanized_name
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
test 'humanized_name handles missing host' do
|
|
85
|
-
non_existent_host_id = 999_999
|
|
86
|
-
|
|
87
|
-
action = create_and_plan_action(
|
|
88
|
-
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
89
|
-
base_folder,
|
|
90
|
-
@host.organization_id,
|
|
91
|
-
non_existent_host_id
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
assert_equal 'Single-host report job', action.humanized_name
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
test 'hostname method returns correct name' do
|
|
98
|
-
action = create_and_plan_action(
|
|
99
|
-
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
100
|
-
base_folder,
|
|
101
|
-
@host.organization_id,
|
|
102
|
-
@host.id
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
assert_equal @host.name, action.hostname(@host.id)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
test 'hostname method handles nil gracefully' do
|
|
109
|
-
action = create_and_plan_action(
|
|
110
|
-
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
111
|
-
base_folder,
|
|
112
|
-
@host.organization_id,
|
|
113
|
-
@host.id
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
assert_nil action.hostname(999_999)
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
test 'generates report with correct archive name for single host' do
|
|
120
|
-
expected_filter = "id=#{@host.id}"
|
|
121
|
-
expected_archive_name = ForemanInventoryUpload.facts_archive_name(@host.organization_id, expected_filter)
|
|
122
|
-
|
|
123
|
-
action = create_and_plan_action(
|
|
124
|
-
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
125
|
-
base_folder,
|
|
126
|
-
@host.organization_id,
|
|
127
|
-
@host.id
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
assert_action_planned_with(
|
|
131
|
-
action,
|
|
132
|
-
ForemanInventoryUpload::Async::QueueForUploadJob,
|
|
133
|
-
base_folder,
|
|
134
|
-
expected_archive_name,
|
|
135
|
-
@host.organization_id
|
|
136
|
-
)
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
test 'respects IoP mode for facet creation' do
|
|
140
|
-
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
|
|
141
|
-
|
|
142
|
-
action = create_and_plan_action(
|
|
143
|
-
ForemanInventoryUpload::Async::SingleHostReportJob,
|
|
144
|
-
base_folder,
|
|
145
|
-
@host.organization_id,
|
|
146
|
-
@host.id
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
assert_action_planned_with(
|
|
150
|
-
action,
|
|
151
|
-
ForemanInventoryUpload::Async::CreateMissingInsightsFacets,
|
|
152
|
-
@host.organization_id
|
|
153
|
-
)
|
|
154
|
-
end
|
|
155
|
-
end
|