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

Initialize severity value with 0 in powerfilter (backport #3031) #3032

Merged
merged 6 commits into from
Jun 29, 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]
## [21.4.2] (unreleased)
### Added
### Changed
### Deprecated
### Removed
### Fixed
- Initialize severity value with 0 in powerfilter SeverityValuesGroup [#3031](https://github.com/greenbone/gsa/pull/3031)

[Unreleased]: https://github.com/greenbone/gsa/compare/v21.4.1...gsa-21.04

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ exports[`Severity Values Group Tests should render 1`] = `
<input
max="10"
min="0"
name="cvss_base"
name="severity"
size="5"
value="3"
/>
Expand Down
42 changes: 31 additions & 11 deletions gsa/src/web/components/powerfilter/__tests__/severityvaluesgroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import Filter from 'gmp/models/filter';

describe('Severity Values Group Tests', () => {
test('should render', () => {
const filter = Filter.fromString('cvss_base>3');
const name = 'cvss_base';
const filter = Filter.fromString('severity>3');
const name = 'severity';
const onChange = jest.fn();

const {element} = render(
Expand All @@ -49,8 +49,8 @@ describe('Severity Values Group Tests', () => {

test('arguments are processed correctly', () => {
const onChange = jest.fn();
const filter = Filter.fromString('cvss_base=3');
const name = 'cvss_base';
const filter = Filter.fromString('severity=3');
const name = 'severity';

const {element} = render(
<SeverityValuesGroup
Expand All @@ -65,14 +65,34 @@ describe('Severity Values Group Tests', () => {
const numField = element.querySelectorAll('input');

expect(formTitle[0]).toHaveTextContent('foo');
expect(numField[0]).toHaveAttribute('name', 'cvss_base');
expect(numField[0]).toHaveAttribute('name', 'severity');
expect(numField[0]).toHaveAttribute('value', '3');
});

test('should initialize value with 0 in case no filter value is given', () => {
const onChange = jest.fn();
const filter = Filter.fromString('rows=10');
const name = 'severity';

const {element} = render(
<SeverityValuesGroup
filter={filter}
name={name}
title="foo"
onChange={onChange}
/>,
);

const numField = element.querySelectorAll('input');

expect(numField[0]).toHaveAttribute('name', 'severity');
expect(numField[0]).toHaveAttribute('value', '0');
});

test('should change value', () => {
const onChange = jest.fn();
const filter = Filter.fromString('cvss_base=3');
const name = 'cvss_base';
const filter = Filter.fromString('severity=3');
const name = 'severity';

const {element} = render(
<SeverityValuesGroup
Expand All @@ -87,13 +107,13 @@ describe('Severity Values Group Tests', () => {

fireEvent.change(numField[0], {target: {value: '9'}});

expect(onChange).toHaveBeenCalledWith(9, 'cvss_base', '=');
expect(onChange).toHaveBeenCalledWith(9, 'severity', '=');
});

test('should change relationship', () => {
const onChange = jest.fn();
const filter = Filter.fromString('cvss_base=3');
const name = 'cvss_base';
const filter = Filter.fromString('severity=3');
const name = 'severity';

const {element, baseElement} = render(
<SeverityValuesGroup
Expand All @@ -111,6 +131,6 @@ describe('Severity Values Group Tests', () => {
fireEvent.click(domItems[2]);

expect(onChange).toBeCalled();
expect(onChange).toBeCalledWith(3, 'cvss_base', '<');
expect(onChange).toBeCalledWith(3, 'severity', '<');
});
});
2 changes: 1 addition & 1 deletion gsa/src/web/components/powerfilter/severityvaluesgroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const SeverityValuesGroup = ({filter, name, title, onChange}) => {
*/

const term = filter.getTerm(name);
const severity = isDefined(term) ? parseSeverity(term.value) : undefined;
const severity = isDefined(term) ? parseSeverity(term.value) : 0;

const [rel, setRel] = useState(isDefined(term) ? term.relation : '='); // here rel is set to '='
const keyword = name;
Expand Down
2 changes: 1 addition & 1 deletion gsa/src/web/pages/results/filterdialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const ResultsFilterDialogComponent = ({
/>

<SeverityValuesGroup
name="cvss_base"
name="severity"
filter={filter}
title={_('Severity')}
onChange={onFilterValueChange}
Expand Down