Skip to content

Commit

Permalink
Add Severity Date to NVTs Details
Browse files Browse the repository at this point in the history
  • Loading branch information
y0urself committed Mar 18, 2021
1 parent 02b8c62 commit 139e9a4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions gsa/src/gmp/models/__tests__/nvt.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import Nvt, {getRefs, hasRefType, getFilteredRefIds} from 'gmp/models/nvt';
import Info from 'gmp/models/info';
import {testModelFromElement, testModelMethods} from 'gmp/models/testing';
import date from 'gmp/models/date';

describe('nvt Model tests', () => {
testModelFromElement(Nvt, 'nvt');
Expand Down Expand Up @@ -160,6 +161,7 @@ describe('nvt Model tests', () => {
severity: {
score: 94,
origin: 'Vendor',
date: '2021-03-10T06:40:13Z',
},
},
cvss_base: '6.6',
Expand All @@ -169,6 +171,7 @@ describe('nvt Model tests', () => {
severity: {
score: 74,
origin: 'Greenbone',
date: '2020-03-10T06:40:13Z',
},
},
cvss_base: '',
Expand All @@ -184,13 +187,16 @@ describe('nvt Model tests', () => {

expect(nvt1.severity).toEqual(9.4);
expect(nvt1.severityOrigin).toEqual('Vendor');
expect(nvt1.severityDate).toEqual(date('2021-03-10T06:40:13Z'));
expect(nvt1.cvss_base).toBeUndefined();
expect(nvt2.severity).toEqual(7.4);
expect(nvt2.cvss_base).toBeUndefined();
expect(nvt2.severityOrigin).toEqual('Greenbone');
expect(nvt2.severityDate).toEqual(date('2020-03-10T06:40:13Z'));
expect(nvt3.cvss_base).toBeUndefined();
expect(nvt3.severity).toEqual(1.0);
expect(nvt3.severityOrigin).toEqual('');
expect(nvt3.severityDate).toBeUndefined();
});

test('should parse preferences', () => {
Expand Down
9 changes: 6 additions & 3 deletions gsa/src/gmp/models/nvt.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {isDefined, isArray, isString} from 'gmp/utils/identity';
import {isEmpty, split} from 'gmp/utils/string';
import {map} from 'gmp/utils/array';

import {parseFloat, parseSeverity, parseText} from 'gmp/parser';
import {parseDate, parseFloat, parseSeverity, parseText} from 'gmp/parser';

import Info from './info';

Expand Down Expand Up @@ -149,8 +149,11 @@ class Nvt extends Info {

if (isDefined(ret.severities)) {
const {severity} = ret.severities;
ret.severity = parseSeverity(severity.score / 10);
ret.severityOrigin = parseText(severity.origin);
ret.severity = parseSeverity(severity?.score / 10);
ret.severityOrigin = parseText(severity?.origin);
ret.severityDate = isDefined(severity?.date)
? parseDate(severity.date)
: undefined;
} else {
ret.severity = parseSeverity(ret.cvss_base);
}
Expand Down
15 changes: 14 additions & 1 deletion gsa/src/web/pages/nvts/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import React from 'react';

import _ from 'gmp/locale';
import {dateTimeWithTimeZone} from 'gmp/locale/date';

import {isDefined} from 'gmp/utils/identity';

Expand Down Expand Up @@ -45,7 +46,15 @@ import Solution from './solution';
import Pre from './preformatted';

const NvtDetails = ({entity, links = true}) => {
const {tags = {}, severity, qod, family, solution, severityOrigin} = entity;
const {
tags = {},
severity,
qod,
family,
solution,
severityOrigin,
severityDate,
} = entity;
return (
<Layout flex="column" grow="1">
{isDefined(tags.summary) && (
Expand Down Expand Up @@ -84,6 +93,10 @@ const NvtDetails = ({entity, links = true}) => {
{na(getTranslatableSeverityOrigin(severityOrigin))}
</TableData>
</TableRow>
<TableRow>
<TableData>{_('CVSS Date')}</TableData>
<TableData>{dateTimeWithTimeZone(severityDate)}</TableData>
</TableRow>
</TableBody>
</InfoTable>
</DetailsBlock>
Expand Down

0 comments on commit 139e9a4

Please sign in to comment.