Skip to content
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

Added the deprecated_by field to CPEs (bp #2751) #2753

Merged
merged 8 commits into from
Feb 24, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- The CVSS v2 BaseScore calculator calculates the score on the client side now. [#2536](https://github.com/greenbone/gsa/pull/2536)

### Fixed
- Added the deprecatedBy field to CPEs [#2751](https://github.com/greenbone/gsa/pull/2751)
- Fixed the severity for different advisories [#2611](https://github.com/greenbone/gsa/pull/2611)

### Removed
Expand Down
14 changes: 14 additions & 0 deletions gsa/src/gmp/models/__tests__/cpe.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,18 @@ describe('CPE model tests', () => {
expect(cpe.update_time).toBeUndefined();
expect(isDate(cpe.updateTime)).toBe(true);
});

test('should parse deprecatedBy', () => {
const cpe = Cpe.fromElement({
raw_data: {'cpe-item': {_deprecated_by: 'foo:/bar'}},
});

expect(cpe.deprecatedBy).toEqual('foo:/bar');
});

test('should not parse deprecatedBy', () => {
const cpe = Cpe.fromElement({raw_data: {'cpe-item': {}}});

expect(cpe.deprecatedBy).toBeUndefined();
});
});
10 changes: 10 additions & 0 deletions gsa/src/gmp/models/cpe.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,21 @@ class Cpe extends Info {
delete ret.status;
}

if (isDefined(ret.nvd_id)) {
ret.nvdId = ret.nvd_id;
}

if (isDefined(ret.update_time)) {
ret.updateTime = parseDate(ret.update_time);
delete ret.update_time;
}

if (isDefined(ret.raw_data) && isDefined(ret.raw_data['cpe-item'])) {
const cpeItem = ret.raw_data['cpe-item'];
if (isDefined(cpeItem._deprecated_by)) {
ret.deprecatedBy = cpeItem._deprecated_by;
}
}
return ret;
}
}
Expand Down
1 change: 1 addition & 0 deletions gsa/src/web/graphql/__mocks__/cpes.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const cpeEntity = deepFreeze({
severity: 1.8,
},
],
deprecatedBy: 'cpe:/a:foo:bar',
score: 98,
status: 'FINAL',
});
Expand Down
2 changes: 2 additions & 0 deletions gsa/src/web/graphql/cpes.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const GET_CPE = gql`
id
severity
}
deprecatedBy
score
status
}
Expand Down Expand Up @@ -94,6 +95,7 @@ export const GET_CPES = gql`
id
severity
}
deprecatedBy
score
status
}
Expand Down
1 change: 1 addition & 0 deletions gsa/src/web/pages/cpes/__tests__/detailspage.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ describe('CPE Detailspage tests', () => {

// test page content
expect(baseElement).toHaveTextContent('StatusFINAL');
expect(baseElement).toHaveTextContent('Deprecated Bycpe:/a:foo:bar');

// severity bar(s)
const progressBars = getAllByTestId('progressbar-box');
Expand Down
14 changes: 11 additions & 3 deletions gsa/src/web/pages/cpes/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import SeverityBar from 'web/components/bar/severitybar';

import DateTime from 'web/components/date/datetime';

import Layout from 'web/components/layout/layout';
import DetailsLink from 'web/components/link/detailslink';

import Layout from 'web/components/layout/layout.js';

import InfoTable from 'web/components/table/infotable';
import TableBody from 'web/components/table/body';
Expand All @@ -36,8 +38,9 @@ import {Col} from 'web/entity/page';

import PropTypes from 'web/utils/proptypes';

const CpeDetails = ({entity}) => {
const CpeDetails = ({entity, links = true}) => {
const {title, nvdId, deprecatedBy, updateTime, status, severity} = entity;

return (
<Layout flex="column" grow="1">
{!isDefined(title) && (
Expand Down Expand Up @@ -70,7 +73,11 @@ const CpeDetails = ({entity}) => {
{isDefined(deprecatedBy) && (
<TableRow>
<TableData>{_('Deprecated By')}</TableData>
<TableData>{deprecatedBy}</TableData>
<TableData>
<DetailsLink id={deprecatedBy} type="cpe" textOnly={!links}>
{deprecatedBy}
</DetailsLink>
</TableData>
</TableRow>
)}
{isDefined(updateTime) && (
Expand Down Expand Up @@ -103,6 +110,7 @@ const CpeDetails = ({entity}) => {

CpeDetails.propTypes = {
entity: PropTypes.model.isRequired,
links: PropTypes.bool,
};

export default CpeDetails;
Expand Down