Skip to content
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
24 changes: 15 additions & 9 deletions modules/exploit-intelligence/src/endpoints/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ use actix_web::{
web,
};
use sea_orm::{ActiveModelTrait, Set, TransactionTrait};
use serde_json::Value;
use test_context::test_context;
use test_log::test;
use time::OffsetDateTime;
use time::{OffsetDateTime, format_description::well_known::Rfc3339};
use trustify_common::{db, error::ErrorInformation, model::PaginatedResults};
use trustify_entity::{
exploit_intelligence_job::{self, ExploitIntelligenceFinding, ExploitIntelligenceJobStatus},
Expand Down Expand Up @@ -149,15 +150,20 @@ async fn get_job_completed(ctx: &TrustifyContext) -> anyhow::Result<()> {

// Then the response contains the completed job details
assert_eq!(resp.status(), 200);
let body: ExploitIntelligenceJobDetails = test::read_body_json(resp).await;
assert_eq!(body.id, job_id);
assert_eq!(body.status, ExploitIntelligenceJobStatus::Completed);
assert_eq!(body.vulnerability_id, "CVE-2024-1234");
assert_eq!(
body.finding,
Some(ExploitIntelligenceFinding::NotVulnerable)
let body: Value = test::read_body_json(resp).await;
assert_eq!(body["id"], job_id.to_string());
assert_eq!(body["status"], "completed");
assert_eq!(body["vulnerability_id"], "CVE-2024-1234");
assert_eq!(body["finding"], "not_vulnerable");
assert!(
OffsetDateTime::parse(body["created"].as_str().unwrap(), &Rfc3339).is_ok(),
"created should be valid RFC3339"
);
assert!(
OffsetDateTime::parse(body["updated"].as_str().unwrap(), &Rfc3339).is_ok(),
"created should be valid RFC3339"
);
assert_eq!(body.total_components, Some(1));
assert_eq!(body["total_components"], 1);

Ok(())
}
Expand Down
6 changes: 6 additions & 0 deletions modules/exploit-intelligence/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ pub struct ExploitIntelligenceJobSummary {
/// Number of completed components with Uncertain finding (computed at query time).
pub uncertain_components: Option<i32>,
/// Timestamp when the job was created.
#[serde(with = "time::serde::rfc3339")]
#[schema(value_type = String)]
pub created: OffsetDateTime,
/// Timestamp when the job was last updated.
#[serde(with = "time::serde::rfc3339")]
#[schema(value_type = String)]
pub updated: OffsetDateTime,
}
Expand Down Expand Up @@ -98,9 +100,11 @@ pub struct ExploitIntelligenceJobDetails {
/// Per-component analysis results (populated for multi-component jobs).
pub components: Vec<ComponentResult>,
/// Timestamp when the job was created.
#[serde(with = "time::serde::rfc3339")]
#[schema(value_type = String)]
pub created: OffsetDateTime,
/// Timestamp when the job was last updated.
#[serde(with = "time::serde::rfc3339")]
#[schema(value_type = String)]
pub updated: OffsetDateTime,
}
Expand Down Expand Up @@ -169,9 +173,11 @@ pub struct ComponentResult {
/// unsupported ecosystem) rather than genuinely failing.
pub excluded: bool,
/// Timestamp when the component record was created.
#[serde(with = "time::serde::rfc3339")]
#[schema(value_type = String)]
pub created: OffsetDateTime,
/// Timestamp when the component record was last updated.
#[serde(with = "time::serde::rfc3339")]
#[schema(value_type = String)]
pub updated: OffsetDateTime,
}
Expand Down
Loading