Skip to content

Commit

Permalink
Add unit test affirming TC-2053
Browse files Browse the repository at this point in the history
See https://issues.redhat.com/browse/TC-2053

This doesn't include relationships in the response of /api/v2/purl as
there's a pending request to remove that requirement.

Signed-off-by: Jim Crossley <[email protected]>
  • Loading branch information
jcrossley3 committed Jan 21, 2025
1 parent a532dd8 commit 009295b
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions modules/analysis/src/endpoints/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,57 @@ async fn issue_tc_2052(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
Ok(())
}

#[test_context(TrustifyContext)]
#[test(actix_web::test)]
async fn issue_tc_2053(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
let app = caller(ctx).await?;
ctx.ingest_documents(["ubi9-9.2-755.1697625012.json"])
.await?;

// Find all deps of "parent" package
let parent = "pkg:oci/ubi9-container@sha256:2f168398c538b287fd705519b83cd5b604dc277ef3d9f479c28a2adb4d830a49?repository_url=registry.redhat.io/ubi9&tag=9.2-755.1697625012";
let uri = format!("/api/v2/analysis/dep/{}", urlencoding::encode(parent));
let request: Request = TestRequest::get().uri(&uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;
log::debug!("{response:#?}");
assert_eq!(
4,
response["items"][0]["deps"]
.as_array()
.into_iter()
.flatten()
.filter(|m| m["relationship"] == "VariantOf")
.count()
);

// Ensure VariantOf relationships
let purls = [
"pkg:oci/ubi9-container@sha256:d4c5d9c980678267b81c3c197a4a0dd206382111c912875a6cdffc6ca319b769?arch=aarch64&repository_url=registry.redhat.io/ubi9&tag=9.2-755.1697625012",
"pkg:oci/ubi9-container@sha256:204383c3d96c0e6c7154c91d07764f92035738dd67aa8896679f7feb73f66bfd?arch=x86_64&repository_url=registry.redhat.io/ubi9&tag=9.2-755.1697625012",
"pkg:oci/ubi9-container@sha256:721ca837c80c8b98752010a17ffccbdf17a0d260ddd916b7097f04187f6aa3a8?arch=s390x&repository_url=registry.redhat.io/ubi9&tag=9.2-755.1697625012",
"pkg:oci/ubi9-container@sha256:9a6092cdd8e7f4361ea3f508ae6d6d3d9dbb9458a921ab09e4cc006c0a7f0a61?arch=ppc64le&repository_url=registry.redhat.io/ubi9&tag=9.2-755.1697625012",
];
for purl in purls {
let uri = format!(
"/api/v2/analysis/root-component/{}",
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:#?}");
assert_eq!(
"VariantOf",
response["items"][0]["ancestors"][0]["relationship"]
);
assert_eq!(
Value::from(vec![Value::from(parent)]),
response["items"][0]["ancestors"][0]["purl"]
);
}

Ok(())
}

#[test_context(TrustifyContext)]
#[test(actix_web::test)]
async fn issue_tc_2054(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
Expand Down

0 comments on commit 009295b

Please sign in to comment.