Skip to content

Commit 7473ae5

Browse files
committed
Add tests for spdx "relationshipType": "PACKAGE_OF"
Verify the relationship type shows up in `/api/v2/analysis/root-component` API calls. Part of issue #1140 Signed-off-by: Hiram Chirino <[email protected]>
1 parent e3af852 commit 7473ae5

File tree

1 file changed

+29
-1
lines changed
  • modules/analysis/src/endpoints

1 file changed

+29
-1
lines changed

modules/analysis/src/endpoints/test.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ async fn spdx_package_of(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
654654
let uri = format!("/api/v2/analysis/dep/{}", urlencoding::encode(purl));
655655
let request: Request = TestRequest::get().uri(&uri).to_request();
656656
let response: Value = app.call_and_read_body_json(request).await;
657-
log::debug!("{response:#?}");
657+
log::debug!("{}", serde_json::to_string_pretty(&response)?);
658658

659659
let sbom = &response["items"][0];
660660
let matches: Vec<_> = sbom["deps"]
@@ -677,6 +677,34 @@ async fn spdx_package_of(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
677677

678678
assert_eq!(1, matches.len());
679679

680+
let uri = format!(
681+
"/api/v2/analysis/root-component?q={}",
682+
urlencoding::encode("SATELLITE-6.15-RHEL-8")
683+
);
684+
let request: Request = TestRequest::get().uri(&uri).to_request();
685+
let response: Value = app.call_and_read_body_json(request).await;
686+
log::info!("{}", serde_json::to_string_pretty(&response)?);
687+
688+
let sbom = &response["items"][0];
689+
let matches: Vec<_> = sbom["ancestors"]
690+
.as_array()
691+
.into_iter()
692+
.flatten()
693+
.filter(|m| {
694+
m == &&json!({
695+
"sbom_id": sbom["sbom_id"],
696+
"node_id": m["node_id"],
697+
"relationship": "PackageOf",
698+
"purl": m["purl"], // long list assume it's correct
699+
"cpe": m["cpe"], // long list assume it's correct
700+
"name": "rubygem-google-cloud-compute",
701+
"version": "0.5.0-1.el8sat"
702+
})
703+
})
704+
.collect();
705+
706+
assert_eq!(1, matches.len());
707+
680708
Ok(())
681709
}
682710

0 commit comments

Comments
 (0)