@@ -540,6 +540,58 @@ async fn vulnerability_queries(ctx: &TrustifyContext) -> Result<(), anyhow::Erro
540540 Ok ( ( ) )
541541}
542542
543+ #[ test_context( TrustifyContext ) ]
544+ #[ test( tokio:: test) ]
545+ async fn vulnerability_numeric_sorting ( ctx : & TrustifyContext ) -> Result < ( ) , anyhow:: Error > {
546+ let service = VulnerabilityService :: new ( ) ;
547+
548+ ctx. graph . ingest_vulnerability ( "CVE-2024-40000" , ( ) , & ctx. db ) . await ?;
549+ ctx. graph . ingest_vulnerability ( "CVE-2024-10288000" , ( ) , & ctx. db ) . await ?;
550+ ctx. graph . ingest_vulnerability ( "CVE-2023-1234" , ( ) , & ctx. db ) . await ?;
551+ ctx. graph . ingest_vulnerability ( "CVE-2024-9000" , ( ) , & ctx. db ) . await ?;
552+ ctx. graph . ingest_vulnerability ( "CVE-2023-5100" , ( ) , & ctx. db ) . await ?;
553+ ctx. graph . ingest_vulnerability ( "GHSA-xxxx-yyyy-zzzz" , ( ) , & ctx. db ) . await ?;
554+ ctx. graph . ingest_vulnerability ( "ABC-xxxx-yyyy" , ( ) , & ctx. db ) . await ?;
555+
556+ // Test ascending sort
557+ let vulns = service
558+ . fetch_vulnerabilities (
559+ q ( "" ) . sort ( "id:asc" ) ,
560+ Paginated :: default ( ) ,
561+ Default :: default ( ) ,
562+ & ctx. db ,
563+ )
564+ . await ?;
565+ assert_eq ! ( 7 , vulns. items. len( ) ) ;
566+ assert_eq ! ( vulns. items[ 0 ] . head. identifier, "ABC-xxxx-yyyy" ) ;
567+ assert_eq ! ( vulns. items[ 1 ] . head. identifier, "CVE-2023-1234" ) ;
568+ assert_eq ! ( vulns. items[ 2 ] . head. identifier, "CVE-2023-5100" ) ;
569+ assert_eq ! ( vulns. items[ 3 ] . head. identifier, "CVE-2024-9000" ) ;
570+ assert_eq ! ( vulns. items[ 4 ] . head. identifier, "CVE-2024-40000" ) ;
571+ assert_eq ! ( vulns. items[ 5 ] . head. identifier, "CVE-2024-10288000" ) ;
572+ assert_eq ! ( vulns. items[ 6 ] . head. identifier, "GHSA-xxxx-yyyy-zzzz" ) ;
573+
574+ // Test descending sort
575+ let vulns = service
576+ . fetch_vulnerabilities (
577+ q ( "" ) . sort ( "id:desc" ) ,
578+ Paginated :: default ( ) ,
579+ Default :: default ( ) ,
580+ & ctx. db ,
581+ )
582+ . await ?;
583+ assert_eq ! ( 7 , vulns. items. len( ) ) ;
584+ assert_eq ! ( vulns. items[ 0 ] . head. identifier, "GHSA-xxxx-yyyy-zzzz" ) ;
585+ assert_eq ! ( vulns. items[ 1 ] . head. identifier, "CVE-2024-10288000" ) ;
586+ assert_eq ! ( vulns. items[ 2 ] . head. identifier, "CVE-2024-40000" ) ;
587+ assert_eq ! ( vulns. items[ 3 ] . head. identifier, "CVE-2024-9000" ) ;
588+ assert_eq ! ( vulns. items[ 4 ] . head. identifier, "CVE-2023-5100" ) ;
589+ assert_eq ! ( vulns. items[ 5 ] . head. identifier, "CVE-2023-1234" ) ;
590+ assert_eq ! ( vulns. items[ 6 ] . head. identifier, "ABC-xxxx-yyyy" ) ;
591+
592+ Ok ( ( ) )
593+ }
594+
543595#[ test_context( TrustifyContext ) ]
544596#[ test( tokio:: test) ]
545597async fn analyze_purls ( ctx : & TrustifyContext ) -> Result < ( ) , anyhow:: Error > {
0 commit comments