Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
"advisor",
"ansible",
"camelcase",
"cdn",
"checkbox",
"csrf",
"cve",
"cves",
"dropdown",
"donut",
"hostnames",
"href",
"ips",
"ipv4",
"dropdown",
"jed",
"katello",
"knowledgebase",
Expand All @@ -31,15 +34,15 @@
"nowrap",
"pid",
"redhat",
"redux",
"remediate",
"remediations",
"repo",
"rhc",
"scalprum",
"theforeman",
"tooltip",
"unmount",
"redux",
"dropdown"
"unmount"
],
"minLength": 3
}
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
"peerDependencies": {
"@theforeman/vendor": ">= 15.0.1"
Comment thread
ShimShtein marked this conversation as resolved.
},
"dependencies": {
"@scalprum/react-core": "^0.9.3",
"@scalprum/core": "^0.8.1"
},
"devDependencies": {
"@babel/core": "^7.7.0",
"@theforeman/builder": ">= 15.0.1",
Expand Down
40 changes: 30 additions & 10 deletions webpack/CVEsHostDetailsTab/CVEsHostDetailsTab.js
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 }) => (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tab content is missing a bounding box. Its contents are rendered very close to the edges.

image

<ScalprumProvider {...providerOptions}>
Comment thread
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;
29 changes: 18 additions & 11 deletions webpack/CVEsHostDetailsTab/__tests__/CVEsHostDetailsTab.test.js
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();
});
});
4 changes: 2 additions & 2 deletions webpack/CVEsHostDetailsTab/index.js
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;
7 changes: 4 additions & 3 deletions webpack/ForemanRhCloudFills.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand All @@ -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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tab is not showing for me. How do I debug it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Are there any errors in web console?
  2. Take a look at the /hosts/:id API call, there is a flag that is passed there under the vulnerability: enabled path.If it is passed as false, it means you need to set the advisor_local setting

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no such key vulnerability on the API response. Probably I've registered the system w/o Insights enabled. How to enable it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremylenz ^ 🙏

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the vulnerability node is only sent with index and not show:

api_view :list => 'api/v2/hosts/insights/insights', :single => 'api/v2/hosts/insights/single'
set_dependent_action :destroy

Need to add it to app/views/api/v2/hosts/insights/base.rabl.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to have vulnerabilityDisabled look at the :use_local_advisor_engine node instead, which is already in the base rabl.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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'),
},
},
];
Expand Down
9 changes: 6 additions & 3 deletions webpack/ForemanRhCloudPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import React from 'react';
import componentRegistry from 'foremanReact/components/componentRegistry';
import { registerRoutes as foremanRegisterRoutes } from 'foremanReact/routes/RoutingService';
import ForemanInventoryUpload from './ForemanInventoryUpload';
import InsightsVulnerability from './InsightsVulnerability/InsightsVulnerability';
import InsightsVulnerabilityListPage from './InsightsVulnerability/InsightsVulnerabilityListPage';
import InsightsCloudSync from './InsightsCloudSync';
import InsightsHostDetailsTab from './InsightsHostDetailsTab';

const pages = [
{ name: 'ForemanInventoryUpload', type: ForemanInventoryUpload },
{ name: 'InsightsCloudSync', type: InsightsCloudSync },
{ name: 'InsightsHostDetailsTab', type: InsightsHostDetailsTab },
{ name: 'InsightsVulnerability', type: InsightsVulnerability },
{
name: 'InsightsVulnerabilityListPage',
type: InsightsVulnerabilityListPage,
},
];

export const registerPages = () => {
Expand All @@ -31,7 +34,7 @@ export const routes = [
{
path: '/foreman_rh_cloud/insights_vulnerability',
exact: true,
render: props => <InsightsVulnerability {...props} />,
render: props => <InsightsVulnerabilityListPage {...props} />,
},
];

Expand Down
13 changes: 0 additions & 13 deletions webpack/InsightsVulnerability/InsightsVulnerability.js

This file was deleted.

18 changes: 0 additions & 18 deletions webpack/InsightsVulnerability/InsightsVulnerability.test.js

This file was deleted.

21 changes: 21 additions & 0 deletions webpack/InsightsVulnerability/InsightsVulnerabilityListPage.js
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();
});
});
63 changes: 63 additions & 0 deletions webpack/common/ScalprumModule/ScalprumContext.js
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,
};