Skip to content
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

Revert purl endpoint relationship exposure and rename tests #1177

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions modules/analysis/src/endpoints/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ where

#[test_context(TrustifyContext)]
#[test(actix_web::test)]
async fn issue_tc_2050(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
async fn cdx_generated_from(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
let app = caller(ctx).await?;
ctx.ingest_documents(["cyclonedx/openssl-3.0.7-18.el9_2.cdx_1.6.sbom.json"])
.await?;
Expand Down Expand Up @@ -457,7 +457,7 @@ async fn issue_tc_2050(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {

#[test_context(TrustifyContext)]
#[test(actix_web::test)]
async fn issue_tc_2051(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
async fn spdx_generated_from(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
let app = caller(ctx).await?;
ctx.ingest_documents(["spdx/openssl-3.0.7-18.el9_2.spdx.json"])
.await?;
Expand Down Expand Up @@ -495,7 +495,7 @@ async fn issue_tc_2051(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {

#[test_context(TrustifyContext)]
#[test(actix_web::test)]
async fn issue_tc_2052(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
async fn cdx_variant_of(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
let app = caller(ctx).await?;
ctx.ingest_documents(["cyclonedx/66FF73123BB3489.json"])
.await?;
Expand Down Expand Up @@ -533,7 +533,7 @@ async fn issue_tc_2052(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {

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

#[test_context(TrustifyContext)]
#[test(actix_web::test)]
async fn issue_tc_2054(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
async fn cdx_ancestor_of(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
let app = caller(ctx).await?;
ctx.ingest_documents(["cyclonedx/openssl-3.0.7-18.el9_2.cdx_1.6.sbom.json"])
.await?;
Expand Down
20 changes: 0 additions & 20 deletions modules/fundamental/src/purl/endpoints/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,23 +346,3 @@ async fn package_with_status(ctx: &TrustifyContext) -> Result<(), anyhow::Error>

Ok(())
}

#[test_context(TrustifyContext)]
#[test(actix_web::test)]
async fn purl_relationships(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
let app = caller(ctx).await?;
ctx.ingest_documents(["cyclonedx/openssl-3.0.7-18.el9_2.cdx_1.6.sbom.json"])
.await?;

let src = "pkg:rpm/redhat/[email protected]_2?arch=src";
let bin = "pkg:rpm/redhat/[email protected]_2?arch=x86_64";

let uri = format!("/api/v2/purl/{}", urlencoding::encode(bin));
let request = TestRequest::get().uri(&uri).to_request();
let response: Value = app.call_and_read_body_json(request).await;
log::debug!("{response:#?}");

assert_eq!(src, response["relationships"]["generated_from"][0]);

Ok(())
}
24 changes: 4 additions & 20 deletions modules/fundamental/src/purl/model/details/purl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ use trustify_common::{
};
use trustify_cvss::cvss3::{score::Score, severity::Severity, Cvss3Base};
use trustify_entity::{
advisory, base_purl, cpe, cvss3, license, organization, package_relates_to_package, product,
product_status, product_version, product_version_range, purl_license_assertion, purl_status,
qualified_purl, relationship::Relationship, sbom, sbom_package, sbom_package_purl_ref, status,
version_range, versioned_purl, vulnerability,
advisory, base_purl, cpe, cvss3, license, organization, product, product_status,
product_version, product_version_range, purl_license_assertion, purl_status, qualified_purl,
sbom, sbom_package, sbom_package_purl_ref, status, version_range, versioned_purl,
vulnerability,
};
use trustify_module_ingestor::common::{Deprecation, DeprecationForExt};
use utoipa::ToSchema;
Expand All @@ -38,7 +38,6 @@ pub struct PurlDetails {
pub base: BasePurlHead,
pub advisories: Vec<PurlAdvisory>,
pub licenses: Vec<PurlLicenseSummary>,
pub relationships: HashMap<Relationship, Vec<String>>,
}

impl PurlDetails {
Expand Down Expand Up @@ -115,27 +114,12 @@ impl PurlDetails {
.all(tx)
.await?;

let relationships: HashMap<Relationship, Vec<_>> =
package_relates_to_package::Entity::find()
.filter(
package_relates_to_package::Column::LeftNodeId
.eq(qualified_package.purl.to_string()),
)
.all(tx)
.await?
.into_iter()
.fold(HashMap::new(), |mut h, m| {
h.entry(m.relationship).or_default().push(m.right_node_id);
h
});

Ok(PurlDetails {
head: PurlHead::from_entity(&package, &package_version, qualified_package, tx).await?,
version: VersionedPurlHead::from_entity(&package, &package_version, tx).await?,
base: BasePurlHead::from_entity(&package).await?,
advisories: PurlAdvisory::from_entities(purl_statuses, product_statuses, tx).await?,
licenses: PurlLicenseSummary::from_entities(&licenses, tx).await?,
relationships,
})
}
}
Expand Down
26 changes: 0 additions & 26 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3607,7 +3607,6 @@ components:
- base
- advisories
- licenses
- relationships
properties:
advisories:
type: array
Expand All @@ -3619,31 +3618,6 @@ components:
type: array
items:
$ref: '#/components/schemas/PurlLicenseSummary'
relationships:
type: object
additionalProperties:
type: array
items:
type: string
propertyNames:
type: string
enum:
- contained_by
- dependency_of
- dev_dependency_of
- optional_dependency_of
- provided_dependency_of
- test_dependency_of
- runtime_dependency_of
- example_of
- generated_from
- ancestor_of
- variant_of
- build_tool_of
- dev_tool_of
- described_by
- package_of
- undefined
version:
$ref: '#/components/schemas/VersionedPurlHead'
PurlHead:
Expand Down
Loading