fix(domain): refuse three non-canonical v3 shapes, R5.5 LOW fixes, R5.6 plan
check_v3_shape at read_report_document v3 and parse_envelope (sheet, practitioner as non-objects, severity as non-string); Protocol errors final; DEV address must be an own unicast address. SQL confirm function and DEV keys characterised, no change.
This commit is contained in:
1 parent
13db5539a3
commit
d502dfa923
11 files changed
+369
-37
No files matched your search
@@ -12,7 +12,7 @@ use ts_rs::TS;
|
||||
use super::envelope::{ENVELOPE_VERSION, EnvelopeVersion1, EnvelopeWrapper, ReportArchiveEnvelope};
|
||||
use super::snapshot::SheetSnapshot;
|
||||
use super::snapshot_rules::{SnapshotRejection, assert_snapshot};
|
||||
use crate::domain::report::read::{ReadFailure, read_report_document, version_of};
|
||||
use crate::domain::report::read::{ReadFailure, check_v3_shape, read_report_document, version_of};
|
||||
use crate::domain::report::{Report, ReportMigrationMap};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
|
||||
@@ -121,5 +121,7 @@ fn snapshot_matches(snapshot: &SheetSnapshot, report: &Report) -> bool {
|
||||
/// `ReportArchiveEnvelopeSchema.parse`: the shape of a whole envelope (the snapshot's shape
|
||||
/// only, no caps nor integrity), as the session keeps it.
|
||||
pub fn parse_envelope(data: &Value) -> Result<ReportArchiveEnvelope, serde_json::Error> {
|
||||
let report = data.get("report").unwrap_or(&Value::Null);
|
||||
check_v3_shape(report).map_err(serde::de::Error::custom)?;
|
||||
ReportArchiveEnvelope::deserialize(data)
|
||||
}
|
||||
@@ -49,6 +49,27 @@ pub fn version_of(data: &Value) -> Option<f64> {
|
||||
data.as_object()?.get("version")?.as_f64()
|
||||
}
|
||||
|
||||
/// The shapes Zod refused and serde's derives accept (owner go 2026-10-24, RUST.md §11.18):
|
||||
/// `sheet` and `practitioner` written as positional arrays, a `severity` written as a one-key
|
||||
/// map. Checked on the raw value before the typed read; nothing else is widened or narrowed.
|
||||
pub fn check_v3_shape(data: &Value) -> Result<(), String> {
|
||||
for key in ["sheet", "practitioner"] {
|
||||
if data.get(key).is_some_and(|value| !value.is_object()) {
|
||||
return Err(format!("{key}: expected an object"));
|
||||
}
|
||||
}
|
||||
let observations = data.get("observations").and_then(Value::as_array);
|
||||
for (index, observation) in observations.into_iter().flatten().enumerate() {
|
||||
let severity = observation.get("severity");
|
||||
if severity.is_some_and(|value| !value.is_string()) {
|
||||
return Err(format!(
|
||||
"observations[{index}].severity: expected a string or null"
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Reads a report document of version 2 or 3 and returns it as v3.
|
||||
pub fn read_report_document(
|
||||
data: &Value,
|
||||
@@ -56,6 +77,7 @@ pub fn read_report_document(
|
||||
) -> Result<MigrationOutcome, ReadFailure> {
|
||||
let version = version_of(data);
|
||||
if version == Some(3.0) {
|
||||
check_v3_shape(data).map_err(ReadFailure::Invalid)?;
|
||||
let report = Report::deserialize(data).map_err(ReadFailure::invalid)?;
|
||||
return Ok(MigrationOutcome {
|
||||
report,
|
||||
|
||||
Reference in new issue
Block a user