foreman_rh_cloud 3.0.22 → 3.0.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/rh_cloud/inventory_controller.rb +50 -0
  3. data/app/controllers/concerns/inventory_upload/report_actions.rb +26 -0
  4. data/app/controllers/concerns/inventory_upload/task_actions.rb +25 -0
  5. data/app/controllers/foreman_inventory_upload/reports_controller.rb +3 -1
  6. data/app/controllers/foreman_inventory_upload/tasks_controller.rb +5 -13
  7. data/app/controllers/foreman_inventory_upload/uploads_controller.rb +4 -4
  8. data/app/controllers/insights_cloud/api/machine_telemetries_controller.rb +6 -3
  9. data/app/controllers/insights_cloud/hits_controller.rb +7 -3
  10. data/app/helpers/foreman_insights_deprecations_helper.rb +9 -0
  11. data/app/helpers/foreman_insights_host_helper.rb +19 -0
  12. data/app/models/insights_client_report_status.rb +11 -22
  13. data/app/overrides/old_plugin_deprecation.rb +20 -0
  14. data/app/services/foreman_rh_cloud/cloud_auth.rb +4 -0
  15. data/app/services/foreman_rh_cloud/cloud_request_forwarder.rb +0 -8
  16. data/app/services/foreman_rh_cloud/insights_status_cleaner.rb +17 -0
  17. data/app/services/foreman_rh_cloud/remediations_retriever.rb +5 -0
  18. data/config/package-lock.json.plugin +32774 -0
  19. data/config/routes.rb +19 -0
  20. data/db/migrate/20210720000001_remove_old_insights_statuses.foreman_rh_cloud.rb +6 -0
  21. data/lib/foreman_inventory_upload.rb +9 -1
  22. data/lib/foreman_inventory_upload/generators/queries.rb +1 -0
  23. data/lib/foreman_inventory_upload/generators/slice.rb +1 -0
  24. data/lib/foreman_inventory_upload/generators/tags.rb +3 -1
  25. data/lib/foreman_rh_cloud/engine.rb +17 -10
  26. data/lib/foreman_rh_cloud/version.rb +1 -1
  27. data/lib/insights_cloud/async/insights_client_status_aging.rb +23 -0
  28. data/lib/insights_cloud/async/insights_full_sync.rb +5 -0
  29. data/lib/insights_cloud/async/insights_resolutions_sync.rb +9 -0
  30. data/lib/insights_cloud/async/insights_rules_sync.rb +5 -0
  31. data/lib/inventory_sync/async/host_result.rb +4 -0
  32. data/lib/inventory_sync/async/inventory_full_sync.rb +5 -0
  33. data/lib/inventory_sync/async/inventory_hosts_sync.rb +21 -2
  34. data/lib/inventory_sync/async/inventory_scheduled_sync.rb +4 -0
  35. data/lib/inventory_sync/async/inventory_self_host_sync.rb +39 -0
  36. data/lib/inventory_sync/async/query_inventory_job.rb +5 -1
  37. data/lib/tasks/insights.rake +15 -0
  38. data/lib/tasks/rh_cloud_inventory.rake +2 -1
  39. data/package.json +2 -2
  40. data/test/controllers/insights_cloud/api/machine_telemetries_controller_test.rb +41 -0
  41. data/test/controllers/inventory_upload/api/inventory_controller_test.rb +53 -0
  42. data/test/jobs/insights_client_status_aging_test.rb +33 -0
  43. data/test/jobs/insights_full_sync_test.rb +1 -0
  44. data/test/jobs/insights_resolutions_sync_test.rb +1 -0
  45. data/test/jobs/insights_rules_sync_test.rb +1 -0
  46. data/test/jobs/inventory_full_sync_test.rb +10 -0
  47. data/test/jobs/inventory_hosts_sync_test.rb +268 -0
  48. data/test/jobs/inventory_scheduled_sync_test.rb +22 -0
  49. data/test/jobs/inventory_self_host_sync_test.rb +104 -0
  50. data/test/models/insights_client_report_status_test.rb +70 -72
  51. data/test/test_plugin_helper.rb +2 -0
  52. data/test/unit/services/foreman_rh_cloud/cloud_request_forwarder_test.rb +3 -3
  53. data/test/unit/services/foreman_rh_cloud/insights_status_cleaner_test.rb +31 -0
  54. data/test/unit/services/foreman_rh_cloud/template_renderer_helper_test.rb +1 -0
  55. data/test/unit/slice_generator_test.rb +15 -0
  56. data/test/unit/tags_generator_test.rb +41 -0
  57. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/PageDescription.js +11 -0
  58. data/webpack/ForemanInventoryUpload/Components/PageHeader/components/PageDescription/__tests__/__snapshots__/PageDescription.test.js.snap +11 -0
  59. data/webpack/InsightsCloudSync/Components/RemediationModal/RemediationModal.scss +14 -0
  60. data/webpack/InsightsCloudSync/Components/__tests__/__snapshots__/NoTokenEmptyState.test.js.snap +20 -13
  61. data/webpack/InsightsCloudSync/__snapshots__/InsightsCloudSync.test.js.snap +2 -2
  62. metadata +26 -4
  63. data/app/subscribers/foreman_rh_cloud/insights_subscriber.rb +0 -9
data/config/routes.rb CHANGED
@@ -40,4 +40,23 @@ Rails.application.routes.draw do
40
40
  match '/*path', :constraints => lambda { |req| !req.path.include?('view/api') }, to: 'machine_telemetries#forward_request', via: [:get, :post, :delete,:put, :patch]
41
41
  end
42
42
  end
43
+
44
+ # API routes
45
+
46
+ namespace :api, :defaults => {:format => 'json'} do
47
+ scope '(:apiv)', :module => :v2, :defaults => {:apiv => 'v2'}, :apiv => /v1|v2/, :constraints => ApiConstraints.new(:version => 2, :default => true) do
48
+ resources :organizations, :only => [:show] do
49
+ namespace 'rh_cloud' do
50
+ get 'report', to: 'inventory#download_file'
51
+ post 'report', to: 'inventory#generate_report'
52
+
53
+ post 'inventory_sync', to: 'inventory#sync_inventory_status'
54
+ end
55
+ end
56
+
57
+ namespace 'rh_cloud' do
58
+ post 'enable_connector', to: 'inventory#enable_cloud_connector'
59
+ end
60
+ end
61
+ end
43
62
  end
@@ -0,0 +1,6 @@
1
+ class RemoveOldInsightsStatuses < ActiveRecord::Migration[5.2]
2
+ def up
3
+ InsightsClientReportStatus.where(status: 2).update_all(status: InsightsClientReportStatus::NO_REPORT)
4
+ InsightsClientReportStatus.where(status: 3).update_all(status: InsightsClientReportStatus::REPORTING)
5
+ end
6
+ end
@@ -70,8 +70,16 @@ module ForemanInventoryUpload
70
70
  folder
71
71
  end
72
72
 
73
+ def self.inventory_base_url
74
+ ForemanRhCloud.base_url + "/api/inventory/v1/hosts"
75
+ end
76
+
73
77
  def self.inventory_export_url
74
78
  tags = URI.encode("satellite/satellite_instance_id=#{Foreman.instance_id}")
75
- ForemanRhCloud.base_url + "/api/inventory/v1/hosts?tags=#{tags}"
79
+ inventory_base_url + "?tags=#{tags}"
80
+ end
81
+
82
+ def self.inventory_self_url
83
+ inventory_base_url + "?hostname_or_id=#{ForemanRhCloud.foreman_host.fqdn}"
76
84
  end
77
85
  end
@@ -27,6 +27,7 @@ module ForemanInventoryUpload
27
27
  'insights_client::obfuscate_ip_enabled',
28
28
  'insights_client::hostname',
29
29
  'insights_client::ips',
30
+ 'insights_id',
30
31
  ]).pluck(:name, :id)
31
32
  ]
32
33
  end
@@ -49,6 +49,7 @@ module ForemanInventoryUpload
49
49
  @stream.simple_field('satellite_id', uuid_value!(host.subscription_facet&.uuid))
50
50
  @stream.simple_field('bios_uuid', bios_uuid(host))
51
51
  @stream.simple_field('vm_uuid', uuid_value(fact_value(host, 'virt::uuid')))
52
+ @stream.simple_field('insights_id', uuid_value(fact_value(host, 'insights_id')))
52
53
  report_ip_addresses(host, host_ips_cache)
53
54
  report_mac_addresses(host)
54
55
  @stream.object_field('system_profile') do
@@ -19,7 +19,9 @@ module ForemanInventoryUpload
19
19
  def generate_parameters
20
20
  return [] unless Setting[:include_parameter_tags]
21
21
 
22
- (@host.host_inherited_params_objects || []).map { |item| [item.name, item.value] }
22
+ (@host.host_inherited_params_objects || [])
23
+ .map { |item| [item.name, item.value] }
24
+ .select { |_name, value| value.present? || value.is_a?(FalseClass) }
23
25
  end
24
26
 
25
27
  private
@@ -6,6 +6,18 @@ module ForemanRhCloud
6
6
  class Engine < ::Rails::Engine
7
7
  engine_name 'foreman_rh_cloud'
8
8
 
9
+ def self.register_scheduled_task(task_class, cronline)
10
+ return if ForemanTasks::RecurringLogic.joins(:tasks)
11
+ .merge(ForemanTasks::Task.where(label: task_class.name))
12
+ .exists?
13
+
14
+ User.as_anonymous_admin do
15
+ recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline(cronline)
16
+ recurring_logic.save!
17
+ recurring_logic.start(task_class)
18
+ end
19
+ end
20
+
9
21
  initializer 'foreman_rh_cloud.load_default_settings', :before => :load_config_initializers do
10
22
  require_dependency File.expand_path('../../app/models/setting/rh_cloud.rb', __dir__)
11
23
  end
@@ -81,7 +93,9 @@ module ForemanRhCloud
81
93
  register_custom_status InventorySync::InventoryStatus
82
94
  register_custom_status InsightsClientReportStatus
83
95
 
84
- subscribe 'host_created.event.foreman', ForemanRhCloud::InsightsSubscriber
96
+ describe_host do
97
+ overview_buttons_provider :insights_host_overview_buttons
98
+ end
85
99
 
86
100
  extend_page 'hosts/show' do |context|
87
101
  context.add_pagelet :main_tabs,
@@ -134,15 +148,8 @@ module ForemanRhCloud
134
148
  # skip object creation when admin user is not present, for example in test DB
135
149
  if User.unscoped.find_by_login(User::ANONYMOUS_ADMIN).present?
136
150
  ::ForemanTasks.dynflow.config.on_init(false) do |world|
137
- unless ForemanTasks::RecurringLogic.joins(:tasks).merge(
138
- ForemanTasks::Task.where(label: 'InventorySync::Async::InventoryScheduledSync')
139
- ).exists?
140
- User.as_anonymous_admin do
141
- recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline("0 0 * * *")
142
- recurring_logic.save!
143
- recurring_logic.start(InventorySync::Async::InventoryScheduledSync)
144
- end
145
- end
151
+ ForemanRhCloud::Engine.register_scheduled_task(InventorySync::Async::InventoryScheduledSync, '0 0 * * *')
152
+ ForemanRhCloud::Engine.register_scheduled_task(InsightsCloud::Async::InsightsClientStatusAging, '0 0 * * *')
146
153
  end
147
154
  end
148
155
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '3.0.22'.freeze
2
+ VERSION = '3.0.25'.freeze
3
3
  end
@@ -0,0 +1,23 @@
1
+ module InsightsCloud
2
+ module Async
3
+ class InsightsClientStatusAging < ::Actions::EntryAction
4
+ include ::Actions::RecurringAction
5
+
6
+ def run
7
+ host_ids = InsightsClientReportStatus.stale.reporting.pluck(:host_id)
8
+
9
+ # update all stale records
10
+ InsightsClientReportStatus.where(host_id: host_ids).update_all(status: InsightsClientReportStatus::NO_REPORT)
11
+
12
+ # refresh global status
13
+ Host.where(id: host_ids).preload(:host_statuses).find_in_batches do |hosts|
14
+ hosts.each { |host| host.refresh_global_status! }
15
+ end
16
+ end
17
+
18
+ def logger
19
+ action_logger
20
+ end
21
+ end
22
+ end
23
+ end
@@ -6,6 +6,11 @@ module InsightsCloud
6
6
  include ::ForemanRhCloud::CloudAuth
7
7
 
8
8
  def plan
9
+ unless cloud_auth_available?
10
+ logger.debug('Cloud authentication is not available, skipping insights sync')
11
+ return
12
+ end
13
+
9
14
  sequence do
10
15
  # This can be turned off when we enable automatic status syncs
11
16
  # This step will query cloud inventory to retrieve inventory uuids for each host
@@ -7,6 +7,15 @@ module InsightsCloud
7
7
 
8
8
  RULE_ID_REGEX = /[^:]*:(?<id>.*)/
9
9
 
10
+ def plan
11
+ unless cloud_auth_available?
12
+ logger.debug('Cloud authentication is not available, skipping resolutions sync')
13
+ return
14
+ end
15
+
16
+ plan_self
17
+ end
18
+
10
19
  def run
11
20
  InsightsResolution.transaction do
12
21
  InsightsResolution.delete_all
@@ -6,6 +6,11 @@ module InsightsCloud
6
6
  include ::ForemanRhCloud::CloudAuth
7
7
 
8
8
  def plan
9
+ unless cloud_auth_available?
10
+ logger.debug('Cloud authentication is not available, skipping rules sync')
11
+ return
12
+ end
13
+
9
14
  plan_self
10
15
  plan_resolutions
11
16
  end
@@ -1,6 +1,8 @@
1
1
  module InventorySync
2
2
  module Async
3
3
  class HostResult
4
+ attr_reader :uuid_by_fqdn
5
+
4
6
  def initialize(result)
5
7
  @total = result['total']
6
8
  @count = result['count']
@@ -8,6 +10,7 @@ module InventorySync
8
10
  @per_page = result['per_page']
9
11
  @sub_ids = result["results"].map { |host| host['subscription_manager_id'] }
10
12
  @uuid_by_sub_id = Hash[result["results"].map { |host| [host['subscription_manager_id'], host['id']] }]
13
+ @uuid_by_fqdn = Hash[result["results"].map { |host| [host['fqdn'].downcase, host['id']] }]
11
14
  end
12
15
 
13
16
  def status_hashes
@@ -19,6 +22,7 @@ module InventorySync
19
22
  host_id: host_id,
20
23
  status: InventorySync::InventoryStatus::SYNC,
21
24
  reported_at: DateTime.current,
25
+ type: InventorySync::InventoryStatus.name,
22
26
  }
23
27
  end
24
28
  end.compact
@@ -5,6 +5,11 @@ module InventorySync
5
5
  set_callback :step, :around, :update_statuses_batch
6
6
 
7
7
  def plan(organization)
8
+ unless cloud_auth_available?
9
+ logger.debug('Cloud authentication is not available, skipping inventory hosts sync')
10
+ return
11
+ end
12
+
8
13
  plan_self(organization_id: organization.id)
9
14
  end
10
15
 
@@ -4,6 +4,17 @@ module InventorySync
4
4
  set_callback :iteration, :around, :setup_facet_transaction
5
5
  set_callback :step, :around, :create_facets
6
6
 
7
+ def plan
8
+ unless cloud_auth_available?
9
+ logger.debug('Cloud authentication is not available, skipping inventory hosts sync')
10
+ return
11
+ end
12
+
13
+ # by default the tasks will be executed concurrently
14
+ plan_self
15
+ plan_self_host_sync
16
+ end
17
+
7
18
  def setup_facet_transaction
8
19
  InsightsFacet.transaction do
9
20
  yield
@@ -20,14 +31,22 @@ module InventorySync
20
31
  private
21
32
 
22
33
  def add_missing_insights_facets(uuids_hash)
23
- existing_facets = InsightsFacet.where(host_id: uuids_hash.keys).pluck(:host_id)
24
- missing_facets = uuids_hash.except(*existing_facets).map do |host_id, uuid|
34
+ existing_facets = InsightsFacet.where(host_id: uuids_hash.keys).pluck(:host_id, :uuid)
35
+ missing_facets = uuids_hash.except(*existing_facets.map(&:first)).map do |host_id, uuid|
25
36
  {
26
37
  host_id: host_id,
27
38
  uuid: uuid,
28
39
  }
29
40
  end
30
41
  InsightsFacet.create(missing_facets)
42
+
43
+ existing_facets.select { |host_id, uuid| uuid.empty? }.each do |host_id, _uuid|
44
+ InsightsFacet.where(host_id: host_id).update_all(uuid: uuids_hash[host_id])
45
+ end
46
+ end
47
+
48
+ def plan_self_host_sync
49
+ plan_action InventorySync::Async::InventorySelfHostSync
31
50
  end
32
51
  end
33
52
  end
@@ -20,6 +20,10 @@ module InventorySync
20
20
  def plan_org_sync(org)
21
21
  plan_action InventoryFullSync, org
22
22
  end
23
+
24
+ def logger
25
+ action_logger
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -0,0 +1,39 @@
1
+ module InventorySync
2
+ module Async
3
+ class InventorySelfHostSync < QueryInventoryJob
4
+ set_callback :step, :around, :create_facets
5
+
6
+ def plan
7
+ unless cloud_auth_available?
8
+ logger.debug('Cloud authentication is not available, skipping self host sync')
9
+ return
10
+ end
11
+
12
+ plan_self
13
+ end
14
+
15
+ def create_facets
16
+ # get the results from the event
17
+ results = yield
18
+
19
+ add_missing_insights_facet(results.uuid_by_fqdn) unless results.uuid_by_fqdn.empty?
20
+ results
21
+ end
22
+
23
+ private
24
+
25
+ def add_missing_insights_facet(uuids_hash)
26
+ facet = InsightsFacet.find_or_create_by(host_id: ForemanRhCloud.foreman_host.id) do |facet|
27
+ facet.uuid = uuids_hash.values.first
28
+ end
29
+
30
+ # fix empty uuid in case the facet already exists
31
+ facet.update(uuid: uuids_hash.values.first) unless facet.uuid
32
+ end
33
+
34
+ def request_url
35
+ ForemanInventoryUpload.inventory_self_url
36
+ end
37
+ end
38
+ end
39
+ end
@@ -31,7 +31,7 @@ module InventorySync
31
31
  def query_inventory(page = 1)
32
32
  hosts_inventory_response = execute_cloud_request(
33
33
  method: :get,
34
- url: ForemanInventoryUpload.inventory_export_url,
34
+ url: request_url,
35
35
  headers: {
36
36
  params: {
37
37
  per_page: 100,
@@ -46,6 +46,10 @@ module InventorySync
46
46
  def logger
47
47
  action_logger
48
48
  end
49
+
50
+ def request_url
51
+ ForemanInventoryUpload.inventory_export_url
52
+ end
49
53
  end
50
54
  end
51
55
  end
@@ -4,4 +4,19 @@ namespace :rh_cloud_insights do
4
4
  ForemanTasks.sync_task(InsightsCloud::Async::InsightsFullSync)
5
5
  puts "Synchronized Insights hosts hits data"
6
6
  end
7
+
8
+ desc "Remove insights client report statuses by searching on host criteria"
9
+ task clean_statuses: [:environment] do
10
+ hosts_search = ENV['SEARCH']
11
+
12
+ if hosts_search.empty?
13
+ puts 'Must specify SEARCH= criteria for hosts search'
14
+ next
15
+ end
16
+
17
+ cleaner = ForemanRhCloud::InsightsStatusCleaner.new
18
+ deleted_count = cleaner.clean(hosts_search)
19
+
20
+ puts "Deleted #{deleted_count} insights statuses"
21
+ end
7
22
  end
@@ -29,8 +29,9 @@ namespace :rh_cloud_inventory do
29
29
  puts "Using #{base_folder} for the output"
30
30
  end
31
31
 
32
- unless portal_user || organizations.empty?
32
+ if portal_user.empty? && organizations.empty?
33
33
  puts "Must specify either portal_user or organization_id"
34
+ return
34
35
  end
35
36
 
36
37
  User.as_anonymous_admin do
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "3.0.22",
3
+ "version": "3.0.25",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -45,4 +45,4 @@
45
45
  "jed": "~1.1.1",
46
46
  "react-intl": "~2.8.0"
47
47
  }
48
- }
48
+ }
@@ -11,6 +11,39 @@ module InsightsCloud::Api
11
11
  host = FactoryBot.create(:host, :with_subscription, :organization => org)
12
12
  User.current = ::Katello::CpConsumerUser.new(:uuid => host.subscription_facet.uuid, :login => host.subscription_facet.uuid)
13
13
  InsightsCloud::Api::MachineTelemetriesController.any_instance.stubs(:upstream_owner).returns({ 'uuid' => 'abcdefg' })
14
+
15
+ @cert1 = "-----BEGIN CERTIFICATE-----\r\n" +
16
+ "MIIFdDCCA1ygAwIBAgIJAM5Uqykb3EAtMA0GCSqGSIb3DQEBCwUAME8xCzAJBgNV\r\n" +
17
+ "BAYTAklMMREwDwYDVQQIDAhUZWwgQXZpdjEUMBIGA1UECgwLVGhlIEZvcmVtYW4x\r\n" +
18
+ "FzAVBgNVBAMMDnRoZWZvcmVtYW4ub3JnMB4XDTE4MDMyNDEyMzYyOFoXDTI4MDMy\r\n" +
19
+ "MTEyMzYyOFowTzELMAkGA1UEBhMCSUwxETAPBgNVBAgMCFRlbCBBdml2MRQwEgYD\r\n" +
20
+ "VQQKDAtUaGUgRm9yZW1hbjEXMBUGA1UEAwwOdGhlZm9yZW1hbi5vcmcwggIiMA0G\r\n" +
21
+ "CSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDF04/s4h+BgHPG1HDZ/sDlYq925pkc\r\n" +
22
+ "RTVAfnE2EXDAmZ6W4Q9ueDY65MHe3ZWO5Dg72kNSP2sK9kRI7Dk5CAFOgyw1rH8t\r\n" +
23
+ "Hd1+0xp/lv6e4SvSYghxIL68vFe0ftKkm1usqejBM5ZTgKr7JCI+XSIN36F65Kde\r\n" +
24
+ "c+vxwBnayuhP04r9/aaE/709SXML4eRVYW8I3qFy9FPtUOm+bY8U2PIv5fHayqbG\r\n" +
25
+ "cL/4t3+MCtMhHJsLzdBXya+1P5t+HcKjUNlmwoUF961YAktVuEFloGd0RMRlqF3/\r\n" +
26
+ "itU3QNlXgA5QBIciE5VPr/PiqgMC3zgd5avjF4OribZ+N9AATLiQMW78il5wSfcc\r\n" +
27
+ "kQjU9ChOLrzku455vQ8KE4bc0qvpCWGfUah6MvL9JB+TQkRl/8kxl0b9ZinIvJDH\r\n" +
28
+ "ynVMb4cB/TDEjrjOfzn9mWLH0ZJqjmc2bER/G12WQxOaYLxdVwRStD3Yh6PtiFWu\r\n" +
29
+ "sXOk19UOTVkeuvGFVtvzLfEwQ1lDEo7+VBQz8FG/HBu2Hpq3IwCFrHuicikwjQJk\r\n" +
30
+ "nfturgD0rBOKEc1qWNZRCvovYOLL6ihvv5Orujsx5ZCHOAtnVNxkvIlFt2RS45LF\r\n" +
31
+ "MtPJyhAc6SjitllfUEirxprsbmeSZqrIfzcGaEhgOSnyik1WMv6bYiqPfBg8Fzjh\r\n" +
32
+ "vOCbtiDNPmvgOwIDAQABo1MwUTAdBgNVHQ4EFgQUtkAgQopsTtG9zSG3MgW2IxHD\r\n" +
33
+ "MDwwHwYDVR0jBBgwFoAUtkAgQopsTtG9zSG3MgW2IxHDMDwwDwYDVR0TAQH/BAUw\r\n" +
34
+ "AwEB/zANBgkqhkiG9w0BAQsFAAOCAgEAJq7iN+ZroRBweNhvUobxs75bLIV6tNn1\r\n" +
35
+ "MdNHDRA+hezwf+gxHZhFyaAHfTpst2/9leK5Qe5Zd6gZLr3E5/8ppQuRod72H39B\r\n" +
36
+ "vxMlG5zxDss0WMo3vZeKZbTY6QhXi/lY2IZ6OGV4feSvCsYxn27GTjjrRUSLFeHH\r\n" +
37
+ "JVemCwCDMavaE3+OIY4v2P4FcG+MjUvfOB9ahI24TWL7YgrsNVmJjCILq+EeUj0t\r\n" +
38
+ "Gde1SXVyLkqt7PoxHRJAE0BCEMJSnjxaVB329acJgeehBUxjj4CCPqtDxtbz9HEH\r\n" +
39
+ "mOKfNdaKpFor+DUeEKUWVGnr9U9xOaC+Ws+oX7MIEUCDM7p2ob4JwcjnFs1jZgHh\r\n" +
40
+ "Hwig+i7doTlc701PvKWO96fuNHK3B3/jTb1fVvSZ49O/RvY1VWODdUdxWmXGHNh3\r\n" +
41
+ "LoR8tSPEb46lC2DXGaIQumqQt8PnBG+vL1qkQa1SGTV7dJ8TTbxbv0S+sS+igkk9\r\n" +
42
+ "zsIEK8Ea3Ep935cXximz0faAAKHSA+It+xHLAyDtqy2KaAEBgGsBuuWlUfK6TaP3\r\n" +
43
+ "Gwdjct3y4yYUO45lUsUfHqX8vk/4ttW5zYeDiW+HArJz+9VUXNbEdury4kGuHgBj\r\n" +
44
+ "xHD4Bsul65+hHZ9QywKU26F1A6TLkYpQ2rk/Dx9LGICM4m4IlHjWJPFsQdtkyOor\r\n" +
45
+ "osxMtcaZZ1E=\r\n" +
46
+ "-----END CERTIFICATE-----"
14
47
  end
15
48
 
16
49
  test "should respond with response from cloud" do
@@ -30,6 +63,14 @@ module InsightsCloud::Api
30
63
  ::ForemanRhCloud::CloudRequestForwarder.any_instance.expects(:execute_cloud_request).with do |opts|
31
64
  opts[:headers][:content_type] == 'application/json'
32
65
  end.returns(res)
66
+ InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:candlepin_id_cert)
67
+ .returns(
68
+ {
69
+ cert: @cert1,
70
+ key: OpenSSL::PKey::RSA.new(1024).to_pem,
71
+ }
72
+ )
73
+ InsightsCloud::Api::MachineTelemetriesController.any_instance.expects(:cp_owner_id).returns('123')
33
74
 
34
75
  post :forward_request, as: :json, params: { "path" => "static/v1/test", "machine_telemetry" => {"foo" => "bar"} }
35
76
  assert_equal @body, @response.body