Resolves #881 Invalid Cve Schemas Posts and Puts now return a 400 status code and corresponding errors #945
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #881
Summary
Invalid language codes in POST/PUT
/api/cve/:id/cna
would cause a 500 error. This was because the language code didn't validate against the Cve schema, causing an invalid schema error that threw a 500. This was changed to throw a 400 error and return corresponding schema validation errors.Important Changes
cve.js
validateCveRecord()
to return an object with corresponding schema validation errorscve.controller.js
submitCna()
andupdateCna()
to throw 400 errors instead of 500 errors when the Cve schema is invalid.Testing
Sample JSON for testing
{"cnaContainer" : {
"descriptions" : [ { "lang" : "eng", "value" : "One more CVE Services test CVE Record post." } ],
"affected" : [ { "versions" : [ { "version" : "1.1.0", "status" : "affected" } ],
"product" : "CVE Services product number two", "vendor" : "MITRE" } ],
"references" : [ { "url" : "http://mitre.org" } ],
"providerMetadata" : { "orgId" : "466e066c-d384-4b8a-8b15-067d9c22c5af",
"shortName" : "mitre",
"dateUpdated" : "2022-04-28T21:30:13.057Z"
}
}}