Set cvss vector default to nil
What does this MR do and why?
The cvss vector validator treats attributes with empty string as invalid. This change updates the data object created to set cvss vectors to nil if they are missing from the imported json.
Changelog: changed
How to set up and validate locally
Run below in rails console.
json = '{"advisory":{"id":"a2e11cbc-61b8-4b91-b72b-fe5df1bc492b","source":"glad","cvss_v2":"AV:N/AC:M/Au:N/C:P/I:P/A:P","published_date":"2013-11-02","identifiers":[{"type":"cve","name":"CVE-2013-4457","value":"CVE-2013-4457","url":"https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2013-4457"}]},"packages":[{"name":"cocaine","purl_type":"gem","affected_range":">=0.4.0 <=0.5.2","solution":"Upgrade to 0.5.3","fixed_versions":["0.5.3"]}]}'
obj = PackageMetadata::AdvisoryDataObject.create(JSON.parse(json), 'rubygem')
advisory = PackageMetadata::Advisory.new(advisory_xid: obj.advisory_xid, cvss_v2: obj.cvss_v2, cvss_v3: obj.cvss_v3, source_xid: 'glad', published_date: obj.published_date, identifiers: obj.identifiers)
advisory.valid?
For master, the json input incorrectly generates an invalid advisory because cvss_v3 is missing in the json. For this branch, a valid advisory is generated.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #417914 (closed)
Edited by Igor Frenkel