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
11 changes: 7 additions & 4 deletions crates/gvm-gateway-app/src/lib_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,10 +1301,13 @@ impl ReportPort for MissingReportPort {
fn test_report(id: &str) -> Report {
Report {
id: id.to_string(),
task: Some(ResourceRef {
id: "223e4567-e89b-12d3-a456-426614174000".to_string(),
name: Some("Task".to_string()),
}),
task: Some(
ResourceRef {
id: "223e4567-e89b-12d3-a456-426614174000".to_string(),
name: Some("Task".to_string()),
}
.into(),
),
scan_start: None,
scan_end: None,
severity: Some(0.0),
Expand Down
3 changes: 2 additions & 1 deletion crates/gvm-gateway-domain/src/lib_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,10 @@ fn target_serializes_exclude_hosts_only_when_nonempty() {
fn report_serializes_camel_case() {
let report = Report {
id: "550e8400-e29b-41d4-a716-446655440000".to_string(),
task: Some(ResourceRef {
task: Some(ReportTaskRef {
id: "task-1".to_string(),
name: Some("Scan".to_string()),
scan_config: None,
}),
scan_start: Some("2026-01-01T00:00:00Z".to_string()),
scan_end: None,
Expand Down
25 changes: 24 additions & 1 deletion crates/gvm-gateway-domain/src/reports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,37 @@ pub struct ReportCvePage {
pub pagination: Pagination,
}

/// Task snapshot reference specific to report representations.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct ReportTaskRef {
/// Report task identifier.
pub id: String,
/// Report task name.
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
/// Configuration recorded by the report, never the current task configuration.
#[serde(rename = "scanConfig", skip_serializing_if = "Option::is_none")]
pub scan_config: Option<ResourceRef>,
}

impl From<ResourceRef> for ReportTaskRef {
fn from(task: ResourceRef) -> Self {
Self {
id: task.id,
name: task.name,
scan_config: None,
}
}
}

/// Domain report representation.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Report {
/// Report identifier.
pub id: String,
/// Associated task reference.
#[serde(skip_serializing_if = "Option::is_none")]
pub task: Option<ResourceRef>,
pub task: Option<ReportTaskRef>,
/// Scan start timestamp.
#[serde(rename = "scanStart", skip_serializing_if = "Option::is_none")]
pub scan_start: Option<String>,
Expand Down
16 changes: 15 additions & 1 deletion crates/gvm-gateway-gvmd/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,10 @@ pub(crate) fn report_from_gmp(report: gvm_gmp::responses::Report) -> Report {

Report {
id: report.meta.id.to_string(),
task: report.task.map(resource_ref_from_named_entity),
task: report
.task
.map(resource_ref_from_named_entity)
.map(Into::into),
scan_start: report.scan_start,
scan_end: report.scan_end,
severity,
Expand Down Expand Up @@ -1278,3 +1281,14 @@ fn map_parser_server_error(
#[cfg(test)]
#[path = "conversions_test.rs"]
mod conversions_test;

/// Convert only the historical task embedded in the structured report.
pub(crate) fn report_task_from_snapshot(
task: gvm_gmp::responses::StructuredReportTask,
) -> Option<gvm_gateway_domain::ReportTaskRef> {
task.id.map(|id| gvm_gateway_domain::ReportTaskRef {
id: id.to_string(),
name: (!task.name.is_empty()).then_some(task.name),
scan_config: task.scan_config.map(resource_ref_from_named_entity),
})
}
38 changes: 38 additions & 0 deletions crates/gvm-gateway-gvmd/src/conversions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,44 @@ fn typed_result_and_nested_reference_types_remain_open_and_optional() {
.is_none());
}

// Intent: historical config identity/name must come from a typed report snapshot, not current task state.
#[test]
fn snapshot_config_preserves_identity_name_and_absence() {
for (config, expected) in [
(
r#"<scan_config id="11111111-1111-1111-1111-111111111111"><name>Old &amp; frozen</name></scan_config>"#,
true,
),
("", false),
] {
let xml = format!(
r#"<get_scan_report_response status="200" status_text="OK"><report id="22222222-2222-2222-2222-222222222222"><name>Report</name><task id="33333333-3333-3333-3333-333333333333"><name>Task</name>{config}</task></report></get_scan_report_response>"#
);
let parsed = gvm_gmp::responses::GetScanReportResponse::from_response(&GmpResponse::from(
xml.as_str(),
))
.unwrap();
let task = report_task_from_snapshot(parsed.report.task.unwrap()).unwrap();
assert_eq!(task.scan_config.is_some(), expected);
if let Some(config) = task.scan_config {
assert_eq!(config.id, "11111111-1111-1111-1111-111111111111");
assert_eq!(config.name.as_deref(), Some("Old & frozen"));
}
}
}

#[test]
fn snapshot_task_omits_unavailable_name_like_generic_report_task() {
// Intent (#736): snapshot enrichment must retain the generic reference's
// optional-name convention when gvmd does not provide a task name.
let parsed = gvm_gmp::responses::GetScanReportResponse::from_response(&GmpResponse::from(
r#"<get_scan_report_response status="200" status_text="OK"><report id="22222222-2222-2222-2222-222222222222"><name>Report</name><task id="33333333-3333-3333-3333-333333333333"/></report></get_scan_report_response>"#,
)).unwrap();
let task = report_task_from_snapshot(parsed.report.task.unwrap()).unwrap();
assert!(task.name.is_none());
assert!(task.scan_config.is_none());
}

#[test]
fn typed_agent_and_group_delay_observations_preserve_full_u32_range() {
// Exercise the real typed-to-domain projections independently of write builders:
Expand Down
24 changes: 24 additions & 0 deletions crates/gvm-gateway-gvmd/src/gvmd_adapter/ports/reports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,30 @@ impl ReportPort for GvmdAdapter {
.map(report_from_gmp)
.ok_or_else(|| GatewayError::NotFound(format!("report {id} not found")))?;

// Read the report snapshot through the typed structured source. Never fetch
// today's task/configuration to stand in for historical metadata.
let snapshot = self
.execute_with_session(
session_token,
"reports.snapshot",
gvm_gmp::commands::reports::GetScanReportRequest::new(parse_entity_id(id)?),
)
.await;
match snapshot {
Ok(snapshot) => {
report.task = snapshot
.report
.task
.and_then(crate::conversions::report_task_from_snapshot)
.or(report.task);
}
// This additive metadata must not make older report reads fail.
// The typed capability check rejects unsupported commands before
// transport. Do not suppress permission, parse or backend errors.
Err(GatewayError::NotImplemented(_)) => {}
Err(error) => return Err(error),
}

// Fetch the explicitly requested embedded-result window for this report.
let filter = paginated_filter(
Some(&format!("report_id={id}")),
Expand Down
86 changes: 86 additions & 0 deletions crates/gvm-gateway-gvmd/tests/gvmd_adapter_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6150,6 +6150,92 @@ async fn ad_verification_uses_discovery_and_status_only_fixture_without_persiste
server.shutdown().await;
}

#[tokio::test]
async fn report_snapshot_metadata_is_additive_on_older_backends() {
// Intent (#736): a typed unsupported snapshot command on GMP 22.7 must
// not break existing report reads or invent scanConfig via today's task.
let report_id = uuid::Uuid::new_v4();
let task_id = uuid::Uuid::new_v4();
let server = MockGmpServer::builder()
.mode(ServerMode::Stateful)
.version(MockVersion::V22_7)
.seed(move |store| {
store.create(Resource::with_id("task", "Existing task", task_id));
let mut report = Resource::with_id("report", "Older report", report_id);
report.set_attr("usage_type", "scan");
report.set_attr("task_id", &task_id.to_string());
store.create(report);
})
.unix_socket_auto()
.build()
.await
.unwrap();
let adapter = GvmdAdapter::unix_socket(server.socket_path().unwrap());
adapter
.connect_session("token", "admin", "admin")
.await
.unwrap();
server.clear_history();
let report = adapter
.get_report("token", &report_id.to_string(), &GetReportOpts::default())
.await
.expect("optional metadata must not raise the existing read version floor");
let task = report.task.expect("generic report task remains present");
assert_eq!(task.id, task_id.to_string());
assert!(task.scan_config.is_none());
let history = server.command_history();
assert!(history
.iter()
.any(|entry| entry.command_name() == "get_reports"));
assert!(history.iter().all(|entry| !matches!(
entry.command_name(),
"get_scan_report" | "get_tasks" | "get_configs" | "get_scan_configs"
)));
server.shutdown().await;
}

#[tokio::test]
async fn report_snapshot_backend_failure_is_not_optional_absence() {
// Intent (#736): only unsupported optional capability may be omitted;
// a failed real snapshot read must not become a successful stale report.
let report_id = uuid::Uuid::new_v4();
let server = MockGmpServer::builder()
.mode(ServerMode::Stateful)
.version(MockVersion::V22_8)
.seed(move |store| {
let mut report = Resource::with_id("report", "Faulted snapshot", report_id);
report.set_attr("usage_type", "scan");
store.create(report);
})
.inject_fault(Fault::on_command(
"get_scan_report",
FaultKind::ErrorStatus {
code: 503,
message: "snapshot unavailable".into(),
},
))
.unix_socket_auto()
.build()
.await
.unwrap();
let adapter = GvmdAdapter::unix_socket(server.socket_path().unwrap());
adapter
.connect_session("token", "admin", "admin")
.await
.unwrap();
server.clear_history();
let error = adapter
.get_report("token", &report_id.to_string(), &GetReportOpts::default())
.await
.expect_err("real snapshot errors must propagate");
assert!(matches!(error, GatewayError::BackendUnavailable(_)));
assert!(server
.command_history()
.iter()
.all(|entry| entry.command_name() != "get_results"));
server.shutdown().await;
}

#[tokio::test]
async fn inventory_token_empty_success_is_typed_backend_failure_without_secret_diagnostics() {
// The owning parser, not the adapter, validates nonempty opaque credentials.
Expand Down
25 changes: 23 additions & 2 deletions crates/gvm-gateway-rest/src/reports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,34 @@ impl From<gvm_gateway_domain::ResultCount> for ResultCountResponse {
}
}

/// Task reference from a report snapshot, distinct from generic task references.
#[derive(Clone, Debug, Serialize, JsonSchema)]
#[schemars(rename = "ReportTaskRef")]
pub(crate) struct ReportTaskRefResponse {
id: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(rename = "scanConfig", skip_serializing_if = "Option::is_none")]
scan_config: Option<ResourceRefResponse>,
}

impl From<gvm_gateway_domain::ReportTaskRef> for ReportTaskRefResponse {
fn from(task: gvm_gateway_domain::ReportTaskRef) -> Self {
Self {
id: parse_uuid(&task.id),
name: task.name,
scan_config: task.scan_config.map(ResourceRefResponse::from),
}
}
}

/// JSON body returned for a single report.
#[derive(Clone, Debug, Serialize, JsonSchema)]
#[schemars(rename = "Report")]
pub(crate) struct ReportResponse {
id: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
task: Option<ResourceRefResponse>,
task: Option<ReportTaskRefResponse>,
#[serde(rename = "scanStart", skip_serializing_if = "Option::is_none")]
#[schemars(schema_with = "datetime_schema")]
scan_start: Option<String>,
Expand All @@ -108,7 +129,7 @@ impl From<gvm_gateway_domain::Report> for ReportResponse {
fn from(r: gvm_gateway_domain::Report) -> Self {
Self {
id: parse_uuid(&r.id),
task: r.task.map(ResourceRefResponse::from),
task: r.task.map(ReportTaskRefResponse::from),
scan_start: r.scan_start,
scan_end: r.scan_end,
severity: r.severity,
Expand Down
26 changes: 26 additions & 0 deletions crates/gvm-gateway-rest/src/reports_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,29 @@ fn application_optional_counts_json_contract() {
assert!(absent.get("occurrences").is_none());
assert!(absent.get("threat").is_none());
}

// Intent: report-only scanConfig survives REST and domain JSON exports; generic refs remain unchanged.
#[test]
fn report_task_snapshot_json_contract() {
let task = gvm_gateway_domain::ReportTaskRef {
id: "33333333-3333-3333-3333-333333333333".into(),
name: Some("Task".into()),
scan_config: Some(gvm_gateway_domain::ResourceRef {
id: "11111111-1111-1111-1111-111111111111".into(),
name: Some("Old & frozen".into()),
}),
};
let export = serde_json::to_value(&task).unwrap();
let rest = serde_json::to_value(super::ReportTaskRefResponse::from(task)).unwrap();
assert_eq!(export, rest);
assert_eq!(rest["scanConfig"]["name"], "Old & frozen");
let absent = serde_json::to_value(super::ReportTaskRefResponse::from(
gvm_gateway_domain::ReportTaskRef {
id: "33333333-3333-3333-3333-333333333333".into(),
name: None,
scan_config: None,
},
))
.unwrap();
assert!(absent.get("scanConfig").is_none());
}
11 changes: 7 additions & 4 deletions crates/gvm-gateway/tests/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2097,10 +2097,13 @@ impl ReportPort for MissingReportPort {
fn report_response(id: &str) -> Report {
Report {
id: id.to_string(),
task: Some(ResourceRef {
id: "660e8400-e29b-41d4-a716-446655440000".to_string(),
name: Some("Task".to_string()),
}),
task: Some(
ResourceRef {
id: "660e8400-e29b-41d4-a716-446655440000".to_string(),
name: Some("Task".to_string()),
}
.into(),
),
scan_start: None,
scan_end: None,
severity: Some(5.0),
Expand Down
5 changes: 5 additions & 0 deletions docs/report-projection-adoption.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ GET /reports/{id}/applications preserves optional hostsCount, occurrences and op
## #735 NVT type

JSON type is an optional open string. Ordinary results (including report embedded results) map typed NvtRef.type_; notes/overrides map typed NvtReference.type_, retaining the legacy family alias for backward compatibility. Aggregate vulnerability and closed-CVE sources lack a typed discriminator and keep it absent. Metadata is unchanged; missing NVTs remain missing.

## #736 report snapshot scan configuration

Detail GET /reports/{id} and gateway JSON exports preserve optional task.scanConfig (UUID/name) using typed GetScanReportRequest / StructuredReportTask.scan_config. Generic GET /reports list task references omit scanConfig: upstream generic Report has only NamedEntity and would need an upstream extension for list coverage. No current task lookup, XML parsing or audit/delta surface is added. Existing metadata and explicit result pagination are retained. This structured helper requires upstream GMP 22.8 support; typed unsupported-command capability results omit this optional enrichment and retain the generic task reference. An absent snapshot task also retains that reference without a configuration. Permission, parse and backend failures propagate, never fabricated metadata.

15 changes: 14 additions & 1 deletion spec/rest-api/reports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ components:
type: string
format: uuid
task:
$ref: "./common.yaml#/components/schemas/ResourceRef"
$ref: "#/components/schemas/ReportTaskRef"
scanStart:
type: string
format: date-time
Expand All @@ -453,6 +453,19 @@ components:
$ref: "./results.yaml#/components/schemas/Result"
description: Embedded results from the requested page when fetching a single report.

ReportTaskRef:
type: object
required: [id]
properties:
id:
type: string
format: uuid
name:
type: string
scanConfig:
$ref: "./common.yaml#/components/schemas/ResourceRef"
description: Historical configuration from the structured report snapshot; absent on report lists.

ResultCount:
type: object
properties:
Expand Down
Loading
Loading