Skip to content

Commit

Permalink
fix: ensure sbom's and adv's can be filtered/sorted by ingested date
Browse files Browse the repository at this point in the history
Fixes: #1077

Signed-off-by: Jim Crossley <[email protected]>
  • Loading branch information
jcrossley3 authored and ctron committed Dec 10, 2024
1 parent 606f596 commit b920d63
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion common/src/db/query/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl TryFrom<(&str, Operator, &Vec<String>, &Columns)> for Filter {
Some(x) => q(&x).filter_for(columns),
None => columns.for_field(field).and_then(|(expr, col_def)| {
Arg::parse(s, col_def.get_column_type()).map(|v| Filter {
operands: Operand::Simple(expr.clone(), v),
operands: Operand::Simple(expr, v),
operator,
})
}),
Expand Down
10 changes: 9 additions & 1 deletion modules/fundamental/src/advisory/endpoints/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,11 @@ async fn one_advisory_by_uuid(ctx: &TrustifyContext) -> Result<(), anyhow::Error
#[test(actix_web::test)]
async fn search_advisories(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
async fn query(app: &impl CallService, q: &str) -> PaginatedResults<AdvisorySummary> {
let uri = format!("/api/v1/advisory?q={}", urlencoding::encode(q));
let uri = format!(
"/api/v1/advisory?q={}&sort={}",
urlencoding::encode(q),
urlencoding::encode("ingested:desc")
);
let req = TestRequest::get().uri(&uri).to_request();
app.call_and_read_body_json(req).await
}
Expand All @@ -317,6 +321,10 @@ async fn search_advisories(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {

let result = query(&app, "").await;
assert_eq!(result.total, 2);
assert_eq!(result.items[0].head.identifier, "CVE-2024-28111");
let result = query(&app, "ingested>last week").await;
assert_eq!(result.total, 2);
assert_eq!(result.items[0].head.identifier, "CVE-2024-28111");
let result = query(&app, "csv").await;
assert_eq!(result.total, 1);
assert_eq!(result.items[0].head.identifier, "CVE-2024-28111");
Expand Down
1 change: 1 addition & 0 deletions modules/fundamental/src/advisory/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl AdvisoryService {
.filtering_with(
search,
Columns::from_entity::<advisory::Entity>()
.add_columns(source_document::Entity)
.add_column("average_score", ColumnType::Decimal(None).def())
.add_column(
"average_severity",
Expand Down
8 changes: 7 additions & 1 deletion modules/fundamental/src/sbom/endpoints/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ async fn get_advisories(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
#[test(actix_web::test)]
async fn query_sboms_by_ingested_time(ctx: &TrustifyContext) -> Result<(), anyhow::Error> {
async fn query(app: &impl CallService, q: &str) -> Value {
let uri = format!("/api/v1/sbom?q={}", urlencoding::encode(q));
let uri = format!(
"/api/v1/sbom?q={}&sort={}",
urlencoding::encode(q),
urlencoding::encode("ingested:desc")
);
let req = TestRequest::get().uri(&uri).to_request();
app.call_and_read_body_json(req).await
}
Expand All @@ -257,6 +261,8 @@ async fn query_sboms_by_ingested_time(ctx: &TrustifyContext) -> Result<(), anyho

// assert expected fields
assert_eq!(all["total"], 2);
assert_eq!(all["items"][0]["name"], json!("zookeeper"));
assert_eq!(all["items"][1]["name"], json!("ubi9-container"));
assert_eq!(ubi["total"], 1);
assert_eq!(ubi["items"][0]["name"], json!("ubi9-container"));
assert_eq!(zoo["total"], 1);
Expand Down

0 comments on commit b920d63

Please sign in to comment.