foreman_rh_cloud 12.2.16 → 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.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/foreman_rh_cloud/locale/fr/foreman_rh_cloud.js +24 -78
  3. data/app/assets/javascripts/foreman_rh_cloud/locale/ja/foreman_rh_cloud.js +24 -78
  4. data/app/assets/javascripts/foreman_rh_cloud/locale/ka/foreman_rh_cloud.js +23 -77
  5. data/app/assets/javascripts/foreman_rh_cloud/locale/ko/foreman_rh_cloud.js +23 -77
  6. data/app/assets/javascripts/foreman_rh_cloud/locale/zh_CN/foreman_rh_cloud.js +23 -77
  7. data/app/controllers/concerns/insights_cloud/package_profile_upload_extensions.rb +3 -5
  8. data/app/controllers/foreman_inventory_upload/accounts_controller.rb +1 -1
  9. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +1 -1
  10. data/app/controllers/insights_cloud/ui_requests_controller.rb +3 -2
  11. data/app/models/concerns/rh_cloud_host.rb +0 -14
  12. data/app/models/foreman_rh_cloud/ping.rb +1 -2
  13. data/app/models/insights_hit.rb +1 -1
  14. data/app/services/foreman_rh_cloud/cert_auth.rb +3 -13
  15. data/app/services/foreman_rh_cloud/gateway_request.rb +26 -0
  16. data/app/services/foreman_rh_cloud/insights_api_forwarder.rb +1 -3
  17. data/app/services/foreman_rh_cloud/tags_auth.rb +4 -15
  18. data/app/views/api/v2/advisor_engine/host_details.json.rabl +3 -1
  19. data/app/views/api/v2/hosts/insights/base.rabl +2 -3
  20. data/lib/foreman_inventory_upload/async/generate_report_job.rb +8 -13
  21. data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +26 -4
  22. data/lib/foreman_inventory_upload/async/upload_report_job.rb +96 -0
  23. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +2 -2
  24. data/lib/foreman_inventory_upload/generators/slice.rb +3 -3
  25. data/lib/foreman_inventory_upload/scripts/uploader.sh.erb +49 -0
  26. data/lib/foreman_inventory_upload.rb +6 -6
  27. data/lib/foreman_rh_cloud/engine.rb +15 -34
  28. data/lib/foreman_rh_cloud/plugin.rb +13 -20
  29. data/lib/foreman_rh_cloud/version.rb +1 -1
  30. data/lib/foreman_rh_cloud.rb +3 -3
  31. data/lib/insights_cloud/async/connector_playbook_execution_reporter_task.rb +3 -3
  32. data/lib/inventory_sync/async/inventory_hosts_sync.rb +2 -0
  33. data/lib/tasks/rh_cloud_inventory.rake +31 -14
  34. data/locale/foreman_rh_cloud.pot +157 -261
  35. data/locale/fr/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  36. data/locale/fr/foreman_rh_cloud.po +26 -79
  37. data/locale/ja/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  38. data/locale/ja/foreman_rh_cloud.po +26 -79
  39. data/locale/ka/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  40. data/locale/ka/foreman_rh_cloud.po +24 -77
  41. data/locale/ko/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  42. data/locale/ko/foreman_rh_cloud.po +25 -78
  43. data/locale/zh_CN/LC_MESSAGES/foreman_rh_cloud.mo +0 -0
  44. data/locale/zh_CN/foreman_rh_cloud.po +25 -78
  45. data/package.json +1 -1
  46. data/test/controllers/accounts_controller_test.rb +1 -1
  47. data/test/controllers/insights_cloud/api/advisor_engine_controller_test.rb +1 -28
  48. data/test/controllers/insights_cloud/ui_requests_controller_test.rb +0 -26
  49. data/test/controllers/uploads_controller_test.rb +1 -1
  50. data/test/factories/insights_factories.rb +0 -29
  51. data/test/jobs/cloud_connector_announce_task_test.rb +2 -3
  52. data/test/jobs/connector_playbook_execution_reporter_task_test.rb +20 -32
  53. data/test/jobs/exponential_backoff_test.rb +8 -9
  54. data/test/jobs/insights_client_status_aging_test.rb +2 -3
  55. data/test/jobs/insights_full_sync_test.rb +7 -13
  56. data/test/jobs/insights_resolutions_sync_test.rb +5 -9
  57. data/test/jobs/insights_rules_sync_test.rb +3 -5
  58. data/test/jobs/inventory_full_sync_test.rb +5 -9
  59. data/test/jobs/inventory_hosts_sync_test.rb +6 -11
  60. data/test/jobs/inventory_scheduled_sync_test.rb +6 -10
  61. data/test/jobs/inventory_self_host_sync_test.rb +1 -1
  62. data/test/jobs/remove_insights_hosts_job_test.rb +15 -14
  63. data/test/jobs/upload_report_job_test.rb +36 -0
  64. data/test/unit/fact_helpers_test.rb +0 -47
  65. data/test/unit/services/foreman_rh_cloud/tags_auth_test.rb +0 -14
  66. data/test/unit/slice_generator_test.rb +0 -57
  67. data/webpack/ForemanColumnExtensions/index.js +0 -2
  68. data/webpack/ForemanInventoryUpload/Components/PageHeader/PageHeader.js +17 -24
  69. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/PageHeader.test.js +8 -178
  70. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageHeader.test.js.snap +36 -0
  71. data/webpack/ForemanInventoryUpload/Components/PageHeader/__tests__/__snapshots__/PageTitle.test.js.snap +1 -1
  72. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/ToolbarButtons.js +1 -3
  73. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/ToolbarButtons/__tests__/ToolbarButtons.test.js +51 -69
  74. data/webpack/ForemanInventoryUpload/ForemanInventoryHelpers.js +1 -1
  75. data/webpack/ForemanInventoryUpload/__tests__/__snapshots__/ForemanInventoryHelpers.test.js.snap +1 -1
  76. data/webpack/ForemanRhCloudFills.js +2 -6
  77. data/webpack/ForemanRhCloudHelpers.js +0 -4
  78. data/webpack/InsightsCloudSync/Components/InsightsSettings/InsightsSettings.js +3 -3
  79. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTable.js +9 -3
  80. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/InsightsTable.test.js +4 -24
  81. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTable.test.js.snap +112 -0
  82. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.js +2 -2
  83. data/webpack/InsightsCloudSync/Components/ToolbarDropdown.js +3 -3
  84. data/webpack/InsightsCloudSync/InsightsCloudSync.js +3 -3
  85. data/webpack/InsightsCloudSync/InsightsCloudSync.test.js +0 -10
  86. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +1 -1
  87. data/webpack/InsightsHostDetailsTab/InsightsTab.scss +0 -4
  88. data/webpack/InsightsHostDetailsTab/InsightsTotalRiskChart.js +23 -59
  89. data/webpack/InsightsHostDetailsTab/NewHostDetailsTab.js +19 -6
  90. data/webpack/InsightsVulnerabilityHostIndexExtensions/CVECountCell.js +2 -8
  91. data/webpack/InsightsVulnerabilityHostIndexExtensions/__tests__/CVECountCell.test.js +4 -105
  92. data/webpack/__mocks__/foremanReact/common/hooks/API/APIHooks.js +3 -0
  93. data/webpack/__tests__/ForemanRhCloudHelpers.test.js +1 -16
  94. data/webpack/__tests__/__snapshots__/ForemanRhCloudHelpers.test.js.snap +0 -6
  95. data/webpack/common/Hooks/ConfigHooks.js +16 -3
  96. metadata +12 -31
  97. data/app/controllers/concerns/foreman_rh_cloud/registration_manager_extensions.rb +0 -39
  98. data/lib/foreman_inventory_upload/async/create_missing_insights_facets.rb +0 -30
  99. data/lib/foreman_inventory_upload/async/generate_host_report.rb +0 -20
  100. data/lib/foreman_inventory_upload/async/host_inventory_report_job.rb +0 -39
  101. data/lib/foreman_inventory_upload/async/single_host_report_job.rb +0 -20
  102. data/lib/foreman_inventory_upload/async/upload_report_direct_job.rb +0 -200
  103. data/test/jobs/create_missing_insights_facets_test.rb +0 -151
  104. data/test/jobs/generate_host_report_test.rb +0 -100
  105. data/test/jobs/generate_report_job_test.rb +0 -146
  106. data/test/jobs/host_inventory_report_job_test.rb +0 -244
  107. data/test/jobs/queue_for_upload_job_test.rb +0 -54
  108. data/test/jobs/single_host_report_job_test.rb +0 -155
  109. data/test/jobs/upload_report_direct_job_test.rb +0 -399
  110. data/test/unit/foreman_rh_cloud_iop_metadata_test.rb +0 -200
  111. data/test/unit/lib/foreman_rh_cloud/registration_manager_extensions_test.rb +0 -154
  112. data/test/unit/rh_cloud_host_test.rb +0 -191
  113. data/webpack/InsightsHostDetailsTab/__tests__/InsightsTotalRiskChart.test.js +0 -194
@@ -1,399 +0,0 @@
1
- require 'test_plugin_helper'
2
- require 'foreman_tasks/test_helpers'
3
-
4
- class UploadReportDirectJobTest < ActiveSupport::TestCase
5
- include Dynflow::Testing::Factories
6
- include Dynflow::Testing::Assertions
7
-
8
- setup do
9
- @organization = FactoryBot.create(:organization)
10
- @uploads_folder = ForemanInventoryUpload.uploads_folder
11
- @filename = File.join(@uploads_folder, 'test_report.tar.xz')
12
-
13
- # Stub settings
14
- Setting.stubs(:[]).with(:subscription_connection_enabled).returns(true)
15
- Setting.stubs(:[]).with(:ssl_certificate).returns('/fake/cert.pem')
16
- Setting.stubs(:[]).with(:ssl_priv_key).returns('/fake/key.pem')
17
-
18
- # Stub ForemanRhCloud methods
19
- ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(false)
20
-
21
- # Stub organization owner details with certificate
22
- @cert_data = {
23
- 'upstreamConsumer' => {
24
- 'idCert' => {
25
- 'cert' => 'FAKE CERTIFICATE',
26
- 'key' => 'FAKE KEY',
27
- },
28
- },
29
- }
30
- Organization.any_instance.stubs(:owner_details).returns(@cert_data)
31
-
32
- # Clear task output
33
- TaskOutputLine.delete_all
34
- TaskOutputStatus.delete_all
35
- end
36
-
37
- test 'plan sets input correctly' do
38
- action = create_and_plan_action(
39
- ForemanInventoryUpload::Async::UploadReportDirectJob,
40
- @filename,
41
- @organization.id
42
- )
43
-
44
- assert_equal @filename, action.input[:filename]
45
- assert_equal @organization.id, action.input[:organization_id]
46
- assert_equal "upload_for_#{@organization.id}", action.input[:instance_label]
47
- end
48
-
49
- test 'output_label generates correct label' do
50
- label = ForemanInventoryUpload::Async::UploadReportDirectJob.output_label(@organization.id)
51
- assert_equal "upload_for_#{@organization.id}", label
52
- end
53
-
54
- test 'uses manifest certificate in regular mode' do
55
- ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(false)
56
-
57
- action = create_and_plan_action(
58
- ForemanInventoryUpload::Async::UploadReportDirectJob,
59
- @filename,
60
- @organization.id
61
- )
62
-
63
- cert = action.send(:certificate)
64
- assert_equal 'FAKE CERTIFICATE', cert[:cert]
65
- assert_equal 'FAKE KEY', cert[:key]
66
- end
67
-
68
- test 'manifest_certificate extracts from organization owner_details' do
69
- action = create_and_plan_action(
70
- ForemanInventoryUpload::Async::UploadReportDirectJob,
71
- @filename,
72
- @organization.id
73
- )
74
-
75
- cert = action.send(:manifest_certificate)
76
- assert_equal 'FAKE CERTIFICATE', cert[:cert]
77
- assert_equal 'FAKE KEY', cert[:key]
78
- end
79
-
80
- test 'uses foreman certificate in IoP mode' do
81
- ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
82
- File.stubs(:read).with('/fake/cert.pem').returns('FOREMAN CERTIFICATE')
83
- File.stubs(:read).with('/fake/key.pem').returns('FOREMAN KEY')
84
-
85
- action = create_and_plan_action(
86
- ForemanInventoryUpload::Async::UploadReportDirectJob,
87
- @filename,
88
- @organization.id
89
- )
90
-
91
- cert = action.send(:foreman_certificate)
92
- assert_equal 'FOREMAN CERTIFICATE', cert[:cert]
93
- assert_equal 'FOREMAN KEY', cert[:key]
94
- end
95
-
96
- test 'certificate method returns manifest cert in regular mode' do
97
- ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(false)
98
-
99
- action = create_and_plan_action(
100
- ForemanInventoryUpload::Async::UploadReportDirectJob,
101
- @filename,
102
- @organization.id
103
- )
104
-
105
- cert = action.send(:certificate)
106
- assert_equal 'FAKE CERTIFICATE', cert[:cert]
107
- assert_equal 'FAKE KEY', cert[:key]
108
- end
109
-
110
- test 'certificate method returns foreman cert in IoP mode' do
111
- ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
112
- File.stubs(:read).with('/fake/cert.pem').returns('FOREMAN CERTIFICATE')
113
- File.stubs(:read).with('/fake/key.pem').returns('FOREMAN KEY')
114
-
115
- action = create_and_plan_action(
116
- ForemanInventoryUpload::Async::UploadReportDirectJob,
117
- @filename,
118
- @organization.id
119
- )
120
-
121
- cert = action.send(:certificate)
122
- assert_equal 'FOREMAN CERTIFICATE', cert[:cert]
123
- assert_equal 'FOREMAN KEY', cert[:key]
124
- end
125
-
126
- test 'filename returns input filename' do
127
- action = create_and_plan_action(
128
- ForemanInventoryUpload::Async::UploadReportDirectJob,
129
- @filename,
130
- @organization.id
131
- )
132
-
133
- assert_equal @filename, action.send(:filename)
134
- end
135
-
136
- test 'organization returns Organization from input organization_id' do
137
- action = create_and_plan_action(
138
- ForemanInventoryUpload::Async::UploadReportDirectJob,
139
- @filename,
140
- @organization.id
141
- )
142
-
143
- org = action.send(:organization)
144
- assert_equal @organization.id, org.id
145
- end
146
-
147
- test 'content_disconnected? returns true when subscription_connection_enabled is false' do
148
- Setting.stubs(:[]).with(:subscription_connection_enabled).returns(false)
149
-
150
- action = create_and_plan_action(
151
- ForemanInventoryUpload::Async::UploadReportDirectJob,
152
- @filename,
153
- @organization.id
154
- )
155
-
156
- assert action.send(:content_disconnected?)
157
- end
158
-
159
- test 'content_disconnected? returns false when subscription_connection_enabled is true' do
160
- Setting.stubs(:[]).with(:subscription_connection_enabled).returns(true)
161
-
162
- action = create_and_plan_action(
163
- ForemanInventoryUpload::Async::UploadReportDirectJob,
164
- @filename,
165
- @organization.id
166
- )
167
-
168
- refute action.send(:content_disconnected?)
169
- end
170
-
171
- test 'instance_label returns label from input' do
172
- action = create_and_plan_action(
173
- ForemanInventoryUpload::Async::UploadReportDirectJob,
174
- @filename,
175
- @organization.id
176
- )
177
-
178
- assert_equal "upload_for_#{@organization.id}", action.send(:instance_label)
179
- end
180
-
181
- test 'clears previous task output on plan' do
182
- # Create some old output
183
- old_label = ForemanInventoryUpload::Async::UploadReportDirectJob.output_label(@organization.id)
184
- TaskOutputLine.create!(label: old_label, line: 'old line')
185
- TaskOutputStatus.create!(label: old_label, status: 'old status')
186
-
187
- create_and_plan_action(
188
- ForemanInventoryUpload::Async::UploadReportDirectJob,
189
- @filename,
190
- @organization.id
191
- )
192
-
193
- # Verify old output was cleared
194
- assert_equal 0, TaskOutputLine.where(label: old_label).count
195
- assert_equal 0, TaskOutputStatus.where(label: old_label).count
196
- end
197
-
198
- test 'rescue_strategy_for_self returns Fail strategy' do
199
- action = create_and_plan_action(
200
- ForemanInventoryUpload::Async::UploadReportDirectJob,
201
- @filename,
202
- @organization.id
203
- )
204
-
205
- assert_equal Dynflow::Action::Rescue::Fail, action.send(:rescue_strategy_for_self)
206
- end
207
-
208
- test 'handles RestClient server error gracefully' do
209
- # Create mock response for RestClient exception
210
- response = mock('response')
211
- response.stubs(:code).returns(500)
212
- response.stubs(:body).returns('Server error')
213
-
214
- # Stub upload_file to raise server error
215
- ForemanInventoryUpload::Async::UploadReportDirectJob.any_instance.stubs(:upload_file)
216
- .raises(RestClient::InternalServerError.new(response))
217
-
218
- action = create_and_plan_action(
219
- ForemanInventoryUpload::Async::UploadReportDirectJob,
220
- @filename,
221
- @organization.id
222
- )
223
-
224
- # Should raise the error (handled by Dynflow retry mechanism)
225
- assert_raises(RestClient::InternalServerError) do
226
- action.send(:try_execute)
227
- end
228
-
229
- # Verify progress output shows error
230
- label = ForemanInventoryUpload::Async::UploadReportDirectJob.output_label(@organization.id)
231
- output = ForemanInventoryUpload::Async::ProgressOutput.get(label).full_output
232
- assert_match(/Upload failed/, output)
233
- end
234
-
235
- test 'handles RestClient timeout gracefully' do
236
- # Stub upload_file to raise timeout (Timeout exception doesn't need response object)
237
- ForemanInventoryUpload::Async::UploadReportDirectJob.any_instance.stubs(:upload_file)
238
- .raises(RestClient::Exceptions::Timeout.new)
239
-
240
- action = create_and_plan_action(
241
- ForemanInventoryUpload::Async::UploadReportDirectJob,
242
- @filename,
243
- @organization.id
244
- )
245
-
246
- # Should raise the error (handled by Dynflow retry mechanism via ExponentialBackoff)
247
- assert_raises(RestClient::Exceptions::Timeout) do
248
- action.send(:try_execute)
249
- end
250
-
251
- # Verify progress output shows error
252
- label = ForemanInventoryUpload::Async::UploadReportDirectJob.output_label(@organization.id)
253
- output = ForemanInventoryUpload::Async::ProgressOutput.get(label).full_output
254
- assert_match(/Upload failed/, output)
255
- end
256
-
257
- test 'uses proxy configuration from ForemanRhCloud' do
258
- proxy_url = 'http://proxy.example.com:8080'
259
- ForemanRhCloud.stubs(:transformed_http_proxy_string).returns(proxy_url)
260
-
261
- # Create test file
262
- FileUtils.mkdir_p(File.dirname(@filename))
263
- FileUtils.touch(@filename)
264
-
265
- action = create_and_plan_action(
266
- ForemanInventoryUpload::Async::UploadReportDirectJob,
267
- @filename,
268
- @organization.id
269
- )
270
-
271
- # Mock response
272
- response = mock('response')
273
- response.stubs(:code).returns(200)
274
-
275
- # Verify execute_cloud_request is called (which handles proxy)
276
- # We can't test the actual proxy parameters because CloudRequest concern
277
- # merges them internally, but we can verify the method is called
278
- action.expects(:execute_cloud_request).returns(response)
279
-
280
- # Stub upload_file to call execute_cloud_request (avoiding SSL cert creation issues)
281
- action.stubs(:upload_file).returns(nil)
282
-
283
- # Manually call upload_file expectations in the test
284
- # This simulates what would happen during actual execution
285
- action.send(:execute_cloud_request,
286
- method: :post,
287
- url: ForemanInventoryUpload.upload_url,
288
- payload: { multipart: true },
289
- headers: { 'X-Org-Id' => @organization.label })
290
- end
291
-
292
- test 'file cleanup when upload aborted due to missing certificate' do
293
- # Remove certificate from organization
294
- Organization.any_instance.stubs(:owner_details).returns({})
295
-
296
- # Create a real test file to verify it's not moved
297
- FileUtils.mkdir_p(@uploads_folder)
298
- test_file = File.join(@uploads_folder, 'test_file_for_cleanup.tar.xz')
299
- FileUtils.touch(test_file)
300
-
301
- begin
302
- action = create_and_plan_action(
303
- ForemanInventoryUpload::Async::UploadReportDirectJob,
304
- test_file,
305
- @organization.id
306
- )
307
-
308
- # Execute the action
309
- action.send(:try_execute)
310
-
311
- # Verify file still exists (not moved or deleted)
312
- assert File.exist?(test_file), "File should remain when upload is aborted"
313
-
314
- # Verify progress output mentions missing certificate
315
- label = ForemanInventoryUpload::Async::UploadReportDirectJob.output_label(@organization.id)
316
- output = ForemanInventoryUpload::Async::ProgressOutput.get(label).full_output
317
- assert_match(/Skipping organization.*no candlepin certificate/, output)
318
-
319
- # Verify status indicates abortion
320
- status = ForemanInventoryUpload::Async::ProgressOutput.get(label).status
321
- assert_match(/exit 1/, status)
322
- ensure
323
- FileUtils.rm_f(test_file) if File.exist?(test_file)
324
- end
325
- end
326
-
327
- test 'file cleanup when upload aborted due to disconnected mode' do
328
- Setting.stubs(:[]).with(:subscription_connection_enabled).returns(false)
329
-
330
- # Create a real test file
331
- FileUtils.mkdir_p(@uploads_folder)
332
- test_file = File.join(@uploads_folder, 'test_file_disconnected.tar.xz')
333
- FileUtils.touch(test_file)
334
-
335
- begin
336
- action = create_and_plan_action(
337
- ForemanInventoryUpload::Async::UploadReportDirectJob,
338
- test_file,
339
- @organization.id
340
- )
341
-
342
- # Execute the action
343
- action.send(:try_execute)
344
-
345
- # Verify file still exists
346
- assert File.exist?(test_file), "File should remain when connection is disabled"
347
-
348
- # Verify progress output
349
- label = ForemanInventoryUpload::Async::UploadReportDirectJob.output_label(@organization.id)
350
- output = ForemanInventoryUpload::Async::ProgressOutput.get(label).full_output
351
- assert_match(/connection to Insights is not enabled/, output)
352
- ensure
353
- FileUtils.rm_f(test_file) if File.exist?(test_file)
354
- end
355
- end
356
-
357
- test 'FileUpload wrapper delegates to file object' do
358
- # Create test file
359
- FileUtils.mkdir_p(File.dirname(@filename))
360
- FileUtils.touch(@filename)
361
-
362
- file = File.open(@filename, 'rb')
363
- begin
364
- wrapped = ForemanInventoryUpload::Async::UploadReportDirectJob::FileUpload.new(
365
- file,
366
- content_type: 'application/test'
367
- )
368
-
369
- assert_equal 'application/test', wrapped.content_type
370
- assert_equal file.path, wrapped.path
371
- assert_respond_to wrapped, :read
372
- assert_respond_to wrapped, :close
373
- ensure
374
- file.close
375
- end
376
- end
377
-
378
- test 'FileUpload wrapper provides content_type for RestClient' do
379
- # Create test file
380
- FileUtils.mkdir_p(File.dirname(@filename))
381
- FileUtils.touch(@filename)
382
-
383
- file = File.open(@filename, 'rb')
384
- begin
385
- wrapped = ForemanInventoryUpload::Async::UploadReportDirectJob::FileUpload.new(
386
- file,
387
- content_type: 'application/vnd.redhat.qpc.tar+tgz'
388
- )
389
-
390
- # RestClient checks for these methods
391
- assert_respond_to wrapped, :read
392
- assert_respond_to wrapped, :path
393
- assert_respond_to wrapped, :content_type
394
- assert_equal 'application/vnd.redhat.qpc.tar+tgz', wrapped.content_type
395
- ensure
396
- file.close
397
- end
398
- end
399
- end
@@ -1,200 +0,0 @@
1
- require 'test_plugin_helper'
2
-
3
- class ForemanRhCloudIopMetadataTest < ActiveSupport::TestCase
4
- setup do
5
- # Clean up any existing IoP smart proxies
6
- SmartProxy.unscoped.with_features('iop').destroy_all
7
- end
8
-
9
- teardown do
10
- # Clean up
11
- SmartProxy.unscoped.with_features('iop').destroy_all
12
- end
13
-
14
- def create_iop_proxy(url: 'https://iop.example.com')
15
- feature = Feature.find_or_create_by(name: 'iop')
16
- proxy = FactoryBot.create(:smart_proxy, :url => url)
17
- # Clear any existing associations for this feature
18
- feature.reload
19
- feature.smart_proxies.clear
20
- proxy.features << feature
21
- proxy
22
- end
23
-
24
- describe 'plugin metadata' do
25
- test 'iop metadata is false when no IoP smart proxy exists' do
26
- # Ensure no IoP proxy exists
27
- refute ForemanRhCloud.with_iop_smart_proxy?
28
-
29
- # Plugin metadata should reflect this
30
- metadata = ::Foreman::Plugin.app_metadata_registry.all_plugin_metadata[:foreman_rh_cloud]
31
-
32
- # The value is a lambda, so we need to call it
33
- assert_kind_of Proc, metadata[:iop]
34
- refute metadata[:iop].call
35
- end
36
-
37
- test 'iop metadata is true when IoP smart proxy exists' do
38
- # Create an IoP smart proxy
39
- create_iop_proxy
40
-
41
- # Verify proxy exists
42
- assert ForemanRhCloud.with_iop_smart_proxy?
43
-
44
- # Plugin metadata should reflect this
45
- metadata = ::Foreman::Plugin.app_metadata_registry.all_plugin_metadata[:foreman_rh_cloud]
46
-
47
- # The value is a lambda, so we need to call it
48
- assert_kind_of Proc, metadata[:iop]
49
- assert metadata[:iop].call
50
- end
51
-
52
- test 'iop metadata updates when IoP smart proxy is created' do
53
- # Initially no IoP proxy
54
- metadata = ::Foreman::Plugin.app_metadata_registry.all_plugin_metadata[:foreman_rh_cloud]
55
- refute metadata[:iop].call
56
-
57
- # Create an IoP smart proxy
58
- create_iop_proxy
59
-
60
- # Metadata should now return true
61
- assert metadata[:iop].call
62
- end
63
-
64
- test 'iop metadata updates when IoP smart proxy is destroyed' do
65
- # Create an IoP smart proxy
66
- proxy = create_iop_proxy
67
-
68
- metadata = ::Foreman::Plugin.app_metadata_registry.all_plugin_metadata[:foreman_rh_cloud]
69
- assert metadata[:iop].call
70
-
71
- # Destroy the proxy
72
- proxy.destroy
73
-
74
- # Metadata should now return false
75
- refute metadata[:iop].call
76
- end
77
- end
78
-
79
- describe 'URL methods' do
80
- test 'base_url returns cloud URL when no IoP smart proxy exists' do
81
- assert_equal 'https://cloud.redhat.com', ForemanRhCloud.base_url
82
- end
83
-
84
- test 'cert_base_url returns cloud URL when no IoP smart proxy exists' do
85
- assert_equal 'https://cert.cloud.redhat.com', ForemanRhCloud.cert_base_url
86
- end
87
-
88
- test 'legacy_insights_url returns cloud URL when no IoP smart proxy exists' do
89
- assert_equal 'https://cert-api.access.redhat.com', ForemanRhCloud.legacy_insights_url
90
- end
91
-
92
- test 'base_url returns IoP URL when IoP smart proxy exists' do
93
- create_iop_proxy
94
-
95
- assert_equal 'https://iop.example.com', ForemanRhCloud.base_url
96
- end
97
-
98
- test 'cert_base_url returns IoP URL when IoP smart proxy exists' do
99
- create_iop_proxy
100
-
101
- assert_equal 'https://iop.example.com', ForemanRhCloud.cert_base_url
102
- end
103
-
104
- test 'legacy_insights_url returns IoP URL when IoP smart proxy exists' do
105
- create_iop_proxy
106
-
107
- assert_equal 'https://iop.example.com', ForemanRhCloud.legacy_insights_url
108
- end
109
-
110
- test 'base_url returns ENV var when set' do
111
- ENV['SATELLITE_RH_CLOUD_URL'] = 'https://custom.example.com'
112
-
113
- assert_equal 'https://custom.example.com', ForemanRhCloud.base_url
114
- ensure
115
- ENV.delete('SATELLITE_RH_CLOUD_URL')
116
- end
117
-
118
- test 'cert_base_url returns ENV var when set' do
119
- ENV['SATELLITE_CERT_RH_CLOUD_URL'] = 'https://env-cert.cloud.test'
120
-
121
- assert_equal 'https://env-cert.cloud.test', ForemanRhCloud.cert_base_url
122
- ensure
123
- ENV.delete('SATELLITE_CERT_RH_CLOUD_URL')
124
- end
125
-
126
- test 'legacy_insights_url returns ENV var when set' do
127
- ENV['SATELLITE_LEGACY_INSIGHTS_URL'] = 'https://env-legacy.insights.test'
128
-
129
- assert_equal 'https://env-legacy.insights.test', ForemanRhCloud.legacy_insights_url
130
- ensure
131
- ENV.delete('SATELLITE_LEGACY_INSIGHTS_URL')
132
- end
133
-
134
- test 'base_url prefers IoP URL over ENV var' do
135
- ENV['SATELLITE_RH_CLOUD_URL'] = 'https://custom.example.com'
136
-
137
- create_iop_proxy
138
-
139
- # IoP URL should take precedence
140
- assert_equal 'https://iop.example.com', ForemanRhCloud.base_url
141
- ensure
142
- ENV.delete('SATELLITE_RH_CLOUD_URL')
143
- end
144
-
145
- test 'cert_base_url prefers IoP URL over ENV var' do
146
- ENV['SATELLITE_CERT_RH_CLOUD_URL'] = 'https://env-cert.cloud.test'
147
-
148
- create_iop_proxy
149
-
150
- # IoP URL should take precedence
151
- assert_equal 'https://iop.example.com', ForemanRhCloud.cert_base_url
152
- ensure
153
- ENV.delete('SATELLITE_CERT_RH_CLOUD_URL')
154
- end
155
-
156
- test 'legacy_insights_url prefers IoP URL over ENV var' do
157
- ENV['SATELLITE_LEGACY_INSIGHTS_URL'] = 'https://env-legacy.insights.test'
158
-
159
- create_iop_proxy
160
-
161
- # IoP URL should take precedence
162
- assert_equal 'https://iop.example.com', ForemanRhCloud.legacy_insights_url
163
- ensure
164
- ENV.delete('SATELLITE_LEGACY_INSIGHTS_URL')
165
- end
166
-
167
- test 'URL methods update when IoP smart proxy is created' do
168
- # Initially returns cloud URLs
169
- assert_equal 'https://cloud.redhat.com', ForemanRhCloud.base_url
170
- assert_equal 'https://cert.cloud.redhat.com', ForemanRhCloud.cert_base_url
171
- assert_equal 'https://cert-api.access.redhat.com', ForemanRhCloud.legacy_insights_url
172
-
173
- # Create an IoP smart proxy
174
- create_iop_proxy
175
-
176
- # Should now return IoP URL for all helpers
177
- assert_equal 'https://iop.example.com', ForemanRhCloud.base_url
178
- assert_equal 'https://iop.example.com', ForemanRhCloud.cert_base_url
179
- assert_equal 'https://iop.example.com', ForemanRhCloud.legacy_insights_url
180
- end
181
-
182
- test 'URL methods update when IoP smart proxy is destroyed' do
183
- # Create an IoP smart proxy
184
- proxy = create_iop_proxy
185
-
186
- # Initially returns IoP URL for all helpers
187
- assert_equal 'https://iop.example.com', ForemanRhCloud.base_url
188
- assert_equal 'https://iop.example.com', ForemanRhCloud.cert_base_url
189
- assert_equal 'https://iop.example.com', ForemanRhCloud.legacy_insights_url
190
-
191
- # Destroy the proxy
192
- proxy.destroy
193
-
194
- # Should now return cloud URLs again
195
- assert_equal 'https://cloud.redhat.com', ForemanRhCloud.base_url
196
- assert_equal 'https://cert.cloud.redhat.com', ForemanRhCloud.cert_base_url
197
- assert_equal 'https://cert-api.access.redhat.com', ForemanRhCloud.legacy_insights_url
198
- end
199
- end
200
- end