foreman_rh_cloud 14.7.1 → 15.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/insights_cloud/ui_requests_controller.rb +11 -0
  3. data/app/services/foreman_rh_cloud/tags_auth.rb +28 -13
  4. data/config/routes.rb +10 -0
  5. data/lib/foreman_rh_cloud/plugin.rb +14 -0
  6. data/lib/foreman_rh_cloud/version.rb +1 -1
  7. data/package.json +1 -1
  8. data/test/controllers/insights_cloud/ui_requests_controller_test.rb +147 -2
  9. data/test/unit/services/foreman_rh_cloud/tags_auth_test.rb +26 -0
  10. data/webpack/ComplianceHostDetailsTab/ComplianceHostDetailsTab.js +36 -0
  11. data/webpack/ComplianceHostDetailsTab/ComplianceHostDetailsTab.scss +3 -0
  12. data/webpack/ComplianceHostDetailsTab/__tests__/ComplianceHostDetailsTab.test.js +159 -0
  13. data/webpack/ComplianceHostDetailsTab/index.js +3 -0
  14. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/InventoryAutoUpload.js +3 -1
  15. data/webpack/ForemanInventoryUpload/SubscriptionsPageExtension/InventoryAutoUpload/__tests__/InventoryAutoUpload.test.js +23 -0
  16. data/webpack/ForemanRhCloudFills.js +11 -0
  17. data/webpack/ForemanRhCloudPages.js +7 -0
  18. data/webpack/InsightsCompliance/ComplianceIframe.js +34 -0
  19. data/webpack/InsightsCompliance/ComplianceIframe.scss +12 -0
  20. data/webpack/InsightsCompliance/InsightsCompliancePage.js +11 -0
  21. data/webpack/InsightsCompliance/InsightsCompliancePage.test.js +35 -0
  22. data/webpack/InsightsCompliance/complianceIframeConstants.js +7 -0
  23. data/webpack/InsightsCompliance/complianceIframeHelpers.js +23 -0
  24. data/webpack/InsightsCompliance/complianceIframeHelpers.test.js +50 -0
  25. data/webpack/common/Hooks/PermissionsHooks.js +10 -0
  26. data/webpack/common/IopIframe/IopAppIframe.js +74 -0
  27. data/webpack/common/IopIframe/IopHostDetailsIframe.js +66 -0
  28. data/webpack/common/IopIframe/IopHostDetailsIframe.scss +6 -0
  29. data/webpack/common/IopIframe/IopHostDetailsIframeTab.js +81 -0
  30. data/webpack/common/IopIframe/__tests__/IopAppIframe.test.js +92 -0
  31. data/webpack/common/IopIframe/__tests__/IopHostDetailsIframeTab.test.js +93 -0
  32. data/webpack/common/IopIframe/__tests__/iopIframeHelpers.test.js +63 -0
  33. data/webpack/common/IopIframe/__tests__/postIopChromeToIframe.test.js +60 -0
  34. data/webpack/common/IopIframe/__tests__/useIopIframeHeight.test.js +37 -0
  35. data/webpack/common/IopIframe/iopIframeConstants.js +5 -0
  36. data/webpack/common/IopIframe/iopIframeHelpers.js +49 -0
  37. data/webpack/common/IopIframe/postIopChromeToIframe.js +35 -0
  38. data/webpack/common/IopIframe/useIopIframeChrome.js +54 -0
  39. data/webpack/common/IopIframe/useIopIframeHeight.js +35 -0
  40. data/webpack/common/IopIframe/useIopIframeNavigate.js +40 -0
  41. metadata +27 -2
  42. data/lib/tasks/hybrid_cloud.rake +0 -132
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df573a3f57c51c056bd94b2f485ace3c6d74a461556fda782d8df21658b28467
4
- data.tar.gz: a043bffea8a13e761f1c4b411059be37fea5cf95556bb8410bd4b38e75265c6d
3
+ metadata.gz: '058ab42a9ca04ad514bb6b70da9fef474f1d632db028c878ca74c683d9e779b7'
4
+ data.tar.gz: 680c4b6007f94101da65041c00ed0ad789534c113a3f900a520c0a24244cc7a8
5
5
  SHA512:
6
- metadata.gz: d21ee9703cf4464e2ad9396c3049e42b19a38abe233a1f5fb82acea8a0ae08d254b8c99a036390bc3528c405fd82b7a00d226234d48f5df95a484458e0109dc7
7
- data.tar.gz: 52915f7c6bdd4c91c1117b7d90b27434f824129e916ba52329aedaa3ba74053346c769ca6013a967501fdf6b42c101ba40c08e8e52534dd3cb96b477acee4dd0
6
+ metadata.gz: f53bc0a6402a59d7e92c0a1ffffaa961fd09eea5bec29204151b68ed50500860f5d39526bd0ebd8874ffb00ae5f8beaafba93d99b307c207ea3d62a6f70295ef
7
+ data.tar.gz: 61e0cba5b33a973607e915ff50b7da93db3ed042a5bbc71dc7df7bed7cad922a1be4281ec2aa7bc4f87ed54e32afb266bdfeed95bd01b917cb13e9a0f8fa7135
@@ -1,5 +1,16 @@
1
1
  module InsightsCloud
2
2
  class UIRequestsController < ::ApplicationController
3
+ # This controller proxies both browser (session + CSRF token) and
4
+ # token-authenticated API requests (e.g. Robottelo). ApplicationController's
5
+ # unconditional protect_from_forgery rejects the latter with a 422, so swap
6
+ # in the same session-only CSRF check Foreman's API base controller uses.
7
+ skip_forgery_protection
8
+ include Foreman::Controller::ApiCsrfProtection
9
+
10
+ protect_from_forgery with: :exception,
11
+ if: :protect_api_from_forgery?,
12
+ prepend: true
13
+
3
14
  layout false
4
15
 
5
16
  before_action :ensure_org, :find_location, :only => [:forward_request]
@@ -5,6 +5,7 @@ module ForemanRhCloud
5
5
  TAG_NAMESPACE = 'sat_iam'.freeze
6
6
  TAG_SHORT_NAME = 'scope'.freeze
7
7
  TAG_NAME = "#{TAG_NAMESPACE}/#{TAG_SHORT_NAME}".freeze
8
+ SYNC_CACHE_TTL = 10.seconds
8
9
 
9
10
  def self.auth_tag_for(user, org, loc)
10
11
  new(user, org, loc, nil).auth_tag
@@ -20,20 +21,28 @@ module ForemanRhCloud
20
21
  end
21
22
 
22
23
  def update_tag
23
- loc_name = location_name_for_tag
24
- logger.debug("Updating tags for user: #{@user}, org: #{@org.name}, loc: #{loc_name}")
24
+ cached = Rails.cache.read(sync_identity)
25
+ return cached if cached
25
26
 
26
- payload = tags_query_payload
27
- params = {
28
- organization: @org,
29
- method: :post,
30
- url: "#{InsightsCloud.gateway_url}/tags",
31
- headers: {
32
- content_type: :json,
33
- },
34
- payload: payload.to_json,
35
- }
36
- execute_cloud_request(params) unless payload[:host_id_list].empty?
27
+ Foreman::AdvisoryLockManager.with_session_lock(sync_identity) do
28
+ Rails.cache.fetch(sync_identity, expires_in: SYNC_CACHE_TTL) do
29
+ loc_name = location_name_for_tag
30
+ logger.debug("Updating tags for user: #{@user}, org: #{@org.name}, loc: #{loc_name}")
31
+
32
+ payload = tags_query_payload
33
+ params = {
34
+ organization: @org,
35
+ method: :post,
36
+ url: "#{InsightsCloud.gateway_url}/tags",
37
+ headers: {
38
+ content_type: :json,
39
+ },
40
+ payload: payload.to_json,
41
+ }
42
+ execute_cloud_request(params) unless payload[:host_id_list].empty?
43
+ true
44
+ end
45
+ end
37
46
  end
38
47
 
39
48
  def allowed_hosts
@@ -63,5 +72,11 @@ module ForemanRhCloud
63
72
  def location_name_for_tag
64
73
  @loc ? @loc.name : '*'
65
74
  end
75
+
76
+ # Single identity string reused as BOTH the advisory-lock name and the
77
+ # Rails.cache key, so the lock and the cached entry always correspond 1:1.
78
+ def sync_identity
79
+ "rh_cloud_tags_auth_sync_#{tag_value}"
80
+ end
66
81
  end
67
82
  end
data/config/routes.rb CHANGED
@@ -36,6 +36,16 @@ Rails.application.routes.draw do
36
36
  get 'insights_cloud', to: '/react#index' # Uses foreman's react controller
37
37
  get 'insights_vulnerability', to: '/react#index'
38
38
  get 'insights_vulnerability/:cve_id', to: '/react#index'
39
+ scope 'insights_compliance' do
40
+ get 'reports', to: '/react#index'
41
+ get 'reports/:report_id', to: '/react#index'
42
+ get 'reports/:report_id/delete', to: '/react#index'
43
+ get 'scappolicies', to: '/react#index'
44
+ get 'scappolicies/new', to: '/react#index'
45
+ get 'scappolicies/:policy_id', to: '/react#index'
46
+ get 'scappolicies/:policy_id/edit', to: '/react#index'
47
+ get 'scappolicies/:policy_id/delete', to: '/react#index'
48
+ end
39
49
  end
40
50
 
41
51
  scope :module => :'insights_cloud/api', :path => :redhat_access do
@@ -145,6 +145,20 @@ module ForemanRhCloud
145
145
  url_hash: { controller: :react, action: :index },
146
146
  parent: :insights_menu,
147
147
  if: -> { ForemanRhCloud.with_iop_smart_proxy? }
148
+ menu :top_menu,
149
+ :insights_compliance_reports,
150
+ caption: N_('Compliance Reports'),
151
+ url: '/foreman_rh_cloud/insights_compliance/reports',
152
+ url_hash: { controller: :react, action: :index },
153
+ parent: :insights_menu,
154
+ if: -> { ForemanRhCloud.with_iop_smart_proxy? }
155
+ menu :top_menu,
156
+ :insights_compliance_scappolicies,
157
+ caption: N_('SCAP Policies'),
158
+ url: '/foreman_rh_cloud/insights_compliance/scappolicies',
159
+ url_hash: { controller: :react, action: :index },
160
+ parent: :insights_menu,
161
+ if: -> { ForemanRhCloud.with_iop_smart_proxy? }
148
162
  end
149
163
 
150
164
  # In IoP case we want the page to be in the admin menu
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '14.7.1'.freeze
2
+ VERSION = '15.0.1'.freeze
3
3
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foreman_rh_cloud",
3
- "version": "14.7.1",
3
+ "version": "15.0.1",
4
4
  "description": "Inventory Upload =============",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -3,8 +3,6 @@ require 'rest-client'
3
3
 
4
4
  module InsightsCloud
5
5
  class UIRequestsControllerTest < ActionController::TestCase
6
- include KatelloCVEHelper
7
-
8
6
  setup do
9
7
  FactoryBot.create(:common_parameter, name: InsightsCloud.enable_client_param, key_type: 'boolean', value: true)
10
8
  end
@@ -222,6 +220,153 @@ module InsightsCloud
222
220
  end
223
221
  end
224
222
 
223
+ context "#forward_request CSRF protection" do
224
+ setup do
225
+ ActionController::Base.allow_forgery_protection = true
226
+ as_admin do
227
+ @org = FactoryBot.create(:organization)
228
+ @loc = FactoryBot.create(:location)
229
+ end
230
+ User.current = nil
231
+ @forwarder = ForemanRhCloud::InsightsApiForwarder.any_instance
232
+ @forwarder.stubs(:forward_request).returns(successful_cloud_response)
233
+ @controller.stubs(:authorized).returns(true)
234
+ end
235
+
236
+ teardown do
237
+ ActionController::Base.allow_forgery_protection = false
238
+ end
239
+
240
+ test 'rejects a browser session without a CSRF token' do
241
+ @forwarder.expects(:forward_request).never
242
+
243
+ assert_raises(ActionController::InvalidAuthenticityToken) do
244
+ request_with(:post, session: set_session)
245
+ end
246
+ end
247
+
248
+ test 'rejects a browser session with an invalid CSRF token' do
249
+ @forwarder.expects(:forward_request).never
250
+
251
+ assert_raises(ActionController::InvalidAuthenticityToken) do
252
+ request_with(:post, session: set_session, headers: { 'X-CSRF-Token' => 'invalid' })
253
+ end
254
+ end
255
+
256
+ test 'forwards a browser session with a valid CSRF token' do
257
+ token = @controller.send(:form_authenticity_token)
258
+
259
+ request_with(:post, params: { authenticity_token: token }, session: set_session,
260
+ headers: { 'X-CSRF-Token' => token })
261
+
262
+ assert_response :success
263
+ end
264
+
265
+ test 'forwards valid basic credentials without a session or CSRF token' do
266
+ set_basic_auth(users(:admin), 'secret')
267
+
268
+ request_with(:post)
269
+
270
+ assert_response :success
271
+ end
272
+
273
+ test 'forwards valid personal access token without a session or CSRF token' do
274
+ user = users(:admin)
275
+ token_value = as_admin do
276
+ token = FactoryBot.create(:personal_access_token, user: user)
277
+ value = token.generate_token
278
+ token.save!
279
+ value
280
+ end
281
+ set_basic_auth(user, token_value)
282
+
283
+ request_with(:post)
284
+
285
+ assert_response :success
286
+ assert_equal user.id, session[:user]
287
+ assert session[:api_authenticated_session]
288
+ end
289
+
290
+ test 'rejects invalid credentials without a session or CSRF token' do
291
+ @forwarder.expects(:forward_request).never
292
+ set_basic_auth('admin', 'invalid')
293
+
294
+ request_with(:post)
295
+
296
+ assert_response :unauthorized
297
+ end
298
+
299
+ test 'rejects a browser session with authorization and without a CSRF token' do
300
+ @forwarder.expects(:forward_request).never
301
+ set_basic_auth(users(:admin), 'secret')
302
+
303
+ assert_raises(ActionController::InvalidAuthenticityToken) do
304
+ request_with(:post, session: set_session)
305
+ end
306
+ end
307
+
308
+ test 'rejects a browser session with authorization and an invalid CSRF token' do
309
+ @forwarder.expects(:forward_request).never
310
+ set_basic_auth(users(:admin), 'secret')
311
+
312
+ assert_raises(ActionController::InvalidAuthenticityToken) do
313
+ request_with(:post, session: set_session, headers: { 'X-CSRF-Token' => 'invalid' })
314
+ end
315
+ end
316
+
317
+ test 'rejects DELETE from a browser session without a CSRF token' do
318
+ @forwarder.expects(:forward_request).never
319
+
320
+ assert_raises(ActionController::InvalidAuthenticityToken) do
321
+ request_with(:delete, session: set_session)
322
+ end
323
+ end
324
+
325
+ test 'forwards DELETE with valid basic credentials without a session or CSRF token' do
326
+ set_basic_auth(users(:admin), 'secret')
327
+
328
+ request_with(:delete)
329
+
330
+ assert_response :success
331
+ end
332
+
333
+ test 'forwards DELETE with a valid personal access token without a session or CSRF token' do
334
+ user = users(:admin)
335
+ token_value = as_admin do
336
+ token = FactoryBot.create(:personal_access_token, user: user)
337
+ value = token.generate_token
338
+ token.save!
339
+ value
340
+ end
341
+ set_basic_auth(user, token_value)
342
+
343
+ request_with(:delete)
344
+
345
+ assert_response :success
346
+ assert_equal user.id, session[:user]
347
+ assert session[:api_authenticated_session]
348
+ end
349
+
350
+ private
351
+
352
+ def request_with(method, params: {}, session: nil, headers: {})
353
+ headers.each { |name, value| @request.headers[name] = value }
354
+ public_send(method, :forward_request,
355
+ params: forward_request_params.merge(params), session: session)
356
+ end
357
+
358
+ def forward_request_params
359
+ { controller: 'vulnerabilities', path: 'api/vulnerability/v1/cves', organization_id: @org.id }
360
+ end
361
+
362
+ def successful_cloud_response
363
+ request = RestClient::Request.new(method: 'POST', url: 'http://test.theforeman.org')
364
+ response = Net::HTTPResponse.new(1.0, 200, 'OK')
365
+ response['content-type'] = 'application/json'
366
+ RestClient::Response.create('{}', response, request)
367
+ end
368
+ end
369
+
225
370
  def set_session
226
371
  set_session_user.merge(
227
372
  organization_id: @org.id,
@@ -3,6 +3,7 @@ require 'json'
3
3
 
4
4
  class TagsAuthTest < ActiveSupport::TestCase
5
5
  setup do
6
+ Rails.cache.clear
6
7
  @user = FactoryBot.build(:user)
7
8
  @logger = Logger.new(IO::NULL)
8
9
  @org = FactoryBot.build(:organization)
@@ -41,6 +42,31 @@ class TagsAuthTest < ActiveSupport::TestCase
41
42
  @auth.update_tag
42
43
  end
43
44
 
45
+ test 'Does not repeat cloud request for the same user/org/location within the sync TTL' do
46
+ @auth.stubs(:allowed_hosts).returns(['test_uuid1'])
47
+ @auth.expects(:execute_cloud_request).once
48
+
49
+ @auth.update_tag
50
+ @auth.update_tag
51
+ end
52
+
53
+ test 'Serializes sync through an advisory lock on a cold cache miss' do
54
+ @auth.stubs(:allowed_hosts).returns(['test_uuid1'])
55
+ @auth.stubs(:execute_cloud_request)
56
+ Foreman::AdvisoryLockManager.expects(:with_session_lock).yields
57
+
58
+ @auth.update_tag
59
+ end
60
+
61
+ test 'Skips the advisory lock entirely on a warm cache hit' do
62
+ @auth.stubs(:allowed_hosts).returns(['test_uuid1'])
63
+ @auth.stubs(:execute_cloud_request)
64
+ @auth.update_tag
65
+
66
+ Foreman::AdvisoryLockManager.expects(:with_session_lock).never
67
+ @auth.update_tag
68
+ end
69
+
44
70
  test 'Generates tags with wildcard location when location is nil' do
45
71
  auth_with_nil_loc = ::ForemanRhCloud::TagsAuth.new(@user, @org, nil, @logger)
46
72
  uuid1 = 'test_uuid1'
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { translate as __ } from 'foremanReact/common/I18n';
4
+ import IopHostDetailsIframeTab from '../common/IopIframe/IopHostDetailsIframeTab';
5
+ import { getComplianceIframeSrc } from '../InsightsCompliance/complianceIframeHelpers';
6
+ import { IOP_COMPLIANCE_READY } from '../InsightsCompliance/complianceIframeConstants';
7
+ import './ComplianceHostDetailsTab.scss';
8
+
9
+ const ComplianceHostDetailsTabWrapper = ({ response = {} }) => (
10
+ <IopHostDetailsIframeTab
11
+ response={response}
12
+ iframeSrc={getComplianceIframeSrc()}
13
+ buildAppRoute={inventoryId => `systems/${inventoryId}`}
14
+ title={__('Compliance')}
15
+ readyMessageType={IOP_COMPLIANCE_READY}
16
+ className="rh-cloud-insights-compliance-host-details-component compliance"
17
+ testId="compliance-host-details-iframe"
18
+ />
19
+ );
20
+
21
+ ComplianceHostDetailsTabWrapper.propTypes = {
22
+ response: PropTypes.shape({
23
+ id: PropTypes.number,
24
+ operatingsystem_name: PropTypes.string,
25
+ insights_attributes: PropTypes.object,
26
+ subscription_facet_attributes: PropTypes.shape({
27
+ uuid: PropTypes.string,
28
+ }),
29
+ }),
30
+ };
31
+
32
+ ComplianceHostDetailsTabWrapper.defaultProps = {
33
+ response: {},
34
+ };
35
+
36
+ export default ComplianceHostDetailsTabWrapper;
@@ -0,0 +1,3 @@
1
+ div.rh-cloud-insights-compliance-host-details-component {
2
+ padding: 0;
3
+ }
@@ -0,0 +1,159 @@
1
+ import React from 'react';
2
+ import { fireEvent, render } from '@testing-library/react';
3
+ import { MemoryRouter } from 'react-router-dom';
4
+ import ComplianceHostDetailsTabWrapper from '../ComplianceHostDetailsTab';
5
+ import { OVERVIEW_TAB_PATH } from '../../ForemanRhCloudHelpers';
6
+
7
+ const mockHistoryReplace = jest.fn();
8
+
9
+ jest.mock('react-router-dom', () => ({
10
+ ...jest.requireActual('react-router-dom'),
11
+ useHistory: () => ({
12
+ replace: mockHistoryReplace,
13
+ }),
14
+ }));
15
+
16
+ jest.mock('foremanReact/Root/Context/ForemanContext', () => ({
17
+ useForemanContext: () => ({
18
+ metadata: {
19
+ permissions: new Set(['view_hosts']),
20
+ },
21
+ }),
22
+ useForemanPermissions: () => new Set(['view_hosts']),
23
+ }));
24
+
25
+ jest.mock('foremanReact/common/I18n', () => ({
26
+ translate: str => str,
27
+ sprintf: str => str,
28
+ }));
29
+
30
+ jest.mock('../../InsightsCompliance/complianceIframeHelpers', () => ({
31
+ getComplianceIframeSrc: () =>
32
+ 'https://example.test/assets/apps/compliance/index.html',
33
+ }));
34
+
35
+ const mockPostChrome = jest.fn();
36
+ jest.mock('../../common/IopIframe/postIopChromeToIframe', () => ({
37
+ postIopChromeToIframe: (...args) => mockPostChrome(...args),
38
+ }));
39
+
40
+ const defaultResponse = {
41
+ id: 1,
42
+ operatingsystem_name: 'Red Hat Enterprise Linux 8',
43
+ insights_attributes: { uuid: 'insights-1' },
44
+ subscription_facet_attributes: { uuid: '1-2-3' },
45
+ };
46
+
47
+ describe('ComplianceHostDetailsTabWrapper', () => {
48
+ beforeEach(() => {
49
+ jest.clearAllMocks();
50
+ });
51
+
52
+ it('renders compliance iframe for a valid host without redirecting', () => {
53
+ const { getByTestId, container } = render(
54
+ <MemoryRouter>
55
+ <ComplianceHostDetailsTabWrapper response={defaultResponse} />
56
+ </MemoryRouter>
57
+ );
58
+
59
+ expect(
60
+ container.querySelector(
61
+ '.rh-cloud-insights-compliance-host-details-component'
62
+ )
63
+ ).toBeTruthy();
64
+
65
+ const iframe = getByTestId('compliance-host-details-iframe');
66
+ expect(iframe.getAttribute('src')).toBe(
67
+ 'https://example.test/assets/apps/compliance/index.html'
68
+ );
69
+ expect(mockHistoryReplace).not.toHaveBeenCalled();
70
+ });
71
+
72
+ it('posts systems/<uuid> appRoute for the host-tab iframe', () => {
73
+ const { getByTestId } = render(
74
+ <MemoryRouter>
75
+ <ComplianceHostDetailsTabWrapper response={defaultResponse} />
76
+ </MemoryRouter>
77
+ );
78
+
79
+ fireEvent.load(getByTestId('compliance-host-details-iframe'));
80
+
81
+ expect(mockPostChrome).toHaveBeenCalledWith(
82
+ expect.anything(),
83
+ expect.objectContaining({
84
+ appRoute: 'systems/1-2-3',
85
+ embedded: 'host-tab',
86
+ })
87
+ );
88
+ });
89
+
90
+ it('posts updated appRoute when inventoryId changes', () => {
91
+ const responseHostA = {
92
+ ...defaultResponse,
93
+ subscription_facet_attributes: { uuid: 'uuid-host-A' },
94
+ };
95
+
96
+ const { rerender, getByTestId } = render(
97
+ <MemoryRouter>
98
+ <ComplianceHostDetailsTabWrapper response={responseHostA} />
99
+ </MemoryRouter>
100
+ );
101
+
102
+ expect(getByTestId('compliance-host-details-iframe')).toBeTruthy();
103
+
104
+ const responseHostB = {
105
+ ...defaultResponse,
106
+ subscription_facet_attributes: { uuid: 'uuid-host-B' },
107
+ };
108
+
109
+ rerender(
110
+ <MemoryRouter>
111
+ <ComplianceHostDetailsTabWrapper response={responseHostB} />
112
+ </MemoryRouter>
113
+ );
114
+
115
+ fireEvent.load(getByTestId('compliance-host-details-iframe'));
116
+
117
+ expect(mockPostChrome).toHaveBeenCalledWith(
118
+ expect.anything(),
119
+ expect.objectContaining({
120
+ appRoute: 'systems/uuid-host-B',
121
+ embedded: 'host-tab',
122
+ })
123
+ );
124
+ });
125
+
126
+ it('redirects to Overview when tab should be hidden', () => {
127
+ const nonRhelResponse = {
128
+ id: 2,
129
+ operatingsystem_name: 'Ubuntu 20.04',
130
+ insights_attributes: { uuid: 'insights-1' },
131
+ subscription_facet_attributes: { uuid: '1-2-3' },
132
+ };
133
+
134
+ const { container } = render(
135
+ <MemoryRouter>
136
+ <ComplianceHostDetailsTabWrapper response={nonRhelResponse} />
137
+ </MemoryRouter>
138
+ );
139
+
140
+ expect(mockHistoryReplace).toHaveBeenCalledWith(OVERVIEW_TAB_PATH);
141
+ expect(
142
+ container.querySelector(
143
+ '.rh-cloud-insights-compliance-host-details-component'
144
+ )
145
+ ).toBeNull();
146
+ });
147
+
148
+ it('does not redirect when host data is not yet loaded', () => {
149
+ const emptyResponse = { subscription_facet_attributes: { uuid: '1-2-3' } };
150
+
151
+ render(
152
+ <MemoryRouter>
153
+ <ComplianceHostDetailsTabWrapper response={emptyResponse} />
154
+ </MemoryRouter>
155
+ );
156
+
157
+ expect(mockHistoryReplace).not.toHaveBeenCalled();
158
+ });
159
+ });
@@ -0,0 +1,3 @@
1
+ import ComplianceHostDetailsTabWrapper from './ComplianceHostDetailsTab';
2
+
3
+ export default ComplianceHostDetailsTabWrapper;
@@ -13,6 +13,7 @@ import {
13
13
  import { InfoAltIcon, CaretRightIcon } from '@patternfly/react-icons';
14
14
  import { translate as __ } from 'foremanReact/common/I18n';
15
15
  import { foremanUrl } from '../../../ForemanRhCloudHelpers';
16
+ import { useIopConfig } from '../../../common/Hooks/ConfigHooks';
16
17
  import SwitcherPF4 from '../../../common/Switcher/SwitcherPF4';
17
18
  import { settingsDict } from '../../Components/InventorySettings/AdvancedSetting/AdvancedSettingsConstants';
18
19
  import InventorySettings from '../../Components/InventorySettings/InventorySettings';
@@ -22,6 +23,7 @@ const InventoryAutoUploadSwitcher = ({
22
23
  setSetting,
23
24
  getSettings,
24
25
  }) => {
26
+ const isIop = useIopConfig();
25
27
  useEffect(() => {
26
28
  getSettings();
27
29
  }, [getSettings]);
@@ -80,7 +82,7 @@ const InventoryAutoUploadSwitcher = ({
80
82
  rel="noopener noreferrer"
81
83
  >
82
84
  <strong>
83
- {__('Configure')}
85
+ {isIop ? __('Administer') : __('Insights')}
84
86
  {' > '}
85
87
  {__('Inventory Upload')}
86
88
  </strong>
@@ -2,6 +2,11 @@ import React from 'react';
2
2
  import { render, screen } from '@testing-library/react';
3
3
  import InventoryAutoUpload from '../InventoryAutoUpload';
4
4
 
5
+ let mockIsIop = false;
6
+ jest.mock('../../../../common/Hooks/ConfigHooks', () => ({
7
+ useIopConfig: () => mockIsIop,
8
+ }));
9
+
5
10
  jest.mock(
6
11
  '../../../Components/InventorySettings/InventorySettings',
7
12
  () => () => <div data-testid="inventory-settings">InventorySettings</div>
@@ -15,6 +20,10 @@ describe('InventoryAutoUpload', () => {
15
20
  ...overrides,
16
21
  });
17
22
 
23
+ beforeEach(() => {
24
+ mockIsIop = false;
25
+ });
26
+
18
27
  it('renders the heading', () => {
19
28
  render(<InventoryAutoUpload {...buildProps()} />);
20
29
  expect(screen.getByText('Red Hat Cloud Inventory')).toBeTruthy();
@@ -39,4 +48,18 @@ describe('InventoryAutoUpload', () => {
39
48
  render(<InventoryAutoUpload {...props} />);
40
49
  expect(props.getSettings).toHaveBeenCalled();
41
50
  });
51
+
52
+ it('points to the Insights menu in regular mode', () => {
53
+ mockIsIop = false;
54
+ render(<InventoryAutoUpload {...buildProps()} />);
55
+ expect(screen.getByText(/Insights/)).toBeTruthy();
56
+ expect(screen.queryByText(/Administer/)).toBeNull();
57
+ });
58
+
59
+ it('points to the Administer menu in IoP mode', () => {
60
+ mockIsIop = true;
61
+ render(<InventoryAutoUpload {...buildProps()} />);
62
+ expect(screen.getByText(/Administer/)).toBeTruthy();
63
+ expect(screen.queryByText(/Insights/)).toBeNull();
64
+ });
42
65
  });
@@ -10,6 +10,7 @@ import {
10
10
  hasNoInsightsFacet,
11
11
  } from './ForemanRhCloudHelpers';
12
12
  import CVEsHostDetailsTabWrapper from './CVEsHostDetailsTab/CVEsHostDetailsTab';
13
+ import ComplianceHostDetailsTabWrapper from './ComplianceHostDetailsTab/ComplianceHostDetailsTab';
13
14
  import InsightsVulnerabilityActionsBar from './InsightsVulnerabilityActionsBar';
14
15
 
15
16
  const fills = [
@@ -51,6 +52,16 @@ const fills = [
51
52
  title: __('Vulnerabilities'),
52
53
  },
53
54
  },
55
+ {
56
+ slot: 'host-details-page-tabs',
57
+ name: 'Compliance',
58
+ component: props => <ComplianceHostDetailsTabWrapper {...props} />,
59
+ weight: 350,
60
+ metadata: {
61
+ hideTab: props => isNotRhelHost(props) || hasNoInsightsFacet(props),
62
+ title: __('Compliance'),
63
+ },
64
+ },
54
65
  ];
55
66
 
56
67
  export const registerFills = () => {
@@ -8,6 +8,7 @@ import IopRecommendationDetails from './IopRecommendationDetails/IopRecommendati
8
8
  import IopPathwayDetails from './IopPathwayDetails/IopPathwayDetails';
9
9
  import InsightsHostDetailsTab from './InsightsHostDetailsTab';
10
10
  import CveDetailsPage from './CveDetailsPage';
11
+ import InsightsCompliancePage from './InsightsCompliance/InsightsCompliancePage';
11
12
  import './common/styles.scss';
12
13
 
13
14
  const pages = [
@@ -20,6 +21,7 @@ const pages = [
20
21
  type: InsightsVulnerabilityListPage,
21
22
  },
22
23
  { name: 'CveDetailsPage', type: CveDetailsPage },
24
+ { name: 'InsightsCompliancePage', type: InsightsCompliancePage },
23
25
  ];
24
26
 
25
27
  export const registerPages = () => {
@@ -57,6 +59,11 @@ export const routes = [
57
59
  exact: true,
58
60
  render: props => <CveDetailsPage {...props} />,
59
61
  },
62
+ {
63
+ path: '/foreman_rh_cloud/insights_compliance',
64
+ exact: false,
65
+ render: props => <InsightsCompliancePage {...props} />,
66
+ },
60
67
  ];
61
68
 
62
69
  export const registerRoutes = () => {