Skip to content

Commit

Permalink
Merge pull request #2359 from sarahd93/flickering_reports_20.08
Browse files Browse the repository at this point in the history
Fix flickering reports
  • Loading branch information
bjoernricks authored Aug 5, 2020
2 parents cd2c503 + 8b15814 commit 81e354e
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Deleting a single entity now removes its ID from store [#1839](https://github.com/greenbone/gsa/pull/1839)

### Fixed
- Fixed flickering reports [#2359](https://github.com/greenbone/gsa/pull/2359)
- Fixed "Hosts scanned" in report details disappearing during page refresh [#2357](https://github.com/greenbone/gsa/pull/2357)
- Fixed schedule_periods not forwarded if there is no schedule [#2331](https://github.com/greenbone/gsa/pull/2331)
- Fixed broken radio buttons in alert dialog [#2326](https://github.com/greenbone/gsa/pull/2326)
Expand Down
243 changes: 243 additions & 0 deletions gsa/src/gmp/models/report/__tests__/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
parseOperatingSystems,
parseTlsCertificates,
parseCves,
parse_errors,
parseClosedCves,
} from '../parser';

describe('report parser tests', () => {
Expand Down Expand Up @@ -438,6 +440,22 @@ describe('report parser tests', () => {
test('should parse tls certificates', () => {
const filterString = 'foo=bar rows=5';
const report = {
results: {
result: [
{
host: {
__text: '1.1.1.1',
},
severity: '5.5',
},
{
host: {
__text: '2.2.2.2',
},
severity: '9.5',
},
],
},
host: [
{
ip: '1.1.1.1',
Expand Down Expand Up @@ -693,6 +711,231 @@ describe('report parser tests', () => {
expect(cve3.hosts.count).toEqual(1);
expect(cve3.occurrences).toEqual(1);
});

test('should parse empty errors', () => {
const filterString = 'foo=bar rows=5';
const report = {};
const errors = parse_errors(report, filterString);

expect(errors.entities.length).toEqual(0);
expect(errors.counts).toBeUndefined();
expect(errors.filter).toEqual('foo=bar rows=5');
});

test('should parse errors', () => {
const filterString = 'foo=bar rows=5';
const report = {
results: {
result: [
{
host: {
__text: '1.1.1.1',
},
severity: '5.5',
},
{
host: {
__text: '2.2.2.2',
},
severity: '9.5',
},
],
},
host: [
{
ip: '1.1.1.1',
detail: [
{
name: 'hostname',
value: 'foo.bar',
},
],
},

{
ip: '2.2.2.2',
detail: [
{
name: 'hostname',
value: 'lorem.ipsum',
},
],
},
],
errors: {
count: '2',
error: [
{
host: {
__text: '1.1.1.1',
asset: {_asset_id: '123'},
},
port: '123/tcp',
description: 'This is an error.',
nvt: {
_oid: '314',
name: 'NVT1',
},
},
{
host: {
__text: '2.2.2.2',
},
port: '456/tcp',
description: 'This is another error.',
nvt: {
_oid: '159',
name: 'NVT2',
},
},
],
},
};

const counts = {
first: 1,
all: 2,
filtered: 2,
length: 2,
rows: 2,
last: 2,
};

const errors = parse_errors(report, filterString);

expect(errors.entities.length).toEqual(2);
expect(errors.counts).toEqual(counts);
expect(errors.filter).toEqual('foo=bar rows=5');

const [error1, error2] = errors.entities;

expect(error1.id).toEqual('1.1.1.1314');
expect(error1.description).toEqual('This is an error.');
expect(error1.host.ip).toEqual('1.1.1.1');
expect(error1.host.name).toEqual('foo.bar');
expect(error1.host.id).toEqual('123');
expect(error1.nvt.id).toEqual('314');
expect(error1.nvt.name).toEqual('NVT1');
expect(error1.port).toEqual('123/tcp');

expect(error2.id).toEqual('2.2.2.2159');
expect(error2.description).toEqual('This is another error.');
expect(error2.host.ip).toEqual('2.2.2.2');
expect(error2.host.name).toEqual('lorem.ipsum');
expect(error2.host.id).toEqual(undefined);
expect(error2.nvt.id).toEqual('159');
expect(error2.nvt.name).toEqual('NVT2');
expect(error2.port).toEqual('456/tcp');
});

test('should parse empty closed CVEs', () => {
const filterString = 'foo=bar rows=5';
const report = {};
const closedCves = parse_errors(report, filterString);

expect(closedCves.entities.length).toEqual(0);
expect(closedCves.counts).toBeUndefined();
expect(closedCves.filter).toEqual('foo=bar rows=5');
});

test('should parse closed CVEs', () => {
const filterString = 'foo=bar rows=5';
const report = {
results: {
result: [
{
host: {
__text: '1.1.1.1',
},
severity: '5.5',
},
{
host: {
__text: '2.2.2.2',
},
severity: '9.5',
},
],
},
host: [
{
ip: '1.1.1.1',
detail: [
{
name: 'hostname',
value: 'foo.bar',
},
{
name: 'Closed CVE',
value: 'CVE-2000-1234',
source: {
type: 'openvas',
name: '201',
description: 'This is a description',
},
extra: '10.0',
},
],
},

{
ip: '2.2.2.2',
detail: [
{
name: 'hostname',
value: 'lorem.ipsum',
},
{
name: 'Closed CVE',
value: 'CVE-2000-5678',
source: {
type: 'openvas',
name: '202',
description: 'This is another description',
},
extra: '5.0',
},
],
},
],
closed_cves: {
count: '2',
},
};

const counts = {
first: 1,
all: 2,
filtered: 2,
length: 2,
rows: 2,
last: 2,
};

const closedCves = parseClosedCves(report, filterString);

expect(closedCves.entities.length).toEqual(2);
expect(closedCves.counts).toEqual(counts);
expect(closedCves.filter).toEqual('foo=bar rows=5');

const [closedCve1, closedCve2] = closedCves.entities;

expect(closedCve1.id).toEqual('CVE-2000-1234-1.1.1.1-201');
expect(closedCve1.cveId).toEqual('CVE-2000-1234');
expect(closedCve1.host.ip).toEqual('1.1.1.1');
expect(closedCve1.host.name).toEqual('foo.bar');
expect(closedCve1.host.id).toEqual(undefined);
expect(closedCve1.source.name).toEqual('201');
expect(closedCve1.severity).toEqual(10);

expect(closedCve2.id).toEqual('CVE-2000-5678-2.2.2.2-202');
expect(closedCve2.cveId).toEqual('CVE-2000-5678');
expect(closedCve2.host.ip).toEqual('2.2.2.2');
expect(closedCve2.host.name).toEqual('lorem.ipsum');
expect(closedCve2.host.id).toEqual(undefined);
expect(closedCve2.source.name).toEqual('202');
expect(closedCve2.severity).toEqual(5);
});
});

// vim: set ts=2 sw=2 tw=80:
26 changes: 17 additions & 9 deletions gsa/src/gmp/models/report/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ import ReportTLSCertificate from './tlscertificate';
import Result from '../result';
import {getRefs, hasRefType} from '../nvt';

// reports with details=1 always have a results element
// (that can be empty) whereas reports with details=0
// never have a results element
const isReportWithDetails = results => isDefined(results);

const emptyCollectionList = filter => {
return {
filter,
Expand All @@ -62,9 +67,9 @@ const getTlsCertificate = (certs, fingerprint) => {
};

export const parseTlsCertificates = (report, filter) => {
const {host: hosts, ssl_certs} = report;
const {host: hosts, ssl_certs, results} = report;

if (!isDefined(ssl_certs)) {
if (!isDefined(ssl_certs) || !isReportWithDetails(results)) {
return emptyCollectionList(filter);
}

Expand Down Expand Up @@ -218,7 +223,7 @@ export const parseApps = (report, filter) => {
const apps_temp = {};
const cpe_host_details = {};

if (!isDefined(apps)) {
if (!isDefined(apps) || !isReportWithDetails(results)) {
return emptyCollectionList(filter);
}

Expand Down Expand Up @@ -337,7 +342,7 @@ export const parseHostSeverities = (results = {}) => {
export const parseOperatingSystems = (report, filter) => {
const {host: hosts, results, os: os_count} = report;

if (!isDefined(os_count)) {
if (!isDefined(os_count) || !isReportWithDetails(results)) {
return emptyCollectionList(filter);
}

Expand Down Expand Up @@ -401,7 +406,10 @@ export const parseOperatingSystems = (report, filter) => {
export const parseHosts = (report, filter) => {
const {host: hosts, results, hosts: hosts_count} = report;

if (!isDefined(hosts)) {
if (
(!isDefined(hosts) && !isDefined(hosts_count)) ||
!isReportWithDetails(results)
) {
return emptyCollectionList(filter);
}

Expand Down Expand Up @@ -468,9 +476,9 @@ export const parseResults = (report, filter) => {
};

export const parse_errors = (report, filter) => {
const {host: hosts, errors} = report;
const {host: hosts, errors, results} = report;

if (!isDefined(errors)) {
if (!isDefined(errors) || !isReportWithDetails(results)) {
return emptyCollectionList(filter);
}

Expand Down Expand Up @@ -536,9 +544,9 @@ export const parse_errors = (report, filter) => {
};

export const parseClosedCves = (report, filter) => {
const {host: hosts, closed_cves} = report;
const {host: hosts, closed_cves, results} = report;

if (!isDefined(closed_cves)) {
if (!isDefined(closed_cves) || !isReportWithDetails(results)) {
return emptyCollectionList(filter);
}

Expand Down

0 comments on commit 81e354e

Please sign in to comment.