Skip to content

Commit

Permalink
update products parsing and test
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-mng committed Jan 16, 2025
1 parent e4477f2 commit 947e0cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 52 deletions.
49 changes: 0 additions & 49 deletions src/gmp/models/__tests__/cve.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ describe('CVE model tests', () => {
},
};
const cve = Cve.fromElement(elem);

expect(cve.products).toEqual(['foo:bar/dolor', 'ipsum:lorem']);
});

Expand Down Expand Up @@ -194,40 +193,6 @@ describe('CVE model tests', () => {
expect(cve.references).toEqual(res);
});

test('should parse cvss source', () => {
const elem = {
raw_data: {
entry: {
'published-datetime': '2018-10-10T11:41:23.022Z',
'last-modified-datetime': '2018-10-10T11:41:23.022Z',
cvss: {
base_metrics: {
source: 'prot://url',
},
},
},
},
};
const cve = Cve.fromElement(elem);

expect(cve.source).toEqual('prot://url');
});

test('should parse summary', () => {
const elem = {
raw_data: {
entry: {
'published-datetime': '2018-10-10T11:41:23.022Z',
'last-modified-datetime': '2018-10-10T11:41:23.022Z',
summary: 'lorem ipsum',
},
},
};
const cve = Cve.fromElement(elem);

expect(cve.description).toEqual('lorem ipsum');
});

test('should parse vulnerable products from raw data', () => {
const elem = {
raw_data: {
Expand All @@ -245,20 +210,6 @@ describe('CVE model tests', () => {
expect(cve.products).toEqual(['lorem', 'ipsum']);
});

test('should delete raw data', () => {
const elem = {
raw_data: {
entry: {
'published-datetime': {__text: '2018-10-10T11:41:23.022Z'},
'last-modified-datetime': {__text: '2018-10-10T11:41:23.022Z'},
},
},
};
const cve = Cve.fromElement(elem);

expect(cve.raw_data).toBeUndefined();
});

test('should return empty array for references if no raw data is given', () => {
const cve = Cve.fromElement({});

Expand Down
8 changes: 5 additions & 3 deletions src/gmp/models/cve.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class Cve extends Info {
}

ret.cvssBaseVector = ret.cvss_vector;

ret.products = isEmpty(ret.products) ? [] : ret.products.split(' ');

/*
Expand All @@ -131,7 +132,7 @@ class Cve extends Info {
);

ret.references = [];
if (isDefined(element.cve.references?.reference)) {
if (element.cve && isDefined(element.cve.references?.reference)) {
ret.references = map(element.cve.references.reference, ref => {
let tags = [];
if (isArray(ref.tags.tag)) {
Expand All @@ -156,6 +157,7 @@ class Cve extends Info {
}

if (
ret.products &&
ret.products.length === 0 &&
isDefined(element.cve?.configuration_nodes?.node)
) {
Expand All @@ -182,11 +184,11 @@ class Cve extends Info {
ret.raw_data?.entry?.['vulnerable-software-list']?.product;
if (productsEntry) {
ret.products = isArray(productsEntry) ? productsEntry : [productsEntry];
} else {
ret.products = [];
}
}

ret.products = ret.products.filter(product => product !== '');

return ret;
}
}
Expand Down

0 comments on commit 947e0cd

Please sign in to comment.