Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion auditFile/versions/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ module.exports = {
ignoreExpiresInDays: { type: 'number' }, // should it be days or should I pull in a dependency to resolve nice text?
ignoreLowSeverity: { type: 'boolean' }
}
}
},
requireReason: { type: 'boolean' },
requireReasonMatch: { type: 'string' }
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const statusManager = require('./statusManager')
const RESOLUTIONS = require('./resolutions/RESOLUTIONS')
const VALIDATIONS = require('./validations/VALIDATIONS')
const fileHandle = require('./auditFile/fileHandle')
const identifier = require('./auditFile/identifier')

module.exports = Object.assign({}, statusManager, {
RESOLUTIONS,
VALIDATIONS,
validateResolveFile: fileHandle.validateResolveFile,
identify: identifier.identify

})
14 changes: 14 additions & 0 deletions statusManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const auditFile = require('./auditFile')
const RESOLUTIONS = require('./resolutions/RESOLUTIONS')

const decision2resolution = require('./resolutions/decision2resolution')
const decision2validation = require('./validations/decision2validation')

/**
*
Expand Down Expand Up @@ -44,6 +45,18 @@ function getResolution ({ id, path }) {
return decision2resolution(data)
}

/**
*
* @param {string} identifierOrItem.id
* @param {string} identifierOrItem.path
* @returns {string} validation
*/
function getValidationError ({ id, path }) {
const data = auditFile.get({ id, path })
const rules = auditFile.getRules()
return decision2validation(data, rules)
}

/**
*
*
Expand All @@ -61,6 +74,7 @@ function set (identifierOrItem, resolution) {
module.exports = {
saveResolution,
getResolution,
getValidationError,
get,
set
}
6 changes: 6 additions & 0 deletions validations/VALIDATIONS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const VALIDATIONS = {
REASON_MISSING: 'reasonMissing',
REASON_MISMATCH: 'reasonMismatch',
}

module.exports = VALIDATIONS
24 changes: 24 additions & 0 deletions validations/decision2validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const VALIDATIONS = require('./VALIDATIONS')

module.exports = function decision2validation (vuln, rules) {
if (!vuln) {
return undefined
}
if (rules.requireReason === true) {
if (vuln.reason === "" || vuln.reason === null || vuln.reason === undefined) {
return VALIDATIONS.REASON_MISSING
}
if (rules.requireReasonMatch) {
let requireReasonRe;
try {
requireReasonRe = new RegExp(rules.requireReasonMatch)
} catch (err) {
throw Error(`audit-resolve "rules.requireReasonMatch" must be a valid JS regex. Got ${rules.requireReasonMatch}`)
}
if (!vuln.reason.match(requireReasonRe)) {
return VALIDATIONS.REASON_MISMATCH
}
}
}
return undefined
}