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
2 changes: 2 additions & 0 deletions crates/gvm-gateway-domain/src/lib_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ fn scan_result_serializes_camel_case() {
cvss_base: Some(9.8),
cves: vec!["CVE-2024-1234".to_string()],
tags: None,
type_: None,
type_metadata: None,
epss: None,
}),
Expand Down Expand Up @@ -523,6 +524,7 @@ fn nvt_ref_omits_empty_cves() {
cvss_base: None,
cves: vec![],
tags: None,
type_: None,
type_metadata: None,
epss: None,
};
Expand Down
3 changes: 3 additions & 0 deletions crates/gvm-gateway-domain/src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ pub struct NvtRef {
/// NVT tags.
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<String>,
/// Open discriminator supplied by the typed NVT source.
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
pub type_: Option<String>,
/// Source-shaped NVT type metadata supplied by gvmd.
#[serde(rename = "typeMetadata", skip_serializing_if = "Option::is_none")]
pub type_metadata: Option<String>,
Expand Down
6 changes: 5 additions & 1 deletion crates/gvm-gateway-gvmd/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ pub(crate) fn result_from_gmp(
cvss_base,
cves: n.cves,
tags: n.tags,
type_: n.type_,
type_metadata: n.type_metadata,
epss: n.epss.map(epss_from_gmp).transpose()?,
})
Expand Down Expand Up @@ -546,6 +547,7 @@ pub(crate) fn result_from_report_vulnerability(
cvss_base: None,
cves: vulnerability.cves,
tags: None,
type_: None,
type_metadata: None,
epss: None,
}),
Expand Down Expand Up @@ -595,6 +597,7 @@ pub(crate) fn report_closed_cve_from_gmp(
cvss_base: None,
cves: closed_cve.cve.clone().into_iter().collect(),
tags: None,
type_: None,
type_metadata: None,
epss: None,
}),
Expand Down Expand Up @@ -1140,7 +1143,8 @@ fn nvt_ref_from_gmp(nvt: gvm_gmp::responses::common::NvtReference) -> NvtRef {
NvtRef {
oid: Some(nvt.oid),
name: nvt.name,
family: nvt.type_,
family: nvt.type_.clone(),
type_: nvt.type_,
cvss_base: None,
cves: vec![],
tags: None,
Expand Down
54 changes: 54 additions & 0 deletions crates/gvm-gateway-gvmd/src/conversions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,60 @@ fn target_source_conversion_preserves_upstream_optional_and_open_values() {
}
}

#[test]
fn typed_result_and_nested_reference_types_remain_open_and_optional() {
// Intent (#735): test typed conversion, not just DTO construction; classic,
// nonclassic, future and parser-normalized empty values must agree across
// result, note and override sources, without fabricating a missing NVT.
for (element, expected) in [
("<type>nvt</type>", Some("nvt")),
("<type>package</type>", Some("package")),
("<type>future-source</type>", Some("future-source")),
("<type/>", None),
("", None),
] {
let nvt =
format!(r#"<nvt oid="1.2.3">{element}<type_metadata>opaque</type_metadata></nvt>"#);
let xml = format!(
r#"<get_results_response status="200" status_text="OK"><result id="11111111-1111-1111-1111-111111111111"><name>Result</name>{nvt}</result></get_results_response>"#
);
let parsed = GetResultsResponse::from_response(&GmpResponse::from(xml.as_str())).unwrap();
let result = result_from_gmp(parsed.items.into_iter().next().unwrap()).unwrap();
let mapped = result.nvt.unwrap();
assert_eq!(mapped.type_.as_deref(), expected);
assert_eq!(mapped.type_metadata.as_deref(), Some("opaque"));
let xml = format!(
r#"<get_notes_response status="200" status_text="OK"><note id="note-1"><name>Note</name>{nvt}</note></get_notes_response>"#
);
let parsed = GetNotesResponse::from_response(&GmpResponse::from(xml.as_str())).unwrap();
assert_eq!(
note_from_gmp(parsed.items.into_iter().next().unwrap())
.nvt
.unwrap()
.type_
.as_deref(),
expected
);
let xml = format!(
r#"<get_overrides_response status="200" status_text="OK"><override id="override-1"><name>Override</name>{nvt}</override></get_overrides_response>"#
);
let parsed = GetOverridesResponse::from_response(&GmpResponse::from(xml.as_str())).unwrap();
assert_eq!(
override_from_gmp(parsed.items.into_iter().next().unwrap())
.nvt
.unwrap()
.type_
.as_deref(),
expected
);
}
let parsed = GetResultsResponse::from_response(&GmpResponse::from(r#"<get_results_response status="200" status_text="OK"><result id="11111111-1111-1111-1111-111111111111"><name>No NVT</name></result></get_results_response>"#)).unwrap();
assert!(result_from_gmp(parsed.items.into_iter().next().unwrap())
.unwrap()
.nvt
.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
2 changes: 2 additions & 0 deletions crates/gvm-gateway-rest/src/reports_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ fn report_vulnerability_response_preserves_aggregate_fields() {
cvss_base: None,
cves: vec!["CVE-2026-0001".to_string()],
tags: None,
type_: None,
type_metadata: None,
epss: None,
}),
Expand Down Expand Up @@ -218,6 +219,7 @@ fn report_closed_cve_response_preserves_closed_cve_fields() {
cvss_base: None,
cves: vec!["CVE-2025-9999".to_string()],
tags: None,
type_: None,
type_metadata: None,
epss: None,
}),
Expand Down
11 changes: 9 additions & 2 deletions crates/gvm-gateway-rest/src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ pub(crate) struct NvtRefResponse {
cves: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
tags: Option<String>,
/// Source-shaped NVT type metadata supplied by gvmd. The gateway preserves this value without
/// parsing or narrowing its schema.
/// Open backend NVT discriminator; unknown values are preserved.
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
type_: Option<String>,
/// Opaque backend type metadata, preserved without interpretation.
#[serde(rename = "typeMetadata", skip_serializing_if = "Option::is_none")]
type_metadata: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -74,6 +76,7 @@ impl From<gvm_gateway_domain::NvtRef> for NvtRefResponse {
cvss_base: n.cvss_base,
cves: n.cves,
tags: n.tags,
type_: n.type_,
type_metadata: n.type_metadata,
epss: n.epss.map(EpssResponse::from),
}
Expand Down Expand Up @@ -141,6 +144,9 @@ pub(crate) struct NvtRefSummaryResponse {
cves: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
tags: Option<String>,
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
type_: Option<String>,
/// Opaque backend type metadata, preserved without interpretation.
#[serde(rename = "typeMetadata", skip_serializing_if = "Option::is_none")]
type_metadata: Option<String>,
}
Expand All @@ -154,6 +160,7 @@ impl From<gvm_gateway_domain::NvtRef> for NvtRefSummaryResponse {
cvss_base: nvt.cvss_base,
cves: nvt.cves,
tags: nvt.tags,
type_: nvt.type_,
type_metadata: nvt.type_metadata,
}
}
Expand Down
28 changes: 28 additions & 0 deletions crates/gvm-gateway-rest/src/results_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ fn result_response_preserves_source_shaped_type_metadata() {
cvss_base: None,
cves: Vec::new(),
tags: None,
type_: None,
type_metadata: Some("{\"future\":[1,true]}".to_string()),
epss: None,
}),
Expand Down Expand Up @@ -135,6 +136,7 @@ fn result_response_omits_absent_type_metadata() {
cvss_base: None,
cves: Vec::new(),
tags: None,
type_: None,
type_metadata: None,
epss: None,
});
Expand All @@ -155,6 +157,7 @@ fn result_response_serializes_distinct_epss_selections() {
cvss_base: None,
cves: Vec::new(),
tags: None,
type_: None,
type_metadata: None,
epss: Some(Epss {
max_epss: EpssSelection {
Expand Down Expand Up @@ -198,6 +201,7 @@ fn summary_nvt_reference_does_not_expose_epss() {
cvss_base: None,
cves: Vec::new(),
tags: None,
type_: None,
type_metadata: None,
epss: Some(Epss {
max_epss: EpssSelection {
Expand All @@ -222,3 +226,27 @@ fn summary_nvt_reference_does_not_expose_epss() {
let value = serde_json::to_value(nvt).expect("summary NVT reference should serialize");
assert!(value.get("epss").is_none());
}

// Intent: both full and nested summary DTOs preserve unknown discriminators without altering metadata.
#[test]
fn nvt_open_type_full_and_summary() {
for kind in [Some("nvt"), Some("package"), Some("future-source"), None] {
let n = NvtRef {
oid: None,
name: None,
family: None,
cvss_base: None,
cves: vec![],
tags: None,
type_: kind.map(str::to_owned),
type_metadata: Some("{opaque}".into()),
epss: None,
};
let full = serde_json::to_value(super::NvtRefResponse::from(n.clone())).unwrap();
let summary = serde_json::to_value(super::NvtRefSummaryResponse::from(n)).unwrap();
for json in [full, summary] {
assert_eq!(json["typeMetadata"], "{opaque}");
assert_eq!(json.get("type").and_then(serde_json::Value::as_str), kind);
}
}
}
4 changes: 4 additions & 0 deletions docs/report-projection-adoption.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
## #734 applications

GET /reports/{id}/applications preserves optional hostsCount, occurrences and open-string threat from typed upstream application summaries. Zero is distinct from absence; severity remains server-calculated. No live Agent qualification is claimed.

## #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.
6 changes: 6 additions & 0 deletions spec/rest-api/results.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ components:
type: string
tags:
type: string
type:
type: string
description: Open backend NVT discriminator; unknown values are preserved.
typeMetadata:
type: string
description: Source-shaped NVT type metadata supplied by gvmd. The gateway preserves this value without parsing or narrowing its schema.
Expand All @@ -154,6 +157,9 @@ components:
type: string
tags:
type: string
type:
type: string
description: Open backend NVT discriminator; unknown values are preserved.
typeMetadata:
type: string
description: Source-shaped NVT type metadata supplied by gvmd. The gateway preserves this value without parsing or narrowing its schema.
Expand Down
2 changes: 2 additions & 0 deletions worklog.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
- #734: preserve typed optional counts/threat and server severity. Dependency baseline pending.

- #734 slice-boundary correction: explicit u32 schema bounds now live with application counts, not the later reference slice. Added generated schema regression; preserved curated limits.
- #735: open JSON type on full/summary result NVTs; typed note/override references no longer mislabel discriminator as family. Aggregate sources retain absence.
- #735 acceptance review: typed classic/nonclassic/future/empty/absent discriminator projections qualified; description comments corrected.
## Review correction #730 (2026-11-20)

Reject explicit null maxDelaySeconds on all agent schedule and group inputs; preserve omission, zero and GMP bounds. Add HTTP 400/no-backend-dispatch regressions and REST boundary coverage.
Expand Down
Loading