Skip to content

Commit 703ac39

Browse files
authored
fix(verifier): make VerificationRequest fields optional (#722)
* fix(verifier): make VerificationRequest fields optional the /verify handler rejected requests that omitted `attestation` and `debug` with a 422, even though the README documents sending only `quote` + `event_log` + `vm_config` (or only `attestation`). every field is an `Option`, but without `#[serde(default)]` serde treats a missing field as a parse error. add `#[serde(default)]` to all fields so any documented subset deserializes and missing fields default to `None`. * test(verifier): cover optional VerificationRequest field combinations add serde tests proving each documented request subset deserializes: quote-only (no attestation), attestation-only, and empty object. these fail with "missing field" without the #[serde(default)] fix.
1 parent 7bf2b00 commit 703ac39

1 file changed

Lines changed: 43 additions & 2 deletions

File tree

verifier/src/types.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ use serde_human_bytes as serde_bytes;
99

1010
#[derive(Debug, Clone, Serialize, Deserialize)]
1111
pub struct VerificationRequest {
12-
#[serde(with = "serde_bytes")]
12+
#[serde(with = "serde_bytes", default)]
1313
pub quote: Option<Vec<u8>>,
14+
#[serde(default)]
1415
pub event_log: Option<String>,
16+
#[serde(default)]
1517
pub vm_config: Option<String>,
16-
#[serde(with = "serde_bytes")]
18+
#[serde(with = "serde_bytes", default)]
1719
pub attestation: Option<Vec<u8>>,
20+
#[serde(default)]
1821
pub debug: Option<bool>,
1922
}
2023

@@ -84,3 +87,41 @@ pub enum RtmrEventStatus {
8487
Extra,
8588
Missing,
8689
}
90+
91+
#[cfg(test)]
92+
mod tests {
93+
use super::*;
94+
95+
// the README documents sending either `attestation` or
96+
// (`quote` + `event_log` + `vm_config`); every field is optional, so any
97+
// documented subset must deserialize without a "missing field" error.
98+
99+
#[test]
100+
fn deserializes_quote_subset_without_attestation() {
101+
let json = r#"{"quote":"00","event_log":"[]","vm_config":"{}"}"#;
102+
let req: VerificationRequest = serde_json::from_str(json).unwrap();
103+
assert_eq!(req.quote, Some(vec![0u8]));
104+
assert_eq!(req.event_log.as_deref(), Some("[]"));
105+
assert_eq!(req.vm_config.as_deref(), Some("{}"));
106+
assert_eq!(req.attestation, None);
107+
assert_eq!(req.debug, None);
108+
}
109+
110+
#[test]
111+
fn deserializes_attestation_subset_without_quote() {
112+
let json = r#"{"attestation":"00"}"#;
113+
let req: VerificationRequest = serde_json::from_str(json).unwrap();
114+
assert_eq!(req.attestation, Some(vec![0u8]));
115+
assert_eq!(req.quote, None);
116+
assert_eq!(req.event_log, None);
117+
assert_eq!(req.vm_config, None);
118+
}
119+
120+
#[test]
121+
fn deserializes_empty_object() {
122+
let req: VerificationRequest = serde_json::from_str("{}").unwrap();
123+
assert_eq!(req.quote, None);
124+
assert_eq!(req.attestation, None);
125+
assert_eq!(req.debug, None);
126+
}
127+
}

0 commit comments

Comments
 (0)