-
Notifications
You must be signed in to change notification settings - Fork 35
Add tests for spdx "relationshipType": "PACKAGE_OF" #1186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -654,7 +654,7 @@ async fn spdx_package_of(ctx: &TrustifyContext) -> Result<(), anyhow::Error> { | |||||||||||||||||||||||||||
| let uri = format!("/api/v2/analysis/dep/{}", urlencoding::encode(purl)); | ||||||||||||||||||||||||||||
| let request: Request = TestRequest::get().uri(&uri).to_request(); | ||||||||||||||||||||||||||||
| let response: Value = app.call_and_read_body_json(request).await; | ||||||||||||||||||||||||||||
| log::debug!("{response:#?}"); | ||||||||||||||||||||||||||||
| log::debug!("{}", serde_json::to_string_pretty(&response)?); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| let sbom = &response["items"][0]; | ||||||||||||||||||||||||||||
| let matches: Vec<_> = sbom["deps"] | ||||||||||||||||||||||||||||
|
|
@@ -677,5 +677,33 @@ async fn spdx_package_of(ctx: &TrustifyContext) -> Result<(), anyhow::Error> { | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| assert_eq!(1, matches.len()); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| let uri = format!( | ||||||||||||||||||||||||||||
| "/api/v2/analysis/root-component?q={}", | ||||||||||||||||||||||||||||
| urlencoding::encode("SATELLITE-6.15-RHEL-8") | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| let request: Request = TestRequest::get().uri(&uri).to_request(); | ||||||||||||||||||||||||||||
| let response: Value = app.call_and_read_body_json(request).await; | ||||||||||||||||||||||||||||
| log::info!("{}", serde_json::to_string_pretty(&response)?); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| let sbom = &response["items"][0]; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| let matches: Vec<_> = sbom["ancestors"] | ||||||||||||||||||||||||||||
| .as_array() | ||||||||||||||||||||||||||||
| .into_iter() | ||||||||||||||||||||||||||||
| .flatten() | ||||||||||||||||||||||||||||
| .filter(|m| { | ||||||||||||||||||||||||||||
| m == &&json!({ | ||||||||||||||||||||||||||||
| "sbom_id": sbom["sbom_id"], | ||||||||||||||||||||||||||||
| "node_id": m["node_id"], | ||||||||||||||||||||||||||||
| "relationship": "PackageOf", | ||||||||||||||||||||||||||||
| "purl": m["purl"], // long list assume it's correct | ||||||||||||||||||||||||||||
| "cpe": m["cpe"], // long list assume it's correct | ||||||||||||||||||||||||||||
| "name": "rubygem-google-cloud-compute", | ||||||||||||||||||||||||||||
| "version": "0.5.0-1.el8sat" | ||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| m == &&json!({ | |
| "sbom_id": sbom["sbom_id"], | |
| "node_id": m["node_id"], | |
| "relationship": "PackageOf", | |
| "purl": m["purl"], // long list assume it's correct | |
| "cpe": m["cpe"], // long list assume it's correct | |
| "name": "rubygem-google-cloud-compute", | |
| "version": "0.5.0-1.el8sat" | |
| }) | |
| m["sbom_id"] == sbom["sbom_id"] | |
| && m["relationship"] == "PackageOf" | |
| && m["name"] == "rubygem-google-cloud-compute" | |
| && m["version"] == "0.5.0-1.el8sat" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kinda was thinking about similar lines. Is there an existing function that can test if an actual Value matches a partial set of fields of another expected Value? The assertion would become more concise and less brittle then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that I know of. You can always downcast the Value to an AncestorSummary or DepSummary, but I'm not sure m["name"] is all that better or worse than m.name.
Another option is to use Value::pointer, but I haven't personally tried that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really wish serde's impl of
:#?usedto_string_pretty. I can remember the former, but never the latter. :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100%