Skip to content

Commit

Permalink
#980 Fixed validation calls for rejecting cves
Browse files Browse the repository at this point in the history
  • Loading branch information
jdaigneau5 committed Jan 6, 2023
1 parent 6ab7600 commit 3370a87
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/controller/cve.controller/cve.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,9 @@ async function rejectCVE (req, res, next) {
const newCveObj = new Cve({ cve: rejectedCve })

result = Cve.validateCveRecord(newCveObj.cve)
if (!result) {
return res.status(500).json(error.serverError())
if (!result.isValid) {
logger.error(JSON.stringify({ uuid: req.ctx.uuid, message: 'CVE JSON schema validation FAILED.' }))
return res.status(400).json(error.invalidCnaContainerJsonSchema(result.errors))
}

// Save rejected CVE record object
Expand Down Expand Up @@ -540,9 +541,10 @@ async function rejectExistingCve (req, res, next) {
// update CVE record to rejected
const updatedRecord = Cve.updateCveToRejected(id, providerMetadata, result.cve, req.ctx.body)
const updatedCve = new Cve({ cve: updatedRecord })
result = Cve.validateCveRecord(updatedCve)
if (!result) {
return res.status(500).json(error.serverError())
result = Cve.validateCveRecord(updatedCve.cve)
if (!result.isValid) {
logger.error(JSON.stringify({ uuid: req.ctx.uuid, message: 'CVE JSON schema validation FAILED.' }))
return res.status(400).json(error.invalidCnaContainerJsonSchema(result.errors))
}
result = await cveRepo.updateByCveId(id, updatedCve)
if (!result) {
Expand Down

0 comments on commit 3370a87

Please sign in to comment.