foreman_rh_cloud 3.0.33 → 4.0.21.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_inventory_upload/reports_controller.rb +1 -3
  3. data/app/controllers/foreman_inventory_upload/tasks_controller.rb +13 -5
  4. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +4 -4
  5. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +7 -29
  6. data/app/controllers/insights_cloud/hits_controller.rb +3 -7
  7. data/app/models/insights_client_report_status.rb +22 -11
  8. data/app/services/foreman_rh_cloud/cloud_auth.rb +0 -16
  9. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +17 -27
  10. data/app/services/foreman_rh_cloud/remediations_retriever.rb +4 -6
  11. data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +9 -0
  12. data/config/Gemfile.lock.gh_test +95 -93
  13. data/config/database.yml.example +2 -2
  14. data/config/routes.rb +1 -20
  15. data/lib/foreman_inventory_upload/generators/fact_helpers.rb +1 -22
  16. data/lib/foreman_inventory_upload/generators/queries.rb +0 -1
  17. data/lib/foreman_inventory_upload/generators/slice.rb +5 -6
  18. data/lib/foreman_inventory_upload/generators/tags.rb +2 -11
  19. data/lib/foreman_inventory_upload.rb +1 -9
  20. data/lib/foreman_rh_cloud/engine.rb +10 -17
  21. data/lib/foreman_rh_cloud/version.rb +1 -1
  22. data/lib/foreman_rh_cloud.rb +1 -12
  23. data/lib/insights_cloud/async/insights_full_sync.rb +14 -9
  24. data/lib/insights_cloud/async/insights_resolutions_sync.rb +6 -13
  25. data/lib/insights_cloud/async/insights_rules_sync.rb +9 -13
  26. data/lib/inventory_sync/async/host_result.rb +5 -4
  27. data/lib/inventory_sync/async/inventory_full_sync.rb +10 -21
  28. data/lib/inventory_sync/async/inventory_hosts_sync.rb +3 -18
  29. data/lib/inventory_sync/async/inventory_scheduled_sync.rb +0 -12
  30. data/lib/inventory_sync/async/query_inventory_job.rb +5 -6
  31. data/lib/tasks/insights.rake +0 -15
  32. data/lib/tasks/rh_cloud_inventory.rake +1 -8
  33. data/package.json +3 -3
  34. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +0 -41
  35. data/test/factories/inventory_upload_factories.rb +1 -1
  36. data/test/jobs/insights_full_sync_test.rb +0 -1
  37. data/test/jobs/insights_resolutions_sync_test.rb +1 -11
  38. data/test/jobs/insights_rules_sync_test.rb +0 -1
  39. data/test/jobs/inventory_full_sync_test.rb +2 -38
  40. data/test/models/insights_client_report_status_test.rb +72 -70
  41. data/test/test_plugin_helper.rb +0 -55
  42. data/test/unit/fact_helpers_test.rb +2 -2
  43. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +3 -21
  44. data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +0 -1
  45. data/test/unit/slice_generator_test.rb +27 -70
  46. data/test/unit/tags_generator_test.rb +0 -56
  47. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +0 -11
  48. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +0 -11
  49. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/SyncButtonActions.js +63 -28
  50. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/SyncButton/__tests__/__snapshots__/integrations.test.js.snap +3 -2
  51. data/webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableActions.js +19 -19
  52. data/webpack/InsightsCloudSync/Components/InsightsTable/__tests__/__snapshots__/InsightsTableActions.test.js.snap +14 -14
  53. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediateButton.js +0 -1
  54. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +0 -14
  55. data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +13 -20
  56. data/webpack/InsightsCloudSync/InsightsCloudSync.js +1 -4
  57. data/webpack/InsightsCloudSync/InsightsCloudSyncActions.js +20 -44
  58. data/webpack/InsightsCloudSync/InsightsCloudSyncConstants.js +0 -2
  59. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +2 -2
  60. data/webpack/InsightsCloudSync/__tests__/__snapshots__/InsightsCloudSyncActions.test.js.snap +7 -11
  61. metadata +4 -32
  62. data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +0 -50
  63. data/app/controllers/concerns/inventory_upload/report_actions.rb +0 -26
  64. data/app/controllers/concerns/inventory_upload/task_actions.rb +0 -25
  65. data/app/helpers/foreman_insights_deprecations_helper.rb +0 -9
  66. data/app/helpers/foreman_insights_host_helper.rb +0 -19
  67. data/app/overrides/old_plugin_deprecation.rb +0 -20
  68. data/app/services/foreman_rh_cloud/cloud_request.rb +0 -14
  69. data/app/services/foreman_rh_cloud/insights_status_cleaner.rb +0 -17
  70. data/config/package-lock.json.plugin +0 -32774
  71. data/db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb +0 -6
  72. data/lib/insights_cloud/async/insights_client_status_aging.rb +0 -23
  73. data/lib/inventory_sync/async/inventory_self_host_sync.rb +0 -39
  74. data/test/controllers/inventory_upload/api/inventory_controller_test.rb +0 -53
  75. data/test/jobs/insights_client_status_aging_test.rb +0 -33
  76. data/test/jobs/inventory_hosts_sync_test.rb +0 -283
  77. data/test/jobs/inventory_scheduled_sync_test.rb +0 -22
  78. data/test/jobs/inventory_self_host_sync_test.rb +0 -104
  79. data/test/unit/foreman_rh_cloud_self_host_test.rb +0 -28
  80. data/test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb +0 -31
  81. data/webpack/common/ForemanTasks/ForemanTasksActions.js +0 -64
  82. data/webpack/common/ForemanTasks/ForemanTasksHelpers.js +0 -7
  83. data/webpack/common/ForemanTasks/index.js +0 -1
@@ -1,75 +1,77 @@
1
1
  require 'test_plugin_helper'
2
2
 
3
3
  class InsightsClientReportStatusTest < ActiveSupport::TestCase
4
- setup do
5
- @host = FactoryBot.create(:host, :managed)
6
- end
7
-
8
- test 'fresh host does not have insights status' do
9
- @host.reload
10
-
11
- refute @host.host_statuses.where(type: 'InsightsClientReportStatus').exists?
12
- insights_status = @host.get_status(InsightsClientReportStatus)
13
- refute insights_status.relevant?
14
- end
15
-
16
- test 'host can refresh all its statuses' do
17
- @host.refresh_statuses
18
- @host.reload
19
-
20
- refute @host.host_statuses.where(type: 'InsightsClientReportStatus').exists?
21
- end
22
-
23
- test 'host with correct report status sets global status to OK' do
24
- global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
25
- # Status has to be OK before action
26
- assert_equal HostStatus::Global::OK, global_status.status
27
-
28
- # force create record
29
- @host.get_status(InsightsClientReportStatus).refresh!
30
- # now refresh should work
31
- @host.refresh_statuses([InsightsClientReportStatus])
32
-
33
- @host.reload
34
- global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
35
- # Status has to be OK after the action too
36
- assert_equal HostStatus::Global::OK, global_status.status
37
-
38
- insights_status = @host.get_status(InsightsClientReportStatus)
39
- # assert the status would be displayed
40
- assert insights_status.relevant?
41
- end
42
-
43
- test 'host will return to OK once the status is refreshed' do
44
- global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
45
- # Status has to be OK before action
46
- assert_equal HostStatus::Global::OK, global_status.status
47
-
48
- insights_status = @host.get_status(InsightsClientReportStatus)
49
- insights_status.status = InsightsClientReportStatus::NO_REPORT
50
- insights_status.save!
51
- @host.refresh_global_status!
52
- global_status = @host.global_status
53
- assert_equal HostStatus::Global::ERROR, global_status
54
-
55
- @host.refresh_statuses([InsightsClientReportStatus])
56
-
57
- @host.reload
58
- # Status has to be OK after the action too
59
- assert_equal HostStatus::Global::OK, @host.global_status
60
- end
61
-
62
- test 'host with stale status would set global to ERROR' do
63
- global_status = @host.get_status(HostStatus.find_status_by_humanized_name('Global'))
64
- # Status has to be OK before action
65
- assert_equal HostStatus::Global::OK, global_status.status
66
-
67
- insights_status = @host.get_status(InsightsClientReportStatus)
68
- insights_status.status = InsightsClientReportStatus::NO_REPORT
69
- insights_status.save!
70
- @host.refresh_global_status!
71
- @host.reload
72
-
73
- assert_equal HostStatus::Global::ERROR, @host.global_status
4
+ describe 'to_status' do
5
+ let(:host) { FactoryBot.create(:host, :managed) }
6
+
7
+ setup do
8
+ CommonParameter.where(name: 'host_registration_insights').destroy_all
9
+ end
10
+
11
+ test 'host_registration_insights = true & is getting data' do
12
+ FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
13
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
14
+
15
+ assert_equal 0, host_status.to_status(data: true)
16
+ end
17
+
18
+ test 'host_registration_insights = true & no data in less than 48 hours' do
19
+ FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
20
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
21
+ host_status.update(reported_at: 1.day.ago)
22
+ assert_equal 0, host_status.to_status
23
+ end
24
+
25
+ test 'host_registration_insights = true & no data in more than 48 hours' do
26
+ FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
27
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
28
+ host_status.update(reported_at: 3.days.ago)
29
+ assert_equal 1, host_status.to_status
30
+ end
31
+
32
+ test 'host_registration_insights = false & no data' do
33
+ FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false)
34
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
35
+ assert_equal 2, host_status.to_status
36
+ end
37
+
38
+ test 'host_registration_insights = false & getting data' do
39
+ FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false)
40
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
41
+ assert_equal 3, host_status.to_status(data: true)
42
+ end
43
+
44
+ test 'host_registration_insights = nil & is getting data' do
45
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
46
+ assert_equal 3, host_status.to_status(data: true)
47
+ end
48
+
49
+ test 'host_registration_insights = nil & no data in less than 48 hours' do
50
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
51
+ host_status.update(reported_at: 1.day.ago)
52
+ assert_equal 2, host_status.to_status
53
+ end
54
+
55
+ test 'host_registration_insights = nil & no data in more than 48 hours' do
56
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
57
+ host_status.update(reported_at: 3.days.ago)
58
+ assert_equal 2, host_status.to_status
59
+ end
60
+
61
+ test 'override param on host level from `false` to `true`' do
62
+ FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false)
63
+ FactoryBot.create(:host_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true, host: host)
64
+
65
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
66
+ assert_equal 0, host_status.to_status(data: true)
67
+ end
68
+
69
+ test 'override param on host level from `true` to `false`' do
70
+ FactoryBot.create(:common_parameter, name: 'host_registration_insights', key_type: 'boolean', value: true)
71
+ FactoryBot.create(:host_parameter, name: 'host_registration_insights', key_type: 'boolean', value: false, host: host)
72
+
73
+ host_status = Host.find_by_name(host.name).reload.get_status(InsightsClientReportStatus)
74
+ assert_equal 2, host_status.to_status
75
+ end
74
76
  end
75
77
  end
@@ -2,8 +2,6 @@
2
2
  require 'test_helper'
3
3
 
4
4
  # Add plugin to FactoryBot's paths
5
- FactoryBot.definition_file_paths << "#{ForemanTasks::Engine.root}/test/factories"
6
- FactoryBot.definition_file_paths << "#{ForemanRemoteExecution::Engine.root}/test/factories"
7
5
  FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
8
6
  # FactoryBot.definition_file_paths << "#{Katello::Engine.root}/test/factories"
9
7
  FactoryBot.reload
@@ -39,56 +37,3 @@ module KatelloLocationFix
39
37
  end
40
38
  end
41
39
  end
42
-
43
- module MockCerts
44
- extend ActiveSupport::Concern
45
-
46
- def test_certificate
47
- @test_certificate ||= "-----BEGIN CERTIFICATE-----\r\n" +
48
- "MIIFdDCCA1ygAwIBAgIJAM5Uqykb3EAtMA0GCSqGSIb3DQEBCwUAME8xCzAJBgNV\r\n" +
49
- "BAYTAklMMREwDwYDVQQIDAhUZWwgQXZpdjEUMBIGA1UECgwLVGhlIEZvcmVtYW4x\r\n" +
50
- "FzAVBgNVBAMMDnRoZWZvcmVtYW4ub3JnMB4XDTE4MDMyNDEyMzYyOFoXDTI4MDMy\r\n" +
51
- "MTEyMzYyOFowTzELMAkGA1UEBhMCSUwxETAPBgNVBAgMCFRlbCBBdml2MRQwEgYD\r\n" +
52
- "VQQKDAtUaGUgRm9yZW1hbjEXMBUGA1UEAwwOdGhlZm9yZW1hbi5vcmcwggIiMA0G\r\n" +
53
- "CSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDF04/s4h+BgHPG1HDZ/sDlYq925pkc\r\n" +
54
- "RTVAfnE2EXDAmZ6W4Q9ueDY65MHe3ZWO5Dg72kNSP2sK9kRI7Dk5CAFOgyw1rH8t\r\n" +
55
- "Hd1+0xp/lv6e4SvSYghxIL68vFe0ftKkm1usqejBM5ZTgKr7JCI+XSIN36F65Kde\r\n" +
56
- "c+vxwBnayuhP04r9/aaE/709SXML4eRVYW8I3qFy9FPtUOm+bY8U2PIv5fHayqbG\r\n" +
57
- "cL/4t3+MCtMhHJsLzdBXya+1P5t+HcKjUNlmwoUF961YAktVuEFloGd0RMRlqF3/\r\n" +
58
- "itU3QNlXgA5QBIciE5VPr/PiqgMC3zgd5avjF4OribZ+N9AATLiQMW78il5wSfcc\r\n" +
59
- "kQjU9ChOLrzku455vQ8KE4bc0qvpCWGfUah6MvL9JB+TQkRl/8kxl0b9ZinIvJDH\r\n" +
60
- "ynVMb4cB/TDEjrjOfzn9mWLH0ZJqjmc2bER/G12WQxOaYLxdVwRStD3Yh6PtiFWu\r\n" +
61
- "sXOk19UOTVkeuvGFVtvzLfEwQ1lDEo7+VBQz8FG/HBu2Hpq3IwCFrHuicikwjQJk\r\n" +
62
- "nfturgD0rBOKEc1qWNZRCvovYOLL6ihvv5Orujsx5ZCHOAtnVNxkvIlFt2RS45LF\r\n" +
63
- "MtPJyhAc6SjitllfUEirxprsbmeSZqrIfzcGaEhgOSnyik1WMv6bYiqPfBg8Fzjh\r\n" +
64
- "vOCbtiDNPmvgOwIDAQABo1MwUTAdBgNVHQ4EFgQUtkAgQopsTtG9zSG3MgW2IxHD\r\n" +
65
- "MDwwHwYDVR0jBBgwFoAUtkAgQopsTtG9zSG3MgW2IxHDMDwwDwYDVR0TAQH/BAUw\r\n" +
66
- "AwEB/zANBgkqhkiG9w0BAQsFAAOCAgEAJq7iN+ZroRBweNhvUobxs75bLIV6tNn1\r\n" +
67
- "MdNHDRA+hezwf+gxHZhFyaAHfTpst2/9leK5Qe5Zd6gZLr3E5/8ppQuRod72H39B\r\n" +
68
- "vxMlG5zxDss0WMo3vZeKZbTY6QhXi/lY2IZ6OGV4feSvCsYxn27GTjjrRUSLFeHH\r\n" +
69
- "JVemCwCDMavaE3+OIY4v2P4FcG+MjUvfOB9ahI24TWL7YgrsNVmJjCILq+EeUj0t\r\n" +
70
- "Gde1SXVyLkqt7PoxHRJAE0BCEMJSnjxaVB329acJgeehBUxjj4CCPqtDxtbz9HEH\r\n" +
71
- "mOKfNdaKpFor+DUeEKUWVGnr9U9xOaC+Ws+oX7MIEUCDM7p2ob4JwcjnFs1jZgHh\r\n" +
72
- "Hwig+i7doTlc701PvKWO96fuNHK3B3/jTb1fVvSZ49O/RvY1VWODdUdxWmXGHNh3\r\n" +
73
- "LoR8tSPEb46lC2DXGaIQumqQt8PnBG+vL1qkQa1SGTV7dJ8TTbxbv0S+sS+igkk9\r\n" +
74
- "zsIEK8Ea3Ep935cXximz0faAAKHSA+It+xHLAyDtqy2KaAEBgGsBuuWlUfK6TaP3\r\n" +
75
- "Gwdjct3y4yYUO45lUsUfHqX8vk/4ttW5zYeDiW+HArJz+9VUXNbEdury4kGuHgBj\r\n" +
76
- "xHD4Bsul65+hHZ9QywKU26F1A6TLkYpQ2rk/Dx9LGICM4m4IlHjWJPFsQdtkyOor\r\n" +
77
- "osxMtcaZZ1E=\r\n" +
78
- "-----END CERTIFICATE-----"
79
- end
80
-
81
- def generate_certs_hash
82
- {
83
- cert: test_certificate,
84
- key: OpenSSL::PKey::RSA.new(1024).to_pem,
85
- }
86
- end
87
-
88
- def setup_certs_expectation
89
- expectation = yield
90
- expectation.returns(
91
- generate_certs_hash
92
- )
93
- end
94
- end
@@ -30,13 +30,13 @@ class FactHelpersTest < ActiveSupport::TestCase
30
30
  test 'obfuscates ips with insights-client data' do
31
31
  host = mock('host')
32
32
  @instance.expects(:fact_value).with(host, 'insights_client::ips').returns(
33
- '[{"obfuscated": "10.230.230.1", "original": "224.0.0.1"}, {"obfuscated": "10.230.230.255", "original": "224.0.0.251"}]'
33
+ '[{"obfuscated": "10.230.230.1", "original": "224.0.0.1"}, {"obfuscated": "10.230.230.2", "original": "224.0.0.251"}]'
34
34
  )
35
35
 
36
36
  actual = @instance.obfuscated_ips(host)
37
37
 
38
38
  assert_equal '10.230.230.1', actual['224.0.0.1']
39
- assert_equal '10.230.231.0', actual['224.0.0.2']
39
+ assert_equal '10.230.230.3', actual['224.0.0.2']
40
40
  end
41
41
 
42
42
  test 'obfuscates ips without insights-client data' do
@@ -42,13 +42,12 @@ class CloudRequestForwarderTest < ActiveSupport::TestCase
42
42
  test 'should prepare correct cloud url' do
43
43
  paths = {
44
44
  "/redhat_access/r/insights/platform/module-update-router/v1/channel?module=insights-core" => "https://cert.cloud.redhat.com/api/module-update-router/v1/channel?module=insights-core",
45
- "/redhat_access/r/insights/v1/static/release/insights-core.egg" => "https://cert-api.access.redhat.com/r/insights/v1/static/release/insights-core.egg",
46
- "/redhat_access/r/insights/v1/static/uploader.v2.json" => "https://cert-api.access.redhat.com/r/insights/v1/static/uploader.v2.json",
47
- "/redhat_access/r/insights/v1/static/uploader.v2.json.asc" => "https://cert-api.access.redhat.com/r/insights/v1/static/uploader.v2.json.asc",
45
+ "/redhat_access/r/insights/v1/static/release/insights-core.egg" => "https://cloud.redhat.com/api/v1/static/release/insights-core.egg",
46
+ "/redhat_access/r/insights/v1/static/uploader.v2.json" => "https://cloud.redhat.com/api/v1/static/uploader.v2.json",
47
+ "/redhat_access/r/insights/v1/static/uploader.v2.json.asc" => "https://cloud.redhat.com/api/v1/static/uploader.v2.json.asc",
48
48
  "/redhat_access/r/insights/platform/inventory/v1/hosts" => "https://cert.cloud.redhat.com/api/inventory/v1/hosts",
49
49
  "/redhat_access/r/insights/platform/ingress/v1/upload" => "https://cert.cloud.redhat.com/api/ingress/v1/upload",
50
50
  "/redhat_access/r/insights/uploads/67200803-132b-474b-a6f9-37be74185df4" => "https://cert-api.access.redhat.com/r/insights/uploads/67200803-132b-474b-a6f9-37be74185df4",
51
- "/redhat_access/r/insights/" => "https://cert.cloud.redhat.com/api/apicast-tests/ping",
52
51
  }
53
52
 
54
53
  paths.each do |key, value|
@@ -139,21 +138,4 @@ class CloudRequestForwarderTest < ActiveSupport::TestCase
139
138
  )
140
139
  assert_equal params.merge(:branch_id => 74), @forwarder.prepare_forward_params(req, 74)
141
140
  end
142
-
143
- test 'should forward content type correctly' do
144
- user_agent = { :foo => :bar }
145
- params = { :page => 5, :per_page => 42 }
146
-
147
- req = ActionDispatch::Request.new(
148
- 'REQUEST_URI' => '/foo/bar',
149
- 'REQUEST_METHOD' => 'GET',
150
- 'HTTP_USER_AGENT' => user_agent,
151
- 'rack.input' => ::Puma::NullIO.new,
152
- 'action_dispatch.request.query_parameters' => params
153
- )
154
-
155
- actual = @forwarder.prepare_request_opts(req, 'TEST PAYLOAD', params, { cert: @cert1, key: OpenSSL::PKey::RSA.new(1024).to_pem })
156
-
157
- assert_match /text\/html/, actual[:headers][:content_type]
158
- end
159
141
  end
@@ -8,7 +8,6 @@ class TemplateRendererHelperTest < ActiveSupport::TestCase
8
8
  response.stubs(:body).returns('TEST PLAYBOOK')
9
9
  ForemanRhCloud::RemediationsRetriever.any_instance.stubs(:query_playbook).returns(response)
10
10
  @host1 = FactoryBot.create(:host)
11
- FactoryBot.create(:setting, name: 'rh_cloud_token', value: 'MOCK_TOKEN')
12
11
  end
13
12
 
14
13
  test 'Generates a playbook for hit and remediation' do
@@ -53,7 +53,6 @@ class SliceGeneratorTest < ActiveSupport::TestCase
53
53
  'insights_client::hostname',
54
54
  'insights_client::obfuscate_ip_enabled',
55
55
  'insights_client::ips',
56
- 'insights_id',
57
56
  ]
58
57
  end
59
58
 
@@ -72,7 +71,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
72
71
  json_str = generator.render
73
72
  actual = JSON.parse(json_str.join("\n"))
74
73
 
75
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
74
+ assert_equal 'slice_123', actual['report_slice_id']
76
75
  assert_not_nil(actual_host = actual['hosts'].first)
77
76
  assert_nil actual_host['ip_addresses']
78
77
  assert_nil actual_host['mac_addresses']
@@ -103,7 +102,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
103
102
  json_str = generator.render
104
103
  actual = JSON.parse(json_str.join("\n"))
105
104
 
106
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
105
+ assert_equal 'slice_123', actual['report_slice_id']
107
106
  assert_not_nil(actual_host = actual['hosts'].first)
108
107
  assert_not_nil(actual_system_profile = actual_host['system_profile'])
109
108
  assert_equal 4, actual_system_profile['number_of_cpus']
@@ -121,7 +120,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
121
120
  json_str = generator.render
122
121
  actual = JSON.parse(json_str.join("\n"))
123
122
 
124
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
123
+ assert_equal 'slice_123', actual['report_slice_id']
125
124
  assert_not_nil(actual_host = actual['hosts'].first)
126
125
  assert_equal @host.interfaces.where.not(ip: nil).first.ip, actual_host['ip_addresses'].first
127
126
  assert_equal @host.interfaces.where.not(mac: nil).first.mac, actual_host['mac_addresses'].first
@@ -143,7 +142,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
143
142
  json_str = generator.render
144
143
  actual = JSON.parse(json_str.join("\n"))
145
144
 
146
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
145
+ assert_equal 'slice_123', actual['report_slice_id']
147
146
  assert_not_nil(actual_host = actual['hosts'].first)
148
147
  assert_equal @host.interfaces.where.not(ip: nil).first.ip, actual_host['ip_addresses'].first
149
148
  assert_equal @host.interfaces.where.not(mac: nil).first.mac, actual_host['mac_addresses'].first
@@ -173,7 +172,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
173
172
  json_str = generator.render
174
173
  actual = JSON.parse(json_str.join("\n"))
175
174
 
176
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
175
+ assert_equal 'slice_123', actual['report_slice_id']
177
176
  assert_not_nil(actual_host = actual['hosts'].first)
178
177
  assert_equal @host.interfaces.where.not(ip: nil).first.ip, actual_host['ip_addresses'].first
179
178
  assert_equal @host.interfaces.where.not(mac: nil).first.mac, actual_host['mac_addresses'].first
@@ -192,7 +191,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
192
191
  json_str = generator.render
193
192
  actual = JSON.parse(json_str.join("\n"))
194
193
 
195
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
194
+ assert_equal 'slice_123', actual['report_slice_id']
196
195
  assert_not_nil(actual_host = actual['hosts'].first)
197
196
  assert_equal '10.230.230.1', actual_host['ip_addresses'].first
198
197
  assert_not_nil(actual_system_profile = actual_host['system_profile'])
@@ -222,7 +221,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
222
221
  json_str = generator.render
223
222
  actual = JSON.parse(json_str.join("\n"))
224
223
 
225
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
224
+ assert_equal 'slice_123', actual['report_slice_id']
226
225
  assert_not_nil(actual_host = actual['hosts'].first)
227
226
  assert_equal '10.230.230.100', actual_host['ip_addresses'].first
228
227
  assert_not_nil(actual_system_profile = actual_host['system_profile'])
@@ -244,7 +243,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
244
243
  json_str = generator.render
245
244
  actual = JSON.parse(json_str.join("\n"))
246
245
 
247
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
246
+ assert_equal 'slice_123', actual['report_slice_id']
248
247
  assert_not_nil(actual_host = actual['hosts'].first)
249
248
  assert_equal 'obfuscated_name', actual_host['fqdn']
250
249
  assert_equal '1234', actual_host['account']
@@ -264,7 +263,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
264
263
 
265
264
  obfuscated_fqdn = Digest::SHA1.hexdigest(@host.fqdn) + '.example.com'
266
265
 
267
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
266
+ assert_equal 'slice_123', actual['report_slice_id']
268
267
  assert_not_nil(actual_host = actual['hosts'].first)
269
268
  assert_equal obfuscated_fqdn, actual_host['fqdn']
270
269
  assert_equal '1234', actual_host['account']
@@ -283,7 +282,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
283
282
  json_str = generator.render
284
283
  actual = JSON.parse(json_str.join("\n"))
285
284
 
286
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
285
+ assert_equal 'slice_123', actual['report_slice_id']
287
286
  assert_not_nil(actual_host = actual['hosts'].first)
288
287
  assert_equal @host.fqdn, actual_host['fqdn']
289
288
  assert_equal '1234', actual_host['account']
@@ -356,7 +355,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
356
355
  json_str = generator.render
357
356
  actual = JSON.parse(json_str.join("\n"))
358
357
 
359
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
358
+ assert_equal 'slice_123', actual['report_slice_id']
360
359
  assert_not_nil(actual_host = actual['hosts'].first)
361
360
  assert_equal @host.fqdn, actual_host['fqdn']
362
361
  assert_not_nil(host_facts = actual_host['facts']&.first)
@@ -378,7 +377,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
378
377
  json_str = generator.render
379
378
  actual = JSON.parse(json_str.join("\n"))
380
379
 
381
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
380
+ assert_equal 'slice_123', actual['report_slice_id']
382
381
  assert_not_nil(actual_host = actual['hosts'].first)
383
382
  assert_equal @host.fqdn, actual_host['fqdn']
384
383
  assert_not_nil(host_facts = actual_host['facts']&.first)
@@ -398,7 +397,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
398
397
  json_str = generator.render
399
398
  actual = JSON.parse(json_str.join("\n"))
400
399
 
401
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
400
+ assert_equal 'slice_123', actual['report_slice_id']
402
401
  assert_not_nil(actual_host = actual['hosts'].first)
403
402
  assert_equal @host.fqdn, actual_host['fqdn']
404
403
  assert_equal '1234', actual_host['account']
@@ -418,7 +417,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
418
417
  json_str = generator.render
419
418
  actual = JSON.parse(json_str.join("\n"))
420
419
 
421
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
420
+ assert_equal 'slice_123', actual['report_slice_id']
422
421
  assert_not_nil(actual_host = actual['hosts'].first)
423
422
  assert_equal @host.fqdn, actual_host['fqdn']
424
423
  assert_equal '1234', actual_host['account']
@@ -437,7 +436,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
437
436
  json_str = generator.render
438
437
  actual = JSON.parse(json_str.join("\n"))
439
438
 
440
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
439
+ assert_equal 'slice_123', actual['report_slice_id']
441
440
  assert_equal 1, generator.hosts_count
442
441
  end
443
442
 
@@ -450,7 +449,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
450
449
  json_str = generator.render
451
450
  actual = JSON.parse(json_str.join("\n"))
452
451
 
453
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
452
+ assert_equal 'slice_123', actual['report_slice_id']
454
453
  assert_not_nil(actual_host = actual['hosts'].first)
455
454
  assert_not_nil(actual_profile = actual_host['system_profile'])
456
455
  assert_equal 1024, actual_profile['system_memory_bytes']
@@ -476,7 +475,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
476
475
  json_str = generator.render
477
476
  actual = JSON.parse(json_str.join("\n"))
478
477
 
479
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
478
+ assert_equal 'slice_123', actual['report_slice_id']
480
479
  assert_not_nil(actual_host = actual['hosts'].first)
481
480
  assert_not_nil(actual_host['account'])
482
481
  assert_not_empty(actual_host['account'])
@@ -493,7 +492,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
493
492
  json_str = generator.render
494
493
  actual = JSON.parse(json_str.join("\n"))
495
494
 
496
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
495
+ assert_equal 'slice_123', actual['report_slice_id']
497
496
  assert_not_nil(actual_host = actual['hosts'].first)
498
497
  assert_not_nil(actual_profile = actual_host['system_profile'])
499
498
  assert_equal 'Red Hat Test Linux 7.1 (TestId)', actual_profile['os_release']
@@ -508,7 +507,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
508
507
  json_str = generator.render
509
508
  actual = JSON.parse(json_str.join("\n"))
510
509
 
511
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
510
+ assert_equal 'slice_123', actual['report_slice_id']
512
511
  assert_not_nil(actual_host = actual['hosts'].first)
513
512
  assert_not_nil(actual_profile = actual_host['system_profile'])
514
513
  assert_equal 'virtual', actual_profile['infrastructure_type']
@@ -523,7 +522,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
523
522
  json_str = generator.render
524
523
  actual = JSON.parse(json_str.join("\n"))
525
524
 
526
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
525
+ assert_equal 'slice_123', actual['report_slice_id']
527
526
  assert_not_nil(actual_host = actual['hosts'].first)
528
527
  assert_not_nil(actual_profile = actual_host['system_profile'])
529
528
  assert_equal 'physical', actual_profile['infrastructure_type']
@@ -538,7 +537,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
538
537
  json_str = generator.render
539
538
  actual = JSON.parse(json_str.join("\n"))
540
539
 
541
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
540
+ assert_equal 'slice_123', actual['report_slice_id']
542
541
  assert_not_nil(actual_host = actual['hosts'].first)
543
542
  assert_not_nil(actual_profile = actual_host['system_profile'])
544
543
  assert_equal 'aws', actual_profile['cloud_provider']
@@ -553,7 +552,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
553
552
  json_str = generator.render
554
553
  actual = JSON.parse(json_str.join("\n"))
555
554
 
556
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
555
+ assert_equal 'slice_123', actual['report_slice_id']
557
556
  assert_not_nil(actual_host = actual['hosts'].first)
558
557
  assert_not_nil(actual_profile = actual_host['system_profile'])
559
558
  assert_equal 'google', actual_profile['cloud_provider']
@@ -568,7 +567,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
568
567
  json_str = generator.render
569
568
  actual = JSON.parse(json_str.join("\n"))
570
569
 
571
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
570
+ assert_equal 'slice_123', actual['report_slice_id']
572
571
  assert_not_nil(actual_host = actual['hosts'].first)
573
572
  assert_not_nil(actual_profile = actual_host['system_profile'])
574
573
  assert_equal 'azure', actual_profile['cloud_provider']
@@ -583,7 +582,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
583
582
  json_str = generator.render
584
583
  actual = JSON.parse(json_str.join("\n"))
585
584
 
586
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
585
+ assert_equal 'slice_123', actual['report_slice_id']
587
586
  assert_not_nil(actual_host = actual['hosts'].first)
588
587
  assert_not_nil(actual_profile = actual_host['system_profile'])
589
588
  assert_equal 'alibaba', actual_profile['cloud_provider']
@@ -598,7 +597,7 @@ class SliceGeneratorTest < ActiveSupport::TestCase
598
597
  json_str = generator.render
599
598
  actual = JSON.parse(json_str.join("\n"))
600
599
 
601
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
600
+ assert_equal 'slice_123', actual['report_slice_id']
602
601
  assert_not_nil(actual_host = actual['hosts'].first)
603
602
  assert_not_nil(actual_profile = actual_host['system_profile'])
604
603
  assert_equal 'alibaba', actual_profile['cloud_provider']
@@ -624,57 +623,15 @@ class SliceGeneratorTest < ActiveSupport::TestCase
624
623
  json_str = generator.render
625
624
  actual = JSON.parse(json_str.join("\n"))
626
625
 
627
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
626
+ assert_equal 'slice_123', actual['report_slice_id']
628
627
  assert_not_nil(actual_host = actual['hosts'].first)
629
628
  assert_not_nil(actual_profile = actual_host['system_profile'])
630
629
  assert_not_nil(actual_profile['installed_packages'])
631
630
  end
632
631
 
633
- test 'omits malformed bios_uuid field' do
634
- FactoryBot.create(:fact_value, fact_name: fact_names['dmi::system::uuid'], value: 'test value', host: @host)
635
-
636
- batch = Host.where(id: @host.id).in_batches.first
637
- generator = create_generator(batch)
638
-
639
- json_str = generator.render
640
- actual = JSON.parse(json_str.join("\n"))
641
-
642
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
643
- assert_not_nil(actual_host = actual['hosts'].first)
644
- assert_nil actual_host['bios_uuid']
645
- end
646
-
647
- test 'passes valid bios_uuid field' do
648
- FactoryBot.create(:fact_value, fact_name: fact_names['dmi::system::uuid'], value: 'D30B0B42-7824-2635-C62D-491394DE43F7', host: @host)
649
-
650
- batch = Host.where(id: @host.id).in_batches.first
651
- generator = create_generator(batch)
652
-
653
- json_str = generator.render
654
- actual = JSON.parse(json_str.join("\n"))
655
-
656
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
657
- assert_not_nil(actual_host = actual['hosts'].first)
658
- assert_not_nil actual_host['bios_uuid']
659
- end
660
-
661
- test 'passes valid insights_id field' do
662
- FactoryBot.create(:fact_value, fact_name: fact_names['insights_id'], value: 'D30B0B42-7824-2635-C62D-491394DE43F7', host: @host)
663
-
664
- batch = Host.where(id: @host.id).in_batches.first
665
- generator = create_generator(batch)
666
-
667
- json_str = generator.render
668
- actual = JSON.parse(json_str.join("\n"))
669
-
670
- assert_equal '00000000-0000-0000-0000-000000000000', actual['report_slice_id']
671
- assert_not_nil(actual_host = actual['hosts'].first)
672
- assert_not_nil actual_host['insights_id']
673
- end
674
-
675
632
  private
676
633
 
677
- def create_generator(batch, name = '00000000-0000-0000-0000-000000000000')
634
+ def create_generator(batch, name = 'slice_123')
678
635
  generator = ForemanInventoryUpload::Generators::Slice.new(batch, [], name)
679
636
  if block_given?
680
637
  yield(generator)
@@ -62,62 +62,6 @@ class TagsGeneratorTest < ActiveSupport::TestCase
62
62
  assert_equal false, actual.key?('content_view')
63
63
  end
64
64
 
65
- test 'generates parameter tags' do
66
- FactoryBot.create(:setting, :name => 'include_parameter_tags', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => true)
67
-
68
- @host.stubs(:host_inherited_params_objects).returns(
69
- [
70
- OpenStruct.new(name: 'bool_param', value: true),
71
- OpenStruct.new(name: 'false_param', value: false),
72
- OpenStruct.new(name: 'int_param', value: 1),
73
- OpenStruct.new(name: 'empty_param', value: nil),
74
- OpenStruct.new(name: 'empty_str_param', value: ''),
75
- ]
76
- )
77
-
78
- generator = create_generator
79
- actual = Hash[generator.generate_parameters]
80
-
81
- assert_equal 3, actual.count
82
- assert_equal true, actual['bool_param']
83
- assert_equal false, actual['false_param']
84
- assert_equal 1, actual['int_param']
85
- end
86
-
87
- test 'skips parameter tags if include_parameter_tags setting is off' do
88
- FactoryBot.create(:setting, :name => 'include_parameter_tags', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => false)
89
-
90
- @host.stubs(:host_inherited_params_objects).returns(
91
- [
92
- OpenStruct.new(name: 'bool_param', value: true),
93
- OpenStruct.new(name: 'false_param', value: false),
94
- OpenStruct.new(name: 'int_param', value: 1),
95
- OpenStruct.new(name: 'empty_param', value: nil),
96
- OpenStruct.new(name: 'empty_str_param', value: ''),
97
- ]
98
- )
99
-
100
- generator = create_generator
101
- actual = generator.generate_parameters.group_by { |key, value| key }
102
-
103
- assert_equal 0, actual.count
104
- end
105
-
106
- test 'truncates parameter tags' do
107
- FactoryBot.create(:setting, :name => 'include_parameter_tags', :settings_type => "boolean", :category => "Setting::RhCloud", :default => false, :value => true)
108
-
109
- @host.stubs(:host_inherited_params_objects).returns(
110
- [
111
- OpenStruct.new(name: 'str_param', value: 'a' * 251),
112
- ]
113
- )
114
-
115
- generator = create_generator
116
- actual = Hash[generator.generate_parameters]
117
-
118
- assert_equal 'Original value exceeds 250 characters', actual['str_param']
119
- end
120
-
121
65
  private
122
66
 
123
67
  def create_generator
@@ -31,17 +31,6 @@ export const PageDescription = () => (
31
31
  About subscription watch
32
32
  </a>
33
33
  </p>
34
- <p>
35
- {__('For more information about Insights and Cloud Connector read')}
36
- &nbsp;
37
- <a
38
- href="https://console.redhat.com/security/insights/"
39
- target="_blank"
40
- rel="noopener noreferrer"
41
- >
42
- Red Hat Insights Data and Application Security
43
- </a>
44
- </p>
45
34
  </div>
46
35
  );
47
36