Skip to content

Commit f9f92c9

Browse files
authored
Merge branch 'dev' into dr_cleanup_jan
2 parents a3ec987 + 6cc3dbb commit f9f92c9

7 files changed

Lines changed: 149 additions & 3 deletions

File tree

api-docs/openapi.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,12 @@
11041104
{
11051105
"$ref": "#/components/parameters/cveRecordFilteredTimeModifiedGt"
11061106
},
1107+
{
1108+
"$ref": "#/components/parameters/cveRecordFilteredTimeCreatedLt"
1109+
},
1110+
{
1111+
"$ref": "#/components/parameters/cveRecordFilteredTimeCreatedGt"
1112+
},
11071113
{
11081114
"$ref": "#/components/parameters/cveState"
11091115
},
@@ -4411,6 +4417,26 @@
44114417
"format": "date-time"
44124418
}
44134419
},
4420+
"cveRecordFilteredTimeCreatedLt": {
4421+
"in": "query",
4422+
"name": "time_created.lt",
4423+
"description": "Most recent CVE record created timestamp to retrieve <br><br> <i>Timestamp format</i> : yyyy-MM-ddTHH:mm:ssZZZZ",
4424+
"required": false,
4425+
"schema": {
4426+
"type": "string",
4427+
"format": "date-time"
4428+
}
4429+
},
4430+
"cveRecordFilteredTimeCreatedGt": {
4431+
"in": "query",
4432+
"name": "time_created.gt",
4433+
"description": "Earliest CVE record created timestamp to retrieve <br><br> <i>Timestamp format</i> : yyyy-MM-ddTHH:mm:ssZZZZ",
4434+
"required": false,
4435+
"schema": {
4436+
"type": "string",
4437+
"format": "date-time"
4438+
}
4439+
},
44144440
"id_quota": {
44154441
"in": "query",
44164442
"name": "id_quota",

src/controller/cve.controller/cve.controller.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ async function getFilteredCves (req, res, next) {
6767
timeStamp: [],
6868
dateOperator: []
6969
}
70+
const timeCreated = {
71+
timeStamp: [],
72+
dateOperator: []
73+
}
7074

7175
// if count_only is the only parameter, return estimated count of full set of records
7276
if ((Object.keys(req.ctx.query).length === 1) &&
@@ -88,6 +92,12 @@ async function getFilteredCves (req, res, next) {
8892
timeModified.dateOperator.push('gt')
8993
timeModified.timeStamp.push(req.ctx.query['time_modified.gt'])
9094
timeModifiedGtDateObject = req.ctx.query['time_modified.gt']
95+
} else if (key === 'time_created.lt') {
96+
timeCreated.dateOperator.push('lt')
97+
timeCreated.timeStamp.push(req.ctx.query['time_created.lt'])
98+
} else if (key === 'time_created.gt') {
99+
timeCreated.dateOperator.push('gt')
100+
timeCreated.timeStamp.push(req.ctx.query['time_created.gt'])
91101
} else if (key === 'state') {
92102
state = req.ctx.query.state
93103
} else if (key === 'assigner_short_name') { // the key is retrieved as lowercase
@@ -131,6 +141,16 @@ async function getFilteredCves (req, res, next) {
131141
}
132142
}
133143

144+
if (timeCreated.timeStamp.length > 0) {
145+
query['time.created'] = {}
146+
for (let i = 0; i < timeCreated.timeStamp.length; i++) {
147+
if (timeCreated.dateOperator[i] === 'lt') {
148+
query['time.created'].$lt = timeCreated.timeStamp[i]
149+
} else {
150+
query['time.created'].$gt = timeCreated.timeStamp[i]
151+
}
152+
}
153+
}
134154
if (adpShortName) {
135155
query['cve.containers.adp.providerMetadata.shortName'] = adpShortName
136156
}

src/controller/cve.controller/cve.middleware.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function parsePostParams (req, res, next) {
2121
}
2222

2323
function parseGetParams (req, res, next) {
24-
utils.reqCtxMapping(req, 'query', ['page', 'time_modified.lt', 'time_modified.gt', 'state', 'count_only', 'assigner_short_name', 'assigner', 'cna_modified', 'adp_short_name', 'next_page', 'previous_page', 'limit'])
24+
utils.reqCtxMapping(req, 'query', ['page', 'time_modified.lt', 'time_modified.gt', 'time_created.lt', 'time_created.gt', 'state', 'count_only', 'assigner_short_name', 'assigner', 'cna_modified', 'adp_short_name', 'next_page', 'previous_page', 'limit'])
2525
utils.reqCtxMapping(req, 'params', ['id'])
2626
next()
2727
}

src/controller/cve.controller/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ router.get('/cve',
202202
#swagger.parameters['$ref'] = [
203203
'#/components/parameters/cveRecordFilteredTimeModifiedLt',
204204
'#/components/parameters/cveRecordFilteredTimeModifiedGt',
205+
'#/components/parameters/cveRecordFilteredTimeCreatedLt',
206+
'#/components/parameters/cveRecordFilteredTimeCreatedGt',
205207
'#/components/parameters/cveState',
206208
'#/components/parameters/countOnly',
207209
'#/components/parameters/assignerShortName',
@@ -259,11 +261,13 @@ router.get('/cve',
259261
*/
260262
mw.validateUser,
261263
mw.onlySecretariatOrBulkDownload,
262-
query().custom((query) => { return mw.validateQueryParameterNames(query, ['page', 'time_modified.lt', 'time_modified.gt', 'state', 'count_only', 'assigner_short_name', 'assigner', 'cna_modified', 'adp_short_name']) }),
263-
query(['page', 'time_modified.lt', 'time_modified.gt', 'state', 'count_only', 'assigner_short_name', 'assigner', 'cna_modified', 'adp_short_name']).custom((val) => { return mw.containsNoInvalidCharacters(val) }),
264+
query().custom((query) => { return mw.validateQueryParameterNames(query, ['page', 'time_modified.lt', 'time_modified.gt', 'time_created.lt', 'time_created.gt', 'state', 'count_only', 'assigner_short_name', 'assigner', 'cna_modified', 'adp_short_name']) }),
265+
query(['page', 'time_modified.lt', 'time_modified.gt', 'time_created.lt', 'time_created.gt', 'state', 'count_only', 'assigner_short_name', 'assigner', 'cna_modified', 'adp_short_name']).custom((val) => { return mw.containsNoInvalidCharacters(val) }),
264266
query(['page']).optional().isInt({ min: CONSTANTS.PAGINATOR_PAGE }),
265267
query(['time_modified.lt']).optional().isString().trim().customSanitizer(val => { return toDate(val) }).not().isEmpty().withMessage(errorMsgs.TIMESTAMP_FORMAT),
266268
query(['time_modified.gt']).optional().isString().trim().customSanitizer(val => { return toDate(val) }).not().isEmpty().withMessage(errorMsgs.TIMESTAMP_FORMAT),
269+
query(['time_created.lt']).optional().isString().trim().customSanitizer(val => { return toDate(val) }).not().isEmpty().withMessage(errorMsgs.TIMESTAMP_FORMAT),
270+
query(['time_created.gt']).optional().isString().trim().customSanitizer(val => { return toDate(val) }).not().isEmpty().withMessage(errorMsgs.TIMESTAMP_FORMAT),
267271
query(['state']).optional().isString().trim().customSanitizer(val => { return val.toUpperCase() }).isIn(CHOICES).withMessage(errorMsgs.CVE_FILTERED_STATES),
268272
query(['count_only']).optional().isBoolean({ loose: true }).withMessage(errorMsgs.COUNT_ONLY),
269273
query(['assigner_short_name']).optional().isString().trim().notEmpty().isLength({ min: CONSTANTS.MIN_SHORTNAME_LENGTH, max: CONSTANTS.MAX_SHORTNAME_LENGTH }),

src/model/cve.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ CveSchema.query.byCveId = function (id) {
2828

2929
CveSchema.index({ 'cve.cveMetadata.cveId': 1 })
3030
CveSchema.index({ 'cve.cveMetadata.dateUpdated': 1 })
31+
CveSchema.index({ 'cve.containers.cna.provderMetadata.dateUpdated': 1 })
32+
CveSchema.index({ 'time.modified': 1 })
33+
CveSchema.index({ 'time.created': 1 })
3134

3235
CveSchema.statics.validateCveRecord = function (record) {
3336
const validateObject = {}

src/swagger.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,26 @@ const doc = {
353353
format: 'date-time'
354354
}
355355
},
356+
cveRecordFilteredTimeCreatedLt: {
357+
in: 'query',
358+
name: 'time_created.lt',
359+
description: 'Most recent CVE record created timestamp to retrieve <br><br> <i>Timestamp format</i> : yyyy-MM-ddTHH:mm:ssZZZZ',
360+
required: false,
361+
schema: {
362+
type: 'string',
363+
format: 'date-time'
364+
}
365+
},
366+
cveRecordFilteredTimeCreatedGt: {
367+
in: 'query',
368+
name: 'time_created.gt',
369+
description: 'Earliest CVE record created timestamp to retrieve <br><br> <i>Timestamp format</i> : yyyy-MM-ddTHH:mm:ssZZZZ',
370+
required: false,
371+
schema: {
372+
type: 'string',
373+
format: 'date-time'
374+
}
375+
},
356376
id_quota: {
357377
in: 'query',
358378
name: 'id_quota',
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* eslint-disable no-unused-expressions */
2+
3+
const chai = require('chai')
4+
chai.use(require('chai-http'))
5+
const expect = chai.expect
6+
7+
const constants = require('../constants.js')
8+
const app = require('../../../src/index.js')
9+
const helpers = require('../helpers.js')
10+
const _ = require('lodash')
11+
12+
const shortName = 'win_5'
13+
14+
describe('Test time_created parameter for get CVE', () => {
15+
let cveId
16+
before(async () => {
17+
cveId = await helpers.cveIdReserveHelper(1, '2023', shortName, 'non-sequential')
18+
await helpers.cveRequestAsCnaHelper(cveId)
19+
})
20+
context('Positive Test', () => {
21+
it('Get CVE with time_created.gt set to a known earlier date', async () => {
22+
await chai.request(app)
23+
.get('/api/cve/?time_created.gt=2022-01-01T00:00:00Z')
24+
.set(constants.headers)
25+
.then((res, err) => {
26+
expect(err).to.be.undefined
27+
expect(res).to.have.status(200)
28+
expect(_.some(res.body.cveRecords, { cveMetadata: { cveId: cveId } })).to.be.true
29+
})
30+
})
31+
it('Get CVE with time_created.gt should return and empty list when searched with a known bad earlier than date', async () => {
32+
await chai.request(app)
33+
.get('/api/cve/?time_created.gt=2100-01-01T00:00:00Z')
34+
.set(constants.headers)
35+
.then((res, err) => {
36+
expect(err).to.be.undefined
37+
expect(res).to.have.status(200)
38+
expect(_.some(res.body.cveRecords, { cveMetadata: { cveId: cveId } })).to.be.false
39+
})
40+
})
41+
42+
it('Get CVE with time_created.lt should return when searched with a known later than date', async () => {
43+
await chai.request(app)
44+
.get('/api/cve/?time_created.lt=2100-01-01T00:00:00Z')
45+
.set(constants.headers)
46+
.then((res, err) => {
47+
expect(err).to.be.undefined
48+
expect(res).to.have.status(200)
49+
expect(_.some(res.body.cveRecords, { cveMetadata: { cveId: cveId } })).to.be.true
50+
})
51+
})
52+
it('Get CVE with time_created.lt should return and empty list when searched with a known bad later than date', async () => {
53+
await chai.request(app)
54+
.get('/api/cve/?time_created.lt=2022-01-01T00:00:00Z')
55+
.set(constants.headers)
56+
.then((res, err) => {
57+
expect(err).to.be.undefined
58+
expect(res).to.have.status(200)
59+
expect(_.some(res.body.cveRecords, { cveMetadata: { cveId: cveId } })).to.be.false
60+
})
61+
})
62+
it('Get CVE with time_created.lt and gt set', async () => {
63+
await chai.request(app)
64+
.get('/api/cve/?time_created.lt=2100-01-01T00:00:00Z&time_created.gt=2022-01-01T00:00:00Z')
65+
.set(constants.headers)
66+
.then((res, err) => {
67+
expect(err).to.be.undefined
68+
expect(res).to.have.status(200)
69+
expect(_.some(res.body.cveRecords, { cveMetadata: { cveId: cveId } })).to.be.true
70+
})
71+
})
72+
})
73+
})

0 commit comments

Comments
 (0)