-
Notifications
You must be signed in to change notification settings - Fork 75
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 #1099 from CVEProject/dr-818
Resolves #818 - Better Errors for Bad dates in time_modified
- Loading branch information
Showing
2 changed files
with
114 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* eslint-disable no-unused-expressions */ | ||
|
||
const chai = require('chai') | ||
chai.use(require('chai-http')) | ||
const expect = chai.expect | ||
|
||
const constants = require('../constants.js') | ||
const app = require('../../../src/index.js') | ||
|
||
describe('Test time_modified for get CVE', () => { | ||
context('Negative Tests', () => { | ||
it('Get CVE should fail if time_modified.gt is given a date with an invalid month', async () => { | ||
await chai.request(app) | ||
.get('/api/cve?time_modified.gt=2022-13-01T00:00:00Z') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(400) | ||
expect(res.body.message).to.contain('Parameters were invalid') | ||
}) | ||
}) | ||
it('Get CVE should fail if time_modified.lt is given a date with an invalid month', async () => { | ||
await chai.request(app) | ||
.get('/api/cve?time_modified.lt=2022-13-01T00:00:00Z') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(400) | ||
expect(res.body.message).to.contain('Parameters were invalid') | ||
}) | ||
}) | ||
it('Get CVE should fail if time_modified.lt is given a date with an invalid day', async () => { | ||
await chai.request(app) | ||
.get('/api/cve?time_modified.lt=2022-01-32T00:00:00Z') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(400) | ||
expect(res.body.message).to.contain('Parameters were invalid') | ||
}) | ||
}) | ||
it('Get CVE should fail if time_modified.gt is given a date with an invalid day', async () => { | ||
await chai.request(app) | ||
.get('/api/cve?time_modified.gt=2022-01-32T00:00:00Z') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(400) | ||
expect(res.body.message).to.contain('Parameters were invalid') | ||
}) | ||
}) | ||
it('Get CVE should fail if time_modified.gt is given a date with invalid hours', async () => { | ||
await chai.request(app) | ||
.get('/api/cve?time_modified.gt=2022-01-01T25:00:00Z') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(400) | ||
expect(res.body.message).to.contain('Parameters were invalid') | ||
}) | ||
}) | ||
it('Get CVE should fail if time_modified.lt is given a date with invalid hours', async () => { | ||
await chai.request(app) | ||
.get('/api/cve?time_modified.lt=2022-01-01T25:00:00Z') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(400) | ||
expect(res.body.message).to.contain('Parameters were invalid') | ||
}) | ||
}) | ||
it('Get CVE should fail if time_modified.gt is given a date with invalid minutes', async () => { | ||
await chai.request(app) | ||
.get('/api/cve?time_modified.gt=2022-01-01T00:61:00Z') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(400) | ||
expect(res.body.message).to.contain('Parameters were invalid') | ||
}) | ||
}) | ||
it('Get CVE should fail if time_modified.lt is given a date with invalid minutes', async () => { | ||
await chai.request(app) | ||
.get('/api/cve?time_modified.lt=2022-01-01T00:61:00Z') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(400) | ||
expect(res.body.message).to.contain('Parameters were invalid') | ||
}) | ||
}) | ||
it('Get CVE should fail if time_modified.gt is given a date with invalid seconds', async () => { | ||
await chai.request(app) | ||
.get('/api/cve?time_modified.gt=2022-01-01T00:00:61Z') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(400) | ||
expect(res.body.message).to.contain('Parameters were invalid') | ||
}) | ||
}) | ||
it('Get CVE should fail if time_modified.lt is given a date with invalid seconds', async () => { | ||
await chai.request(app) | ||
.get('/api/cve?time_modified.lt=2022-01-01T00:00:61Z') | ||
.set(constants.headers) | ||
.then((res, err) => { | ||
expect(err).to.be.undefined | ||
expect(res).to.have.status(400) | ||
expect(res.body.message).to.contain('Parameters were invalid') | ||
}) | ||
}) | ||
}) | ||
}) |