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

Disable feed object editing using <predefined> and adjust feed status page filters #2398

Merged
merged 9 commits into from
Aug 19, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added

### Changed
- Use <predefined> to disable feed object editing and filter creation on feed status page [#2398](https://github.com/greenbone/gsa/pull/2398)

### Fixed

Expand Down
8 changes: 8 additions & 0 deletions gsa/src/gmp/models/__tests__/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ describe('Policy model tests', () => {

expect(policy.audits).toEqual([]);
});

test('should parse predefined as boolean correctly', () => {
const policy = Policy.fromElement({predefined: '0'});
const policy2 = Policy.fromElement({predefined: '1'});

expect(policy.predefined).toEqual(false);
expect(policy2.predefined).toEqual(true);
});
});

// vim: set ts=2 sw=2 tw=80:
8 changes: 8 additions & 0 deletions gsa/src/gmp/models/__tests__/portlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ describe('PortList model tests', () => {

expect(portList.targets).toEqual([]);
});

test('should parse predefined as boolean correctly', () => {
const portList = PortList.fromElement({predefined: '0'});
const portList2 = PortList.fromElement({predefined: '1'});

expect(portList.predefined).toEqual(false);
expect(portList2.predefined).toEqual(true);
});
});

// vim: set ts=2 sw=2 tw=80:
8 changes: 8 additions & 0 deletions gsa/src/gmp/models/__tests__/reportformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ describe('ReportFormat model tests', () => {
expect(reportFormat2.active).toEqual(YES_VALUE);
});

test('should parse predefined as boolean correctly', () => {
const reportFormat = ReportFormat.fromElement({predefined: '0'});
const reportFormat2 = ReportFormat.fromElement({predefined: '1'});

expect(reportFormat.predefined).toEqual(false);
expect(reportFormat2.predefined).toEqual(true);
});

test('should parse alerts', () => {
const elem = {
alerts: {
Expand Down
8 changes: 8 additions & 0 deletions gsa/src/gmp/models/__tests__/scanconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ describe('ScanConfig model tests', () => {

expect(scanConfig.tasks).toEqual([]);
});

test('should parse predefined as boolean correctly', () => {
const scanConfig = ScanConfig.fromElement({predefined: '0'});
const scanConfig2 = ScanConfig.fromElement({predefined: '1'});

expect(scanConfig.predefined).toEqual(false);
expect(scanConfig2.predefined).toEqual(true);
});
});

describe('ScanConfigs model function test', () => {
Expand Down
4 changes: 3 additions & 1 deletion gsa/src/gmp/models/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {isDefined} from '../utils/identity';
import {forEach, map} from '../utils/array';
import {isEmpty} from '../utils/string';

import {parseInt} from '../parser';
import {parseInt, parseBoolean} from '../parser';

import Model, {parseModelFromElement} from '../model';

Expand Down Expand Up @@ -130,6 +130,8 @@ class Policy extends Model {
ret.audits = [];
}

ret.predefined = parseBoolean(element.predefined);

return ret;
}
}
Expand Down
5 changes: 4 additions & 1 deletion gsa/src/gmp/models/portlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {map} from '../utils/array';

import Model, {parseModelFromElement} from '../model';

import {parseInt} from '../parser';
import {parseInt, parseBoolean} from '../parser';

class PortRange extends Model {
static entityType = 'portrange';
Expand Down Expand Up @@ -71,6 +71,9 @@ class PortList extends Model {
} else {
ret.targets = [];
}

ret.predefined = parseBoolean(element.predefined);

return ret;
}
}
Expand Down
3 changes: 2 additions & 1 deletion gsa/src/gmp/models/reportformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {isDefined, isObject} from '../utils/identity';
import {map} from '../utils/array';
import {isEmpty} from '../utils/string';

import {parseDate, parseYesNo, YES_VALUE} from '../parser';
import {parseDate, parseYesNo, YES_VALUE, parseBoolean} from '../parser';

import Model, {parseModelFromElement} from '../model';

Expand Down Expand Up @@ -84,6 +84,7 @@ class ReportFormat extends Model {
}

ret.active = parseYesNo(element.active);
ret.predefined = parseBoolean(element.predefined);

return ret;
}
Expand Down
4 changes: 3 additions & 1 deletion gsa/src/gmp/models/scanconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {isDefined} from '../utils/identity';
import {forEach, map} from '../utils/array';
import {isEmpty} from '../utils/string';

import {parseInt} from '../parser';
import {parseInt, parseBoolean} from '../parser';

import Model, {parseModelFromElement} from '../model';

Expand Down Expand Up @@ -167,6 +167,8 @@ class ScanConfig extends Model {
ret.tasks = [];
}

ret.predefined = parseBoolean(element.predefined);

return ret;
}
}
Expand Down
30 changes: 5 additions & 25 deletions gsa/src/web/pages/extras/__tests__/feedstatuspage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import React from 'react';

import {rendererWith, wait} from 'web/utils/testing';

import FeedStatus, {composeObjFilter} from '../feedstatuspage';
import FeedStatus from '../feedstatuspage';
import {Feed} from 'gmp/commands/feedstatus';

import Response from 'gmp/http/response';
Expand Down Expand Up @@ -118,21 +118,18 @@ describe('Feed status page tests', () => {
expect(links[4]).toHaveAttribute('href', '/ovaldefs');
expect(links[5]).toHaveAttribute('href', '/certbunds');
expect(links[6]).toHaveAttribute('href', '/dfncerts');
expect(links[7]).toHaveAttribute(
'href',
'/policies?filter=uuid%3Dc4b7c0cb-6502-4809-b034-8e635311b3e6%20',
);
expect(links[7]).toHaveAttribute('href', '/policies?filter=predefined%3D1');
expect(links[8]).toHaveAttribute(
'href',
'/portlists?filter=uuid%3D33d0cd82-57c6-11e1-8ed1-406186ea4fc5%20uuid%3D4a4717fe-57d2-11e1-9a26-406186ea4fc5%20uuid%3D730ef368-57e2-11e1-a90f-406186ea4fc5%20',
'/portlists?filter=predefined%3D1',
);
expect(links[9]).toHaveAttribute(
'href',
'/reportformats?filter=uuid%3D5057e5cc-b825-11e4-9d0e-28d24461215b%20uuid%3Dc1645568-627a-11e3-a660-406186ea4fc5%20uuid%3D77bd6c4a-1f62-11e1-abf0-406186ea4fc5%20uuid%3Dc402cc3e-b531-11e1-9163-406186ea4fc5%20uuid%3Da3810a62-1f62-11e1-9219-406186ea4fc5%20uuid%3Da994b278-1f62-11e1-96ac-406186ea4fc5%20',
'/reportformats?filter=predefined%3D1',
);
expect(links[10]).toHaveAttribute(
'href',
'/scanconfigs?filter=uuid%3Dd21f6c81-2b88-4ac1-b7b4-a2a9f2ad4663%20uuid%3D8715c877-47a0-438d-98a3-27c7a6ab2196%20uuid%3D085569ce-73ed-11df-83c3-002264764cea%20uuid%3Ddaba56c8-73ec-11df-a475-002264764cea%20uuid%3D2d3f051c-55ba-11e3-bf43-406186ea4fc5%20uuid%3Dbbca7412-a950-11e3-9109-406186ea4fc5%20',
'/scanconfigs?filter=predefined%3D1',
);

// Test headers
Expand Down Expand Up @@ -191,22 +188,5 @@ describe('Feed status page tests', () => {
});
});

describe('Test uuid filter composer', () => {
test('Should return empty string for empty array', () => {
const emptyFilter = composeObjFilter([]);
expect(emptyFilter).toEqual('');
});

test('Should not crash on undefined input', () => {
const noFilter = composeObjFilter();
expect(noFilter).toEqual('');
});

test('Should return correct filter string', () => {
const filterString = composeObjFilter(['foo', 'bar', 'baz']);
expect(filterString).toEqual('uuid=foo uuid=bar uuid=baz ');
});
});

// restore overwritten method
global.Date.now = _now;
56 changes: 4 additions & 52 deletions gsa/src/web/pages/extras/feedstatuspage.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,42 +100,6 @@ const renderFeedStatus = feed => {
return _('Current');
};

export const COMPLIANCE_POLICIES_FROM_FEED = [
'c4b7c0cb-6502-4809-b034-8e635311b3e6', // IT-Grundschutz
];

export const PORT_LISTS_FROM_FEED = [
'33d0cd82-57c6-11e1-8ed1-406186ea4fc5', // All IANA assigned TCP
'4a4717fe-57d2-11e1-9a26-406186ea4fc5', // All IANA assigned TCP and UDP
'730ef368-57e2-11e1-a90f-406186ea4fc5', // All TCP and Nmap top 100 UDP
];

export const REPORT_FORMATS_FROM_FEED = [
'5057e5cc-b825-11e4-9d0e-28d24461215b', // Anonymous XML
'c1645568-627a-11e3-a660-406186ea4fc5', // CSV Results
'77bd6c4a-1f62-11e1-abf0-406186ea4fc5', // ITG
'c402cc3e-b531-11e1-9163-406186ea4fc5', // PDF
'a3810a62-1f62-11e1-9219-406186ea4fc5', // TXT
'a994b278-1f62-11e1-96ac-406186ea4fc5', // XML
];

export const SCAN_CONFIGS_FROM_FEED = [
'd21f6c81-2b88-4ac1-b7b4-a2a9f2ad4663', // Base
'8715c877-47a0-438d-98a3-27c7a6ab2196', // Discovery
'085569ce-73ed-11df-83c3-002264764cea', // empty
'daba56c8-73ec-11df-a475-002264764cea', // Full and fast
'2d3f051c-55ba-11e3-bf43-406186ea4fc5', // Host Discovery
'bbca7412-a950-11e3-9109-406186ea4fc5', // System Discovery
];

export const composeObjFilter = (objectIds = []) => {
let filterString = '';

objectIds.forEach(id => (filterString += 'uuid=' + id + ' '));

return filterString;
};

const FeedStatus = ({feeds}) => {
return (
<React.Fragment>
Expand Down Expand Up @@ -207,37 +171,25 @@ const FeedStatus = ({feeds}) => {
)}
{feed.feed_type === GVMD_DATA_FEED && (
<IconDivider>
<Link
to="policies"
filter={composeObjFilter(COMPLIANCE_POLICIES_FROM_FEED)}
>
<Link to="policies" filter="predefined=1">
<IconDivider align={['start', 'center']}>
<PolicyIcon size="medium" />
<span>{_('Compliance Policies')}</span>
</IconDivider>
</Link>
<Link
to="portlists"
filter={composeObjFilter(PORT_LISTS_FROM_FEED)}
>
<Link to="portlists" filter="predefined=1">
<IconDivider align={['start', 'center']}>
<PortListIcon size="medium" />
<span>{_('Port Lists')}</span>
</IconDivider>
</Link>
<Link
to="reportformats"
filter={composeObjFilter(REPORT_FORMATS_FROM_FEED)}
>
<Link to="reportformats" filter="predefined=1">
<IconDivider align={['start', 'center']}>
<ReportFormatIcon size="medium" />
<span>{_('Report Formats')}</span>
</IconDivider>
</Link>
<Link
to="scanconfigs"
filter={composeObjFilter(SCAN_CONFIGS_FROM_FEED)}
>
<Link to="scanconfigs" filter="predefined=1">
<IconDivider align={['start', 'center']}>
<ScanConfigIcon size="medium" />
<span>{_('Scan Configs')}</span>
Expand Down
4 changes: 1 addition & 3 deletions gsa/src/web/pages/policies/detailspage.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ import CloneIcon from 'web/entity/icon/cloneicon';
import EditIcon from 'web/entity/icon/editicon';
import TrashIcon from 'web/entity/icon/trashicon';

import {COMPLIANCE_POLICIES_FROM_FEED} from 'web/pages/extras/feedstatuspage';

import {selector, loadEntity} from 'web/store/entities/policies';

import {
Expand Down Expand Up @@ -96,7 +94,7 @@ export const ToolBarIcons = withCapabilities(
onClick={onPolicyCloneClick}
/>
<EditIcon
disabled={COMPLIANCE_POLICIES_FROM_FEED.includes(entity.id)}
disabled={entity.predefined}
entity={entity}
displayName={_('Policy')}
onClick={onPolicyEditClick}
Expand Down
4 changes: 1 addition & 3 deletions gsa/src/web/pages/policies/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import CloneIcon from 'web/entity/icon/cloneicon';
import EditIcon from 'web/entity/icon/editicon';
import TrashIcon from 'web/entity/icon/trashicon';

import {COMPLIANCE_POLICIES_FROM_FEED} from 'web/pages/extras/feedstatuspage';

import PropTypes from 'web/utils/proptypes';
import withCapabilities from 'web/utils/withCapabilities';
import compose from 'web/utils/compose';
Expand All @@ -64,7 +62,7 @@ const PoliciesActions = compose(
/>
<EditIcon
displayName={_('Policy')}
disabled={COMPLIANCE_POLICIES_FROM_FEED.includes(entity.id)}
disabled={entity.predefined}
name="config"
entity={entity}
onClick={onPolicyEditClick}
Expand Down
4 changes: 1 addition & 3 deletions gsa/src/web/pages/portlists/detailspage.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ import CreateIcon from 'web/entity/icon/createicon';
import EditIcon from 'web/entity/icon/editicon';
import TrashIcon from 'web/entity/icon/trashicon';

import {PORT_LISTS_FROM_FEED} from 'web/pages/extras/feedstatuspage';

import {selector, loadEntity} from 'web/store/entities/portlists';

import {
Expand Down Expand Up @@ -90,7 +88,7 @@ const ToolBarIcons = ({
<CloneIcon entity={entity} onClick={onPortListCloneClick} />
<EditIcon
entity={entity}
disabled={PORT_LISTS_FROM_FEED.includes(entity.id)}
disabled={entity.predefined}
onClick={onPortListEditClick}
/>
<TrashIcon entity={entity} onClick={onPortListDeleteClick} />
Expand Down
4 changes: 1 addition & 3 deletions gsa/src/web/pages/portlists/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ import IconDivider from 'web/components/layout/icondivider';
import TableData from 'web/components/table/data';
import TableRow from 'web/components/table/row';

import {PORT_LISTS_FROM_FEED} from 'web/pages/extras/feedstatuspage';

const IconActions = ({
entity,
onPortListDeleteClick,
Expand All @@ -56,7 +54,7 @@ const IconActions = ({
/>
<EditIcon
entity={entity}
disabled={PORT_LISTS_FROM_FEED.includes(entity.id)}
disabled={entity.predefined}
displayName={_('Port List')}
name="port_list"
onClick={onPortListEditClick}
Expand Down
4 changes: 1 addition & 3 deletions gsa/src/web/pages/reportformats/detailspage.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ import withEntityContainer, {
permissionsResourceFilter,
} from 'web/entity/withEntityContainer';

import {REPORT_FORMATS_FROM_FEED} from 'web/pages/extras/feedstatuspage';

import {selector, loadEntity} from 'web/store/entities/reportformats';

import {
Expand Down Expand Up @@ -98,7 +96,7 @@ const ToolBarIcons = withCapabilities(
/>
<EditIcon
displayName={_('Report Format')}
disabled={REPORT_FORMATS_FROM_FEED.includes(entity.id)}
disabled={entity.predefined}
entity={entity}
onClick={onReportFormatEditClick}
/>
Expand Down
4 changes: 1 addition & 3 deletions gsa/src/web/pages/reportformats/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ import {renderYesNo} from 'web/utils/render';
import withCapabilities from 'web/utils/withCapabilities';
import withEntitiesActions from 'web/entities/withEntitiesActions';

import {REPORT_FORMATS_FROM_FEED} from 'web/pages/extras/feedstatuspage';

const Actions = compose(
withCapabilities,
withEntitiesActions,
Expand All @@ -64,7 +62,7 @@ const Actions = compose(
/>
<EditIcon
displayName={_('Report Format')}
disabled={REPORT_FORMATS_FROM_FEED.includes(entity.id)}
disabled={entity.predefined}
name="report_format"
entity={entity}
onClick={onReportFormatEditClick}
Expand Down
Loading