forked from CVEProject/cve-services
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request CVEProject#1091 from CVEProject/jd-741
Resolves CVEProject#741 Fixes GET `/cve-id` endpoint's out of memory bug
- Loading branch information
Showing
6 changed files
with
295 additions
and
871 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* eslint-disable no-unused-expressions */ | ||
|
||
const chai = require('chai') | ||
chai.use(require('chai-http')) | ||
const _ = require('lodash') | ||
|
||
const expect = chai.expect | ||
|
||
const constants = require('../constants.js') | ||
const app = require('../../../src/index.js') | ||
|
||
describe('Testing Get CVE-ID endpoint', () => { | ||
const RESESRVED_COUNT = 116 | ||
const YEAR_COUNT = 10 | ||
const PUB_YEAR_COUNT = 4 | ||
const TIME_WINDOW_COUNT = 40 | ||
|
||
context('Positive Tests', () => { | ||
it('Get CVE-ID should return everything when no parameters are specifed', async () => { | ||
await chai.request(app) | ||
.get('/api/cve-id') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(200) | ||
}) | ||
}) | ||
it('Get CVE-ID should return an empty array when time modified is set to a very far future date', async () => { | ||
await chai.request(app) | ||
.get('/api/cve-id?time_modified.gt=2100-01-01T00:00:00') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(200) | ||
expect(res.body.cve_ids).to.have.length(0) | ||
}) | ||
}) | ||
// Need a better way to test each individual cve-id's time_modified | ||
it('Get all CVE-IDs modified within a given timeframe', async () => { | ||
await chai.request(app) | ||
.get('/api/cve-id?time_modified.gt=2021-05-11T15:05:20.093Z&time_modified.lt=2021-05-11T15:07:00.093Z') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(200) | ||
expect(res.body.cve_ids).to.have.length(TIME_WINDOW_COUNT) | ||
}) | ||
}) | ||
it('Get all CVE-IDs in the RESERVED state', async () => { | ||
await chai.request(app) | ||
.get('/api/cve-id?state=RESERVED') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(200) | ||
expect(_.every(res.body.cve_ids, { state: 'RESERVED' })).to.be.true | ||
expect(res.body.cve_ids).to.have.length(RESESRVED_COUNT) | ||
}) | ||
}) | ||
it('Get all CVE-IDs in the PUBLISHED state', async () => { | ||
await chai.request(app) | ||
.get('/api/cve-id?state=PUBLISHED') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(200) | ||
expect(_.every(res.body.cve_ids, { state: 'PUBLISHED' })).to.be.true | ||
}) | ||
}) | ||
it('Get all CVE-IDs in the REJECTED state', async () => { | ||
await chai.request(app) | ||
.get('/api/cve-id?state=REJECTED') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(200) | ||
expect(_.every(res.body.cve_ids, { state: 'REJECTED' })).to.be.true | ||
}) | ||
}) | ||
it('Get all CVE-IDs with cve_id_year 1999', async () => { | ||
await chai.request(app) | ||
.get('/api/cve-id?cve_id_year=1999') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(200) | ||
expect(_.every(res.body.cve_ids, { cve_year: '1999' })).to.be.true | ||
expect(res.body.cve_ids).to.have.length(YEAR_COUNT) | ||
}) | ||
}) | ||
it('Get all CVE-IDs with cve_id_year 1999 with state PUBLISHED', async () => { | ||
await chai.request(app) | ||
.get('/api/cve-id?cve_id_year=1999&state=PUBLISHED') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(200) | ||
expect(_.every(res.body.cve_ids, { cve_year: '1999', state: 'PUBLISHED' })).to.be.true | ||
expect(res.body.cve_ids).to.have.length(PUB_YEAR_COUNT) | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.