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

if details not defined, then choose first OS from identifiers #1719

Merged
merged 3 commits into from
Oct 24, 2019
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 @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added

### Changed
- If details not defined, then choose first OS from identifiers [#1719](https://github.com/greenbone/gsa/pull/1719)
- Sorting of SecInfo items [#1717](https://github.com/greenbone/gsa/pull/1717))
- Disable edit PowerFilter icon if isLoading [#1714](https://github.com/greenbone/gsa/pull/1714)
- Don't show empty menu section [#1711](https://github.com/greenbone/gsa/pull/1711)
Expand Down
53 changes: 53 additions & 0 deletions gsa/src/gmp/models/__tests__/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,59 @@ describe('Host model tests', () => {
expect(host3.hostname).toBeUndefined();
});

test('should parse best_os_cpe', () => {
const elem1 = {
host: {
detail: [
{
name: 'best_os_cpe',
value: 'cpe:/foo/bar',
},
],
},
};

const elem2 = {
identifiers: {
identifier: [
{
name: 'OS',
value: 'cpe:/foo/bar',
},
],
},
};

const elem3 = {
identifiers: {
identifier: [
{
name: 'notavailable',
value: 'no',
},
],
},
};

const elem4 = {
host: {
severity: {
value: '8.5',
},
},
};

const host1 = Host.fromElement(elem1);
const host2 = Host.fromElement(elem2);
const host3 = Host.fromElement(elem3);
const host4 = Host.fromElement(elem4);

expect(host1.os).toEqual('cpe:/foo/bar');
expect(host2.os).toEqual('cpe:/foo/bar');
expect(host3.os).toBeUndefined();
expect(host4.os).toBeUndefined();
});

test('should return ip identifier', () => {
const elem = {
identifiers: {
Expand Down
22 changes: 18 additions & 4 deletions gsa/src/gmp/models/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import {isDefined} from '../utils/identity';
import {isEmpty} from '../utils/string';
import {forEach, map} from '../utils/array';

import 'core-js/features/array/find';

import {isDefined} from 'gmp/utils/identity';
import {isEmpty} from 'gmp/utils/string';
import {forEach, map} from 'gmp/utils/array';

import {
parseInt,
parseProperties,
parseSeverity,
parseYesNo,
setProperties,
} from '../parser';
} from 'gmp/parser';

import Asset from './asset';

Expand Down Expand Up @@ -110,6 +113,17 @@ class Host extends Asset {
ret.routes = [];
}

if (isDefined(ret.details) && isDefined(ret.details.best_os_cpe)) {
ret.os = ret.details.best_os_cpe.value;
} else if (isDefined(ret.identifiers)) {
const firstOs = ret.identifiers.find(
identifier => identifier.name === 'OS',
);
ret.os = isDefined(firstOs) ? firstOs.value : undefined;
} else {
ret.os = undefined;
}

return ret;
}
}
Expand Down
6 changes: 2 additions & 4 deletions gsa/src/web/pages/hosts/row.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,8 @@ const Row = ({
onToggleDetailsClick,
...props
}) => {
const {details = {}} = entity;
const os_cpe = isDefined(details.best_os_cpe)
? details.best_os_cpe.value
: undefined;
const {details = {}, os} = entity;
const os_cpe = os;
const os_txt = isDefined(details.best_os_txt)
? details.best_os_txt.value
: undefined;
Expand Down