Skip to content

Commit

Permalink
#1063 Removed check and error preventing user from adding adp contain…
Browse files Browse the repository at this point in the history
…ers to their own cve records
  • Loading branch information
jdaigneau5 committed May 9, 2023
1 parent 4f7d03d commit 2216eac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 36 deletions.
54 changes: 25 additions & 29 deletions src/controller/cve.controller/cve.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ async function rejectExistingCve (req, res, next) {
// Called by PUT /cve/:id/adp
async function insertAdp (req, res, next) {
const CONSTANTS = getConstants()

try {
const id = req.ctx.params.id
const cveRepo = req.ctx.repositories.getCveRepository()
Expand Down Expand Up @@ -612,14 +612,10 @@ async function insertAdp (req, res, next) {
return res.status(403).json(error.cveRecordRejected())
}

if (orgUuid === cveRecord.containers.cna.providerMetadata.orgId) {
return res.status(403).json(error.cveRecordCnaContainerConflict())
if (!req.ctx.body.hasOwnProperty('adpContainer')) {
return res.status(400).json(error.badAdpFormat())
}

if (! req.ctx.body.hasOwnProperty('adpContainer')) {
return res.status(400).json(error.badAdpFormat())
}

const adpContainer = req.ctx.body.adpContainer
const dateUpdated = (new Date()).toISOString()
cveRecord.cveMetadata.dateUpdated = dateUpdated
Expand All @@ -632,41 +628,41 @@ async function insertAdp (req, res, next) {
let dupeStatus = 'new'

if (cveRecord.containers.hasOwnProperty('adp')) {
cveRecord.containers.adp.forEach(function (item, index) {
if (orgUuid === item.providerMetadata.orgId) {
dupeFound = 1
dupeIndex = index
dupeStatus = 'replacement'
}
})

adpCount = cveRecord.containers.adp.length + 1
if (dupeFound === 1) {
adpCount = adpCount - 1
}
logger.info('Number of ADP containers already: ' + cveRecord.containers.adp.length)
cveRecord.containers.adp.forEach(function (item, index) {
if (orgUuid === item.providerMetadata.orgId) {
dupeFound = 1
dupeIndex = index
dupeStatus = 'replacement'
}
})

adpCount = cveRecord.containers.adp.length + 1
if (dupeFound === 1) {
adpCount = adpCount - 1
}
logger.info('Number of ADP containers already: ' + cveRecord.containers.adp.length)
} else {
logger.info('There were previously zero ADP containers.')
adpCount = 1
cveRecord.containers.adp = []
logger.info('There were previously zero ADP containers.')
adpCount = 1
cveRecord.containers.adp = []
}

if (dupeFound === 1) {
cveRecord.containers.adp[dupeIndex] = adpContainer
cveRecord.containers.adp[dupeIndex] = adpContainer
} else {
cveRecord.containers.adp.push(adpContainer)
cveRecord.containers.adp.push(adpContainer)
}

const cveModel = new Cve({ cve: cveRecord })
result = Cve.validateCveRecord(cveModel.cve)
if (!result.isValid) {
logger.error(JSON.stringify({ uuid: req.ctx.uuid, message: 'CVE JSON schema validation FAILED.' }))
logger.error(JSON.stringify({ uuid: req.ctx.uuid, message: 'CVE JSON schema validation FAILED.' }))
return res.status(400).json(error.badAdpJson(result.errors))
}

await cveRepo.updateByCveId(id, cveModel)

let outcome = id + ' record had ' + dupeStatus + ' ADP container ' + adpCount + ' successfully inserted. This submission should appear on ' + url + ' within 15 minutes.'
const outcome = id + ' record had ' + dupeStatus + ' ADP container ' + adpCount + ' successfully inserted. This submission should appear on ' + url + ' within 15 minutes.'
const responseMessage = {
message: outcome,
updated: cveModel.cve
Expand Down Expand Up @@ -696,5 +692,5 @@ module.exports = {
CVE_UPDATE_CNA: updateCna,
CVE_REJECT_RECORD: rejectCVE,
CVE_REJECT_EXISTING_CVE: rejectExistingCve,
CVE_INSERT_ADP: insertAdp
CVE_INSERT_ADP: insertAdp
}
7 changes: 0 additions & 7 deletions src/controller/cve.controller/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ class CveControllerError extends idrErr.IDRError {
return err
}

cveRecordCnaContainerConflict () { // cve
const err = {}
err.error = 'CVE_RECORD_CNA_CONTAINER_CONFLICT'
err.message = 'The CVE Record already has a CNA container from the provider associated with the current request.'
return err
}

badAdpJson (errors) { // cve
const err = {}
err.error = 'BAD_ADP_JSON'
Expand Down

0 comments on commit 2216eac

Please sign in to comment.