Files
pruefwerk/compliance-core/tests/vex_schemas.rs
T
sharang 44b2f38841
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 5s
CI / Deploy Dashboard (push) Successful in 5m49s
CI / Deploy Docs (push) Successful in 1m15s
CI / Deploy MCP (push) Successful in 3m33s
CI / Deploy Agent (push) Successful in 8m37s
fix(vex): CVE is the primary vulnerability id in VEX, CSAF and CycloneDX, GHSA an alias (#542)
2026-10-09 13:22:05 +00:00

624 lines
23 KiB
Rust

//! The SBOM and VEX documents Prüfwerk writes against the official schemas
//! vendored in `schemas/` (#498, #508): CycloneDX 1.6, OpenVEX 0.2.0 and CSAF
//! 2.0.
#![allow(clippy::expect_used, clippy::unwrap_used)]
use chrono::Utc;
use compliance_core::csaf_docs;
use compliance_core::models::{
CveAlert, CveSource, SbomEntry, VexAssessment, VexJustification, VexStatus, VulnRef,
};
use compliance_core::sbom_docs;
use compliance_core::vex_docs::{self, VexInput};
fn schema(name: &str) -> serde_json::Value {
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("schemas")
.join(name);
serde_json::from_str(&std::fs::read_to_string(path).unwrap()).unwrap()
}
/// The errors of `doc` against CycloneDX 1.6 (with the SPDX and JSF schemas
/// it refers to).
fn cyclonedx_errors(doc: &serde_json::Value) -> Vec<String> {
let validator = jsonschema::options()
.with_resource(
"http://cyclonedx.org/schema/spdx.schema.json",
jsonschema::Resource::from_contents(schema("spdx.schema.json")).unwrap(),
)
.with_resource(
"http://cyclonedx.org/schema/jsf-0.82.schema.json",
jsonschema::Resource::from_contents(schema("jsf-0.82.schema.json")).unwrap(),
)
.build(&schema("bom-1.6.schema.json"))
.unwrap();
validator
.iter_errors(doc)
.map(|e| format!("{} at {}", e, e.instance_path))
.collect()
}
/// The errors of `doc` against CSAF 2.0 (with the CVSS schemas it refers to).
fn csaf_errors(doc: &serde_json::Value) -> Vec<String> {
let mut options = jsonschema::options();
for version in ["2.0", "3.0", "3.1"] {
options = options.with_resource(
format!("https://www.first.org/cvss/cvss-v{version}.json"),
jsonschema::Resource::from_contents(schema(&format!("cvss-v{version}.json"))).unwrap(),
);
}
let validator = options.build(&schema("csaf_json_schema.json")).unwrap();
validator
.iter_errors(doc)
.map(|e| format!("{} at {}", e, e.instance_path))
.collect()
}
fn openvex_errors(doc: &serde_json::Value) -> Vec<String> {
let validator = jsonschema::validator_for(&schema("openvex-0.2.0.schema.json")).unwrap();
validator
.iter_errors(doc)
.map(|e| format!("{} at {}", e, e.instance_path))
.collect()
}
fn sbom() -> Vec<SbomEntry> {
let mut log4j = SbomEntry::new(
"t".into(),
"log4j-core".into(),
"2.14.1".into(),
"maven".into(),
);
log4j.purl = Some("pkg:maven/org.apache.logging.log4j/log4j-core@2.14.1".into());
log4j.license = Some("Apache-2.0".into());
log4j.known_vulnerabilities = vec![VulnRef {
id: "GHSA-jfh8-c2jp-5v3q".into(),
source: "osv".into(),
severity: Some("CRITICAL".into()),
url: None,
exploitation: None,
aliases: Vec::new(),
}];
let mut lodash = SbomEntry::new("t".into(), "lodash".into(), "4.17.20".into(), "npm".into());
lodash.purl = Some("pkg:npm/lodash@4.17.20".into());
lodash.license = Some("MIT OR Apache-2.0".into());
lodash.hashes = vec![compliance_core::models::ComponentHash {
alg: "SHA-512".into(),
content: "bf690311ee7b95e713ba568322e3533f2dd1cb880b189e99d4edef13592b81764daec43e2c54c61d5c558dc5cfb35ecb85b65519e74026ff17675b6f8f916f4a".into(),
}];
lodash.download_url = Some("https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz".into());
lodash.manufacturer_url = Some("https://lodash.com/".into());
let mut fw = SbomEntry::new(
"t".into(),
"PumpSDK".into(),
"3.1.0".into(),
"carthage".into(),
);
fw.license = Some("Custom Pump License".into());
vec![log4j, lodash, fw]
}
fn alert(id: &str, package: &str, version: &str) -> CveAlert {
let mut a = CveAlert::new(
id.into(),
"t".into(),
package.into(),
version.into(),
CveSource::Osv,
);
a.severity = Some("HIGH".into());
a
}
fn statement(status: VexStatus) -> VexAssessment {
VexAssessment {
status,
justification: None,
impact_statement: None,
action_statement: None,
by: "u1".into(),
by_name: Some("Erika".into()),
at: Utc::now(),
by_scan: false,
}
}
fn alerts() -> Vec<CveAlert> {
let mut affected = alert("CVE-2021-44228", "log4j-core", "2.14.1");
let mut s = statement(VexStatus::Affected);
s.action_statement = Some("Update the pump app to 4.2, which ships log4j 2.17.1.".into());
affected.vex = Some(s);
affected.fixed_versions = vec!["2.17.1".into()];
let mut not_affected = alert("CVE-2021-23337", "lodash", "4.17.20");
let mut s = statement(VexStatus::NotAffected);
s.justification = Some(VexJustification::VulnerableCodeNotInExecutePath);
s.impact_statement = Some("template() is never called.".into());
not_affected.vex = Some(s);
let mut gone = alert("CVE-2020-0001", "zlib", "1.2.11");
gone.resolved_at = Some(Utc::now());
vec![
affected,
not_affected,
gone,
alert("CVE-2024-0002", "PumpSDK", "3.1.0"),
]
}
#[test]
fn the_cyclonedx_sbom_is_valid_and_its_vulnerabilities_point_at_components() {
let doc = sbom_docs::cyclonedx(&sbom(), "Pump Remote");
assert_eq!(cyclonedx_errors(&doc), Vec::<String>::new());
assert_eq!(doc["specVersion"], "1.6");
assert_eq!(doc["metadata"]["manufacturer"]["name"], "BreakPilot GmbH");
assert_eq!(
doc["metadata"]["manufacturer"]["contact"][0]["email"],
"kontakt@breakpilot.com"
);
// The product's version is when its SBOM data was compiled.
assert!(doc["metadata"]["component"]["version"]
.as_str()
.unwrap()
.ends_with('Z'));
assert_eq!(
doc["metadata"]["component"]["bom-ref"],
"pkg:generic/Pump%20Remote"
);
assert_eq!(
doc["vulnerabilities"][0]["affects"][0]["ref"],
"pkg:maven/org.apache.logging.log4j/log4j-core@2.14.1"
);
assert_eq!(
doc["components"][1]["licenses"][0]["expression"],
"MIT OR Apache-2.0"
);
assert_eq!(
doc["components"][2]["licenses"][0]["license"]["name"],
"Custom Pump License"
);
// BSI TR-03183-2: registry packages name their file and describe it;
// a component without a purl gets none of the properties.
let property = |i: usize, name: &str| {
doc["components"][i]["properties"]
.as_array()
.into_iter()
.flatten()
.find(|p| p["name"] == name)
.map(|p| p["value"].as_str().unwrap().to_string())
};
assert_eq!(
property(0, "bsi:component:filename").as_deref(),
Some("log4j-core-2.14.1.jar")
);
assert_eq!(
property(1, "bsi:component:filename").as_deref(),
Some("lodash-4.17.20.tgz")
);
assert_eq!(
property(1, "bsi:component:executable").as_deref(),
Some("non-executable")
);
assert_eq!(property(2, "bsi:component:filename"), None);
// The lockfile's hash, on the component and on its download.
assert_eq!(doc["components"][1]["hashes"][0]["alg"], "SHA-512");
assert_eq!(
doc["components"][1]["externalReferences"][0]["type"],
"distribution"
);
assert_eq!(
doc["components"][1]["externalReferences"][0]["hashes"][0]["alg"],
"SHA-512"
);
assert!(doc["components"][0].get("hashes").is_none());
assert_eq!(
doc["components"][1]["manufacturer"]["url"][0],
"https://lodash.com/"
);
assert_eq!(doc["components"][0]["group"], "org.apache.logging.log4j");
assert!(doc["components"][2].get("group").is_none());
assert_eq!(
doc["components"][0]["licenses"][0]["license"]["acknowledgement"],
"declared"
);
// The product depends on every component; each has its own entry, and
// the graph says it is incomplete (the SBOM is flat).
let dependencies = doc["dependencies"].as_array().unwrap();
assert_eq!(dependencies.len(), 4);
assert_eq!(dependencies[0]["ref"], "pkg:generic/Pump%20Remote");
assert_eq!(dependencies[0]["dependsOn"].as_array().unwrap().len(), 3);
assert_eq!(doc["compositions"][0]["aggregate"], "incomplete");
// The checks catch what was wrong before: vulnerabilities inside a
// component, and a license name passed off as an SPDX id.
let mut nested = doc.clone();
nested["components"][0]["vulnerabilities"] = serde_json::json!([]);
assert!(!cyclonedx_errors(&nested).is_empty());
let mut bad_id = doc.clone();
bad_id["components"][2]["licenses"] =
serde_json::json!([{ "license": { "id": "Custom Pump License" } }]);
assert!(!cyclonedx_errors(&bad_id).is_empty());
}
#[test]
fn the_vex_documents_are_valid_against_their_schemas() {
let sbom = sbom();
let alerts = alerts();
let input = VexInput {
subject: "Pump Remote",
author: "Example Pumps GmbH",
tooling: "Prüfwerk test",
alerts: &alerts,
sbom: &sbom,
now: Utc::now(),
};
let openvex = vex_docs::openvex(&input);
assert_eq!(openvex_errors(&openvex), Vec::<String>::new());
let mut no_status = openvex.clone();
no_status["statements"][0]
.as_object_mut()
.unwrap()
.remove("status");
assert!(!openvex_errors(&no_status).is_empty());
let statuses: Vec<&str> = openvex["statements"]
.as_array()
.unwrap()
.iter()
.map(|s| s["status"].as_str().unwrap())
.collect();
assert_eq!(
statuses,
["affected", "not_affected", "fixed", "under_investigation"]
);
assert_eq!(
openvex["statements"][1]["justification"],
"vulnerable_code_not_in_execute_path"
);
let cdx = vex_docs::cyclonedx_vex(&input);
assert_eq!(cyclonedx_errors(&cdx), Vec::<String>::new());
let states: Vec<&str> = cdx["vulnerabilities"]
.as_array()
.unwrap()
.iter()
.map(|v| v["analysis"]["state"].as_str().unwrap())
.collect();
assert_eq!(
states,
["exploitable", "not_affected", "resolved", "in_triage"]
);
assert_eq!(
cdx["vulnerabilities"][1]["analysis"]["justification"],
"code_not_reachable"
);
assert_eq!(
cdx["vulnerabilities"][0]["analysis"]["response"][0],
"update"
);
}
fn vex_input<'a>(alerts: &'a [CveAlert], sbom: &'a [SbomEntry]) -> VexInput<'a> {
VexInput {
subject: "Pump Remote",
author: "Example Pumps GmbH",
tooling: "Prüfwerk test",
alerts,
sbom,
now: Utc::now(),
}
}
/// The alerts plus a GitHub advisory for the same CVE as the log4j alert,
/// found in a second component: one vulnerability in CSAF.
fn csaf_alerts() -> Vec<CveAlert> {
let mut alerts = alerts();
let mut ghsa = alert("GHSA-jfh8-c2jp-5v3q", "log4j-api", "2.14.1");
ghsa.aliases = vec!["CVE-2021-44228".into()];
ghsa.summary = Some("Remote code injection in Log4j".into());
alerts.push(ghsa);
alerts
}
#[test]
fn the_csaf_advisory_is_valid_and_carries_the_statements() {
let (sbom, alerts) = (sbom(), csaf_alerts());
let doc = csaf_docs::csaf_vex(
&vex_input(&alerts, &sbom),
"https://example.invalid/pumps",
"de",
);
assert_eq!(csaf_errors(&doc), Vec::<String>::new());
assert_eq!(doc["document"]["category"], "csaf_vex");
assert_eq!(doc["document"]["tracking"]["status"], "draft");
assert_eq!(doc["document"]["distribution"]["tlp"]["label"], "AMBER");
assert_eq!(doc["document"]["lang"], "de");
assert_eq!(doc["document"]["notes"][0]["text"], csaf_docs::DRAFT_NOTE);
let vulns = doc["vulnerabilities"].as_array().unwrap();
// Log4Shell once, though two alerts name it.
assert_eq!(vulns.len(), 4);
let log4shell = &vulns[0];
assert_eq!(log4shell["cve"], "CVE-2021-44228");
assert_eq!(
log4shell["ids"][0]["system_name"],
"GitHub Security Advisories"
);
assert_eq!(log4shell["ids"][0]["text"], "GHSA-jfh8-c2jp-5v3q");
let affected = log4shell["product_status"]["known_affected"]
.as_array()
.unwrap();
assert_eq!(affected.len(), 1);
assert_eq!(
log4shell["product_status"]["under_investigation"][0],
"C5-IN-PRODUCT"
);
assert_eq!(log4shell["remediations"][0]["category"], "vendor_fix");
assert_eq!(log4shell["remediations"][0]["product_ids"][0], affected[0]);
let lodash = &vulns[1];
assert_eq!(
lodash["flags"][0]["label"],
"vulnerable_code_not_in_execute_path"
);
assert_eq!(lodash["threats"][0]["category"], "impact");
assert!(vulns[2]["product_status"]["fixed"].is_array());
// Every status names a component in the product.
let relationships = doc["product_tree"]["relationships"].as_array().unwrap();
assert_eq!(relationships.len(), 5);
assert_eq!(relationships[0]["relates_to_product_reference"], "PRODUCT");
// A broken document fails the check.
let mut no_publisher = doc.clone();
no_publisher["document"]
.as_object_mut()
.unwrap()
.remove("publisher");
assert!(!csaf_errors(&no_publisher).is_empty());
}
/// The advisory checked by the CSAF validators themselves, when installed:
/// gocsaf's `csaf_validator` (Apache-2.0; `CSAF_VALIDATOR`, the schema and
/// file name) and BSI's csaf-validator-lib (MIT; `CSAF_VALIDATOR_LIB`, the
/// directory it is installed in, run by `tests/csaf/validate.mjs`: the
/// mandatory and optional tests). `cargo test -p compliance-core --test
/// vex_schemas -- --ignored --nocapture`.
#[test]
#[ignore = "needs the CSAF validators"]
fn the_csaf_advisory_passes_the_csaf_validators() {
let (sbom, alerts) = (sbom(), csaf_alerts());
let doc = csaf_docs::csaf_vex(
&vex_input(&alerts, &sbom),
"https://example.invalid/pumps",
"de",
);
let dir = std::env::temp_dir().join(format!("csaf-{}", uuid::Uuid::new_v4()));
std::fs::create_dir_all(&dir).unwrap();
let id = doc["document"]["tracking"]["id"].as_str().unwrap();
let path = dir.join(csaf_docs::filename(id));
std::fs::write(&path, serde_json::to_vec_pretty(&doc).unwrap()).unwrap();
let mut ran = false;
if let Ok(validator) = std::env::var("CSAF_VALIDATOR") {
let out = std::process::Command::new(validator)
.arg(&path)
.output()
.unwrap();
let text = String::from_utf8_lossy(&out.stdout);
println!("csaf_validator: {text}");
// Exit 4: no remote validator configured; anything else is a failure.
assert!(matches!(out.status.code(), Some(0 | 4)), "{text}");
ran = true;
}
if let Ok(lib) = std::env::var("CSAF_VALIDATOR_LIB") {
let script =
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/csaf/validate.mjs");
let out = std::process::Command::new("node")
.arg(script)
.arg(&path)
.env("NODE_PATH", format!("{lib}/node_modules"))
.current_dir(&lib)
.output()
.unwrap();
let text = String::from_utf8_lossy(&out.stdout);
println!("csaf-validator-lib: {text}");
let result: serde_json::Value = serde_json::from_str(&text).unwrap();
assert_eq!(result["errors"], serde_json::json!([]), "{text}");
assert_eq!(result["isValid"], true);
ran = true;
}
std::fs::remove_dir_all(&dir).ok();
assert!(ran, "set CSAF_VALIDATOR and/or CSAF_VALIDATOR_LIB");
}
#[test]
fn a_fixed_component_that_left_the_sbom_keeps_its_stored_purl() {
// Arrange: log4j-core was updated to 2.17.1, so the SBOM no longer has
// 2.14.1; its alert kept the purl. An alert stored before purls were
// recorded has none.
let mut sbom = sbom();
sbom[0].version = "2.17.1".into();
sbom[0].purl = Some("pkg:maven/org.apache.logging.log4j/log4j-core@2.17.1".into());
let maven = "pkg:maven/org.apache.logging.log4j/log4j-core@2.14.1";
let mut log4j = alert("CVE-2021-44228", "log4j-core", "2.14.1");
log4j.purl = Some(maven.into());
log4j.resolved_at = Some(Utc::now());
let mut old = alert("CVE-2020-0001", "zlib", "1.2.11");
old.resolved_at = Some(Utc::now());
let alerts = vec![log4j, old];
let input = vex_input(&alerts, &sbom);
// Act
let openvex = vex_docs::openvex(&input);
let cdx = vex_docs::cyclonedx_vex(&input);
let csaf = csaf_docs::csaf_vex(&input, "https://example.invalid/pumps", "en");
// Assert: the stored purl, else the generic fallback, in every format.
assert_eq!(openvex_errors(&openvex), Vec::<String>::new());
assert_eq!(cyclonedx_errors(&cdx), Vec::<String>::new());
assert_eq!(csaf_errors(&csaf), Vec::<String>::new());
let generic = "pkg:generic/zlib@1.2.11";
for (i, purl) in [maven, generic].into_iter().enumerate() {
let statement = &openvex["statements"][i];
assert_eq!(statement["status"], "fixed");
let sub = &statement["products"][0]["subcomponents"][0];
assert_eq!(sub["@id"], purl);
assert_eq!(sub["identifiers"]["purl"], purl);
assert_eq!(cdx["vulnerabilities"][i]["affects"][0]["ref"], purl);
// The product tree's first entry is the target itself.
assert_eq!(
csaf["product_tree"]["full_product_names"][i + 1]["product_identification_helper"]
["purl"],
purl
);
}
}
#[test]
fn the_cve_is_the_vulnerability_id_and_the_github_advisory_an_alias() {
// Arrange: Log4Shell as a CVE alert on log4j-core and as a GitHub
// advisory aliasing it on log4j-api; a CVE-only alert; a GitHub advisory
// without a CVE.
let sbom = sbom();
let mut alerts = csaf_alerts();
alerts.push(alert("GHSA-xxxx-yyyy-zzzz", "lodash", "4.17.20"));
let input = vex_input(&alerts, &sbom);
// Act
let openvex = vex_docs::openvex(&input);
let cdx = vex_docs::cyclonedx_vex(&input);
let csaf = csaf_docs::csaf_vex(&input, "https://example.invalid/pumps", "en");
// Assert
assert_eq!(openvex_errors(&openvex), Vec::<String>::new());
assert_eq!(cyclonedx_errors(&cdx), Vec::<String>::new());
assert_eq!(csaf_errors(&csaf), Vec::<String>::new());
let statements = openvex["statements"].as_array().unwrap();
let vulns = cdx["vulnerabilities"].as_array().unwrap();
assert_eq!(statements.len(), 6);
assert_eq!(vulns.len(), 6);
// CVE only: the CVE, from NVD, nothing else.
assert_eq!(statements[0]["vulnerability"]["name"], "CVE-2021-44228");
assert!(statements[0]["vulnerability"].get("aliases").is_none());
assert_eq!(vulns[0]["id"], "CVE-2021-44228");
assert_eq!(vulns[0]["source"]["name"], "NVD");
assert!(vulns[0].get("references").is_none());
// CVE and GHSA: the CVE, the GHSA as alias and reference.
let ghsa = "GHSA-jfh8-c2jp-5v3q";
assert_eq!(statements[4]["vulnerability"]["name"], "CVE-2021-44228");
assert_eq!(
statements[4]["vulnerability"]["aliases"],
serde_json::json!([ghsa])
);
assert_eq!(vulns[4]["id"], "CVE-2021-44228");
assert_eq!(
vulns[4]["source"]["url"],
"https://nvd.nist.gov/vuln/detail/CVE-2021-44228"
);
assert_eq!(vulns[4]["references"][0]["id"], ghsa);
assert_eq!(
vulns[4]["references"][0]["source"]["name"],
"GitHub Security Advisories"
);
assert_eq!(csaf["vulnerabilities"][0]["cve"], "CVE-2021-44228");
assert_eq!(csaf["vulnerabilities"][0]["ids"][0]["text"], ghsa);
// GHSA only: its own id, as the scanner found it.
let only = "GHSA-xxxx-yyyy-zzzz";
assert_eq!(statements[5]["vulnerability"]["name"], only);
assert!(statements[5]["vulnerability"].get("aliases").is_none());
assert_eq!(vulns[5]["id"], only);
assert_eq!(vulns[5]["source"]["name"], "OSV");
assert!(vulns[5].get("references").is_none());
let csaf_only = &csaf["vulnerabilities"][4];
assert!(csaf_only.get("cve").is_none());
assert_eq!(csaf_only["ids"][0]["text"], only);
assert_eq!(
csaf_only["ids"][0]["system_name"],
"GitHub Security Advisories"
);
}
#[test]
fn a_cve_found_as_cve_and_as_github_advisory_in_one_component_is_one_statement() {
// Arrange: the GHSA alert of Log4Shell on the same log4j-core as the
// CVE alert, open; the CVE alert carries the statement.
let sbom = sbom();
let mut alerts = alerts();
let mut ghsa = alert("GHSA-jfh8-c2jp-5v3q", "log4j-core", "2.14.1");
ghsa.aliases = vec!["CVE-2021-44228".into()];
alerts.insert(0, ghsa);
let input = vex_input(&alerts, &sbom);
// Act
let openvex = vex_docs::openvex(&input);
let cdx = vex_docs::cyclonedx_vex(&input);
let csaf = csaf_docs::csaf_vex(&input, "https://example.invalid/pumps", "en");
// Assert: four statements, Log4Shell once with the stated status.
assert_eq!(openvex_errors(&openvex), Vec::<String>::new());
assert_eq!(cyclonedx_errors(&cdx), Vec::<String>::new());
assert_eq!(csaf_errors(&csaf), Vec::<String>::new());
let statements = openvex["statements"].as_array().unwrap();
assert_eq!(statements.len(), 4);
let log4shell: Vec<_> = statements
.iter()
.filter(|s| s["vulnerability"]["name"] == "CVE-2021-44228")
.collect();
assert_eq!(log4shell.len(), 1);
assert_eq!(log4shell[0]["status"], "affected");
assert_eq!(
log4shell[0]["vulnerability"]["aliases"],
serde_json::json!(["GHSA-jfh8-c2jp-5v3q"])
);
let vulns = cdx["vulnerabilities"].as_array().unwrap();
assert_eq!(vulns.len(), 4);
assert_eq!(vulns[0]["id"], "CVE-2021-44228");
assert_eq!(vulns[0]["analysis"]["state"], "exploitable");
let csaf_vulns = csaf["vulnerabilities"].as_array().unwrap();
assert_eq!(csaf_vulns.len(), 4);
assert_eq!(csaf_vulns[0]["cve"], "CVE-2021-44228");
assert!(csaf_vulns[0]["product_status"]
.get("under_investigation")
.is_none());
assert_eq!(
csaf_vulns[0]["product_status"]["known_affected"]
.as_array()
.unwrap()
.len(),
1
);
}
#[test]
fn the_cyclonedx_sbom_lists_a_vulnerability_under_its_cve_once() {
// Arrange: log4j-core's GHSA aliases the CVE NVD also found it under;
// lodash has a GHSA without a CVE.
let mut sbom = sbom();
sbom[0].known_vulnerabilities[0].aliases = vec!["CVE-2021-44228".into()];
sbom[0].known_vulnerabilities.push(VulnRef {
id: "CVE-2021-44228".into(),
source: "nvd".into(),
severity: None,
url: None,
exploitation: None,
aliases: Vec::new(),
});
sbom[1].known_vulnerabilities.push(VulnRef {
id: "GHSA-xxxx-yyyy-zzzz".into(),
source: "osv".into(),
severity: Some("MODERATE".into()),
url: None,
exploitation: None,
aliases: Vec::new(),
});
// Act
let doc = sbom_docs::cyclonedx(&sbom, "Pump Remote");
// Assert
assert_eq!(cyclonedx_errors(&doc), Vec::<String>::new());
let vulns = doc["vulnerabilities"].as_array().unwrap();
assert_eq!(vulns.len(), 2);
assert_eq!(vulns[0]["id"], "CVE-2021-44228");
assert_eq!(vulns[0]["source"]["name"], "NVD");
assert_eq!(vulns[0]["references"][0]["id"], "GHSA-jfh8-c2jp-5v3q");
assert_eq!(vulns[0]["affects"].as_array().unwrap().len(), 1);
assert_eq!(vulns[0]["ratings"][0]["severity"], "critical");
assert_eq!(vulns[1]["id"], "GHSA-xxxx-yyyy-zzzz");
assert_eq!(vulns[1]["source"]["name"], "osv");
assert!(vulns[1].get("references").is_none());
}