@@ -13,7 +13,9 @@ use trustify_common::{id::Id, model::PaginatedResults};
1313use trustify_entity:: labels:: Labels ;
1414use trustify_module_ingestor:: model:: IngestResult ;
1515use trustify_test_context:: { TrustifyContext , call:: CallService , document_bytes} ;
16+ use urlencoding:: encode;
1617use uuid:: Uuid ;
18+
1719#[ test_context( TrustifyContext ) ]
1820#[ test( actix_web:: test) ]
1921async fn license_export ( ctx : & TrustifyContext ) -> Result < ( ) , anyhow:: Error > {
@@ -303,3 +305,39 @@ async fn query_sboms_by_ingested_time(ctx: &TrustifyContext) -> Result<(), anyho
303305
304306 Ok ( ( ) )
305307}
308+
309+ #[ test_context( TrustifyContext ) ]
310+ #[ test( actix_web:: test) ]
311+ async fn query_sboms_by_package ( ctx : & TrustifyContext ) -> Result < ( ) , anyhow:: Error > {
312+ let query = async |purl, sort| {
313+ let app = caller ( ctx) . await . unwrap ( ) ;
314+ let uri = format ! (
315+ "/api/v2/sbom/by-package?purl={}&sort={}" ,
316+ encode( purl) ,
317+ encode( sort)
318+ ) ;
319+ let request = TestRequest :: get ( ) . uri ( & uri) . to_request ( ) ;
320+ let response: Value = app. call_and_read_body_json ( request) . await ;
321+ tracing:: debug!( test = "" , "{response:#?}" ) ;
322+ response
323+ } ;
324+
325+ // Ingest 2 SBOM's that depend on the same purl
326+ ctx. ingest_documents ( [ "spdx/simple-ext-a.json" , "spdx/simple-ext-b.json" ] )
327+ . await ?;
328+
329+ assert_eq ! (
330+ 2 ,
331+ query
( "pkg:rpm/redhat/[email protected] ?arch=src" , "" ) . await [ "total" ] 332+ ) ;
333+ assert_eq ! (
334+ "simple-a" ,
335+ query
( "pkg:rpm/redhat/[email protected] ?arch=src" , "name:asc" ) . await [ "items" ] [ 0 ] [ "name" ] 336+ ) ;
337+ assert_eq ! (
338+ "simple-b" ,
339+ query
( "pkg:rpm/redhat/[email protected] ?arch=src" , "name:desc" ) . await [ "items" ] [ 0 ] [ "name" ] 340+ ) ;
341+
342+ Ok ( ( ) )
343+ }
0 commit comments