-
Notifications
You must be signed in to change notification settings - Fork 60
New Vulnerabilities list tab and page #1031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0578ab5
daddd32
9d92d4d
d5db34c
44864b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,37 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import { translate as __ } from 'foremanReact/common/I18n'; | ||
| import { ScalprumComponent, ScalprumProvider } from '@scalprum/react-core'; | ||
| import { providerOptions } from '../common/ScalprumModule/ScalprumContext'; | ||
|
|
||
| const CVEsHostDetailsTab = ({ hostName }) => ( | ||
| <div> | ||
| <h1> | ||
| {__('CVEs tab for host:')} {hostName} | ||
| </h1> | ||
| </div> | ||
| ); | ||
| const CVEsHostDetailsTab = ({ systemId }) => { | ||
| const scope = 'vulnerability'; | ||
| const module = './SystemDetailTable'; | ||
| return ( | ||
| <div className="rh-cloud-insights-vulnerability-host-details-component"> | ||
| <ScalprumComponent scope={scope} module={module} systemId={systemId} /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| CVEsHostDetailsTab.propTypes = { | ||
| hostName: PropTypes.string.isRequired, | ||
| systemId: PropTypes.string.isRequired, | ||
| }; | ||
|
|
||
| const CVEsHostDetailsTabWrapper = ({ response }) => ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| <ScalprumProvider {...providerOptions}> | ||
|
jeremylenz marked this conversation as resolved.
|
||
| <CVEsHostDetailsTab | ||
| // eslint-disable-next-line camelcase | ||
| systemId={response?.subscription_facet_attributes?.uuid} | ||
| /> | ||
| </ScalprumProvider> | ||
| ); | ||
|
|
||
| CVEsHostDetailsTabWrapper.propTypes = { | ||
| response: PropTypes.shape({ | ||
| subscription_facet_attributes: PropTypes.shape({ | ||
| uuid: PropTypes.string.isRequired, | ||
| }), | ||
| }).isRequired, | ||
| }; | ||
|
|
||
| export default CVEsHostDetailsTab; | ||
| export default CVEsHostDetailsTabWrapper; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,25 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import CVEsHostDetailsTab from '../CVEsHostDetailsTab'; | ||
| import { render } from '@testing-library/react'; | ||
| import CVEsHostDetailsTabWrapper from '../CVEsHostDetailsTab'; | ||
|
|
||
| describe('CVEsHostDetailsTab', () => { | ||
| jest.mock('@scalprum/react-core', () => ({ | ||
| ScalprumComponent: jest.fn(props => ( | ||
| <div data-testid="mock-scalprum-component">{JSON.stringify(props)}</div> | ||
| )), | ||
| ScalprumProvider: jest.fn(({ children }) => <div>{children}</div>), | ||
| })); | ||
|
|
||
| describe('CVEsHostDetailsTabWrapper', () => { | ||
| it('renders without crashing', () => { | ||
| render(<CVEsHostDetailsTab hostName="test-host.example.com" />); | ||
| const { container } = render( | ||
| <CVEsHostDetailsTabWrapper | ||
| response={{ subscription_facet_attributes: { uuid: '1-2-3' } }} | ||
| /> | ||
| ); | ||
| expect( | ||
| screen.getByText('CVEs tab for host: test-host.example.com') | ||
| container.querySelector( | ||
| '.rh-cloud-insights-vulnerability-host-details-component' | ||
| ) | ||
| ).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('renders the host name', () => { | ||
| const hostName = 'test-host.example.com'; | ||
| render(<CVEsHostDetailsTab hostName={hostName} />); | ||
| expect(screen.getByText(`CVEs tab for host: ${hostName}`)).toBeTruthy(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| import CVEsHostDetailsTab from './CVEsHostDetailsTab'; | ||
| import CVEsHostDetailsTabWrapper from './CVEsHostDetailsTab'; | ||
|
|
||
| export default CVEsHostDetailsTab; | ||
| export default CVEsHostDetailsTabWrapper; |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,7 +5,7 @@ import InventoryAutoUploadSwitcher from './ForemanInventoryUpload/SubscriptionsP | |||||
| import NewHostDetailsTab from './InsightsHostDetailsTab/NewHostDetailsTab'; | ||||||
| import { InsightsTotalRiskChartWrapper } from './InsightsHostDetailsTab/InsightsTotalRiskChartWrapper'; | ||||||
| import { isNotRhelHost, vulnerabilityDisabled } from './ForemanRhCloudHelpers'; | ||||||
| import CVEsHostDetailsTab from './CVEsHostDetailsTab/CVEsHostDetailsTab'; | ||||||
| import CVEsHostDetailsTabWrapper from './CVEsHostDetailsTab/CVEsHostDetailsTab'; | ||||||
|
|
||||||
| const fills = [ | ||||||
| { | ||||||
|
|
@@ -32,11 +32,12 @@ const fills = [ | |||||
| }, | ||||||
| { | ||||||
| slot: 'host-details-page-tabs', | ||||||
| name: 'CVEs', | ||||||
| component: props => <CVEsHostDetailsTab {...props} />, | ||||||
| name: 'Vulnerabilities', | ||||||
| component: props => <CVEsHostDetailsTabWrapper {...props} />, | ||||||
| weight: 300, | ||||||
| metadata: { | ||||||
| hideTab: vulnerabilityDisabled, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tab is not showing for me. How do I debug it?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no such key
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jeremylenz ^ 🙏
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the foreman_rh_cloud/lib/foreman_rh_cloud/engine.rb Lines 131 to 132 in da91f30
Need to add it to app/views/api/v2/hosts/insights/base.rabl.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another option is to have
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From Shim: "We are adding it to API, specifically to a single rabl. The only thing that needs to exist, is the insights facet. If the facet is not there, we won't add the node. Now the facet should be created on each package upload. Maybe in Viliam's case the host was there before my package upload pr got in, so he doesn't have the insights facet on the host. The easiest way would be to sync hosts with a button. I think I have enabled this use case, and it will properly sync the ids"
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did a resycn with "Generate and upload report" but some hosts still don't show it. Interesting fact is that navigating from CVE counts form the hosts list table gets the tab shown, but it doesn't provide it a subscription/system id. |
||||||
| title: __('Vulnerabilities'), | ||||||
| }, | ||||||
| }, | ||||||
| ]; | ||||||
|
|
||||||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import React from 'react'; | ||
| import { ScalprumComponent, ScalprumProvider } from '@scalprum/react-core'; | ||
| import { providerOptions } from '../common/ScalprumModule/ScalprumContext'; | ||
|
|
||
| const InsightsVulnerabilityListPage = () => { | ||
| const scope = 'vulnerability'; | ||
| const module = './CveListPage'; | ||
| return ( | ||
| <div className="rh-cloud-insights-vulnerability-page"> | ||
| <ScalprumComponent scope={scope} module={module} /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| const InsightsVulnerabilityListPageWrap = () => ( | ||
| <ScalprumProvider {...providerOptions}> | ||
| <InsightsVulnerabilityListPage /> | ||
| </ScalprumProvider> | ||
| ); | ||
|
|
||
| export default InsightsVulnerabilityListPageWrap; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
| import InsightsVulnerabilityListPage from './InsightsVulnerabilityListPage'; | ||
|
|
||
| jest.mock('@scalprum/react-core', () => ({ | ||
| ScalprumComponent: jest.fn(props => ( | ||
| <div data-testid="mock-scalprum-component">{JSON.stringify(props)}</div> | ||
| )), | ||
| ScalprumProvider: jest.fn(({ children }) => <div>{children}</div>), | ||
| })); | ||
|
|
||
| describe('InsightsVulnerabilityListPage component', () => { | ||
| it('renders the container with correct class', () => { | ||
| const { container } = render(<InsightsVulnerabilityListPage />); | ||
| expect( | ||
| container.querySelector('.rh-cloud-insights-vulnerability-page') | ||
| ).toBeTruthy(); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| export const modulesConfig = { | ||
| vulnerability: { | ||
| name: 'vulnerability', | ||
| manifestLocation: `${window.location.origin}/assets/apps/vulnerability/fed-mods.json`, | ||
| cdnPath: `${window.location.origin}/assets/apps/vulnerability/`, | ||
| }, | ||
| }; | ||
|
|
||
| export const mockUser = { | ||
| entitlements: {}, | ||
| identity: { | ||
| account_number: 'string', | ||
| org_id: 'FOREMAN', | ||
| internal: { | ||
| org_id: 'string', | ||
| account_id: 'string', | ||
| }, | ||
| type: 'string', | ||
| user: { | ||
| username: 'string', | ||
| email: 'string', | ||
| first_name: 'string', | ||
| last_name: 'string', | ||
| is_active: 'boolean', | ||
| is_internal: 'boolean', | ||
| is_org_admin: 'boolean', | ||
| locale: 'string', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export const providerOptions = { | ||
| pluginSDKOptions: { | ||
| pluginLoaderOptions: { | ||
| transformPluginManifest: manifest => { | ||
| if ( | ||
| manifest.baseURL === 'auto' && | ||
| modulesConfig[manifest.name]?.cdnPath | ||
| ) { | ||
| const _cdnPath = modulesConfig[manifest.name]?.cdnPath; | ||
| return { | ||
| ...manifest, | ||
| baseURL: _cdnPath, | ||
| loadScripts: manifest.loadScripts.map( | ||
| script => `${_cdnPath}${script}` | ||
| ), | ||
| }; | ||
| } | ||
| return manifest; | ||
| }, | ||
| }, | ||
| }, | ||
| api: { | ||
| chrome: { | ||
| isBeta: () => false, | ||
| on: () => {}, | ||
| auth: { | ||
| getUser: () => Promise.resolve(mockUser), | ||
| }, | ||
| }, | ||
| }, | ||
| config: modulesConfig, | ||
| }; |

Uh oh!
There was an error while loading. Please reload this page.