mhome-core-api 1.78.0

Shared wire types and service contracts for the mHome core
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
//! Package-owned Node definitions. This contract contains no Plugin registry.
use serde::{Deserialize, Serialize};
use serde_json::Value;
use sha2::{Digest, Sha256};

pub const NODE_METADATA_TARGET: &str = "/node/metadata";
pub const NODE_METADATA_SCHEMA_VERSION: &str = "meow.node.metadata.v2";
pub const NODE_MANIFEST_MAX_BYTES: usize = 1024 * 1024;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum PluginKind {
    Core,
    Extension,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum NodeDelivery {
    Host,
    Firmware,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum NodeBindingCardinality {
    Single,
    Multiple,
}

impl NodeBindingCardinality {
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Single => "single",
            Self::Multiple => "multiple",
        }
    }
    pub fn binding_slot(self, service_instance_id: &str) -> &str {
        match self {
            Self::Single => "single",
            Self::Multiple => service_instance_id,
        }
    }
}
impl std::fmt::Display for NodeBindingCardinality {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PluginDefinition {
    pub id: String,
    pub node_type: String,
    pub service_id: String,
    pub component_id: String,
    pub kind: PluginKind,
    pub binding_cardinality: NodeBindingCardinality,
    pub display_name: String,
    pub description: String,
    /// Digest of the fixed public contribution index, covered by release/Host proof.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub contributions: Option<crate::plugin_contributions::ContributionFile>,
}

impl PluginDefinition {
    pub fn validate(&self) -> Result<(), String> {
        if let Some(reference) = &self.contributions {
            if reference.size == 0 {
                return Err("Plugin contribution index cannot be empty".into());
            }
            reference.validate(crate::plugin_contributions::CONTRIBUTIONS_INDEX_MAX_BYTES)?;
        }
        let valid_id = !self.id.is_empty()
            && self.id.len() <= 80
            && self.id.starts_with(|c: char| c.is_ascii_lowercase())
            && self
                .id
                .chars()
                .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-');
        if !valid_id
            || self.node_type != self.id
            || self.service_id != self.id
            || self.component_id != format!("node-{}", self.id)
            || self.display_name.trim().is_empty()
            || self.description.trim().is_empty()
        {
            return Err("Invalid Plugin definition".into());
        }
        Ok(())
    }

    /// These fields identify one Plugin across versions, platforms and delivery forms.
    pub fn same_identity(&self, other: &Self) -> bool {
        self.id == other.id
            && self.node_type == other.node_type
            && self.service_id == other.service_id
            && self.component_id == other.component_id
            && self.kind == other.kind
            && self.binding_cardinality == other.binding_cardinality
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct NodeReleaseManifestBundle {
    pub schema_version: u32,
    pub kind: String,
    /// Exact publisher-signed bytes. Consumers must not reserialize before verification.
    pub manifest: String,
    pub signature: String,
}

impl NodeReleaseManifestBundle {
    pub fn sha256(&self) -> String {
        format!("{:x}", Sha256::digest(self.manifest.as_bytes()))
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct NodeMetadata {
    pub schema_version: String,
    pub delivery: NodeDelivery,
    pub node_type: String,
    pub service_id: String,
    pub service_version: String,
    pub source: NodeSource,
}

/// Explicit provenance: failed publisher validation never becomes Preview.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "camelCase", deny_unknown_fields)]
pub enum NodeSource {
    Published {
        #[serde(rename = "releaseManifest")]
        release_manifest: NodeReleaseManifestBundle,
    },
    Preview {
        manifest: String,
        #[serde(rename = "hostProof")]
        host_proof: String,
    },
}
impl NodeSource {
    pub fn kind(&self) -> NodeSourceKind {
        match self {
            Self::Published { .. } => NodeSourceKind::Published,
            Self::Preview { .. } => NodeSourceKind::Preview,
        }
    }
    pub fn manifest_sha256(&self) -> String {
        match self {
            Self::Published { release_manifest } => release_manifest.sha256(),
            Self::Preview { manifest, .. } => {
                crate::plugin_preview::PluginPreviewManifest::digest(manifest)
            }
        }
    }
    pub fn published(&self) -> Result<&NodeReleaseManifestBundle, String> {
        match self {
            Self::Published { release_manifest } => Ok(release_manifest),
            Self::Preview { .. } => Err("Preview requires trusted Host provenance".into()),
        }
    }
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum NodeSourceKind {
    Published,
    Preview,
}

/// Verified binding state. Persisted with the binding, usable without Host/CDN access.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NodeBindingMetadata {
    pub definition: PluginDefinition,
    pub delivery: NodeDelivery,
    pub version: String,
    pub platform: String,
    pub manifest_sha256: String,
    pub core_protocol: Option<u32>,
    pub source: NodeSourceKind,
    /// Captured from the verified onboarding challenge; a reconnect cannot replace it.
    pub host_public_key: Option<crate::host::auth::PublicKey>,
    /// Verified platform attestation; absent for official releases and local Preview.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub publication: Option<crate::plugin_publication::PluginPublication>,
}

impl NodeMetadata {
    /// The caller supplies environment-scoped publisher trust. No device may choose
    /// its own trusted key. Verification precedes all use of manifest fields.
    pub fn verify(
        &self,
        verify_signature: impl FnOnce(&[u8], &str) -> Result<(), String>,
    ) -> Result<NodeBindingMetadata, String> {
        let bundle = self.source.published()?;
        if self.schema_version != NODE_METADATA_SCHEMA_VERSION
            || bundle.schema_version != 1
            || bundle.manifest.len() > NODE_MANIFEST_MAX_BYTES
            || bundle.signature.len() > 4096
        {
            return Err("Invalid Node metadata envelope".into());
        }
        let (bundle_kind, manifest_kind) = match self.delivery {
            NodeDelivery::Host => ("meow.plugin.manifest-bundle", "meow.plugin.manifest"),
            NodeDelivery::Firmware => (
                "meow.node.firmware-manifest-bundle",
                "meow.node.firmware-manifest",
            ),
        };
        if bundle.kind != bundle_kind {
            return Err("Node delivery and manifest kind disagree".into());
        }
        verify_signature(bundle.manifest.as_bytes(), &bundle.signature)?;
        let manifest: Value = serde_json::from_str(&bundle.manifest).map_err(|e| e.to_string())?;
        if manifest["schemaVersion"] != 1 || manifest["kind"] != manifest_kind {
            return Err("Invalid signed Node manifest".into());
        }
        let component = match self.delivery {
            NodeDelivery::Host => &manifest["component"],
            NodeDelivery::Firmware => &manifest,
        };
        let definition: PluginDefinition =
            serde_json::from_value(component["nodeMetadata"]["plugin"].clone())
                .map_err(|e| format!("Invalid signed Plugin definition: {e}"))?;
        definition.validate()?;
        let publication = manifest
            .get("publication")
            .map(|value| {
                serde_json::from_value::<crate::plugin_publication::PluginPublication>(
                    value.clone(),
                )
                .map_err(|e| format!("Invalid Plugin publication: {e}"))
            })
            .transpose()?;
        if let Some(publication) = &publication {
            if self.delivery != NodeDelivery::Host {
                return Err("Community publication requires Host delivery".into());
            }
            publication.validate(&definition)?;
        }
        let version = component["version"]
            .as_str()
            .ok_or("Node manifest version missing")?;
        let platform = manifest["platform"]
            .as_str()
            .filter(|v| !v.trim().is_empty())
            .ok_or("Node manifest platform missing")?;
        if version.trim().is_empty()
            || version != self.service_version
            || definition.node_type != self.node_type
            || definition.service_id != self.service_id
            || manifest["pluginId"] != definition.id
            || manifest["componentId"] != definition.component_id
        {
            return Err("Node manifest does not describe the running service".into());
        }
        let protocol_value = &component["compatibility"]["coreProtocol"];
        let core_protocol = if protocol_value.is_null() {
            None
        } else {
            Some(
                protocol_value
                    .as_u64()
                    .and_then(|p| u32::try_from(p).ok())
                    .filter(|p| *p > 0)
                    .ok_or("Invalid Node Core protocol revision")?,
            )
        };
        match (definition.kind, core_protocol) {
            (PluginKind::Core, Some(_)) | (PluginKind::Extension, None) => {}
            _ => return Err("Plugin kind and Core protocol disagree".into()),
        }
        Ok(NodeBindingMetadata {
            definition,
            delivery: self.delivery,
            version: version.into(),
            platform: platform.into(),
            manifest_sha256: bundle.sha256(),
            core_protocol,
            source: NodeSourceKind::Published,
            host_public_key: None,
            publication,
        })
    }

    /// The verifier MUST use a key from authenticated onboarding or an existing
    /// binding, never one offered in this Node's metadata.
    pub fn verify_preview(
        &self,
        host_id: &str,
        env: crate::RuntimeEnv,
        verify_proof: impl FnOnce(&str) -> Result<crate::plugin_preview::PluginPreviewProof, String>,
    ) -> Result<NodeBindingMetadata, String> {
        let NodeSource::Preview {
            manifest,
            host_proof,
        } = &self.source
        else {
            return Err("Expected Preview provenance".into());
        };
        if self.schema_version != NODE_METADATA_SCHEMA_VERSION
            || self.delivery != NodeDelivery::Host
            || host_proof.len() > 16384
            || host_id.is_empty()
        {
            return Err("Invalid Preview metadata envelope".into());
        }
        let parsed = crate::plugin_preview::PluginPreviewManifest::parse(manifest)?;
        let proof = verify_proof(host_proof)?;
        let digest = self.source.manifest_sha256();
        if proof.host_id != host_id
            || proof.env != env
            || proof.manifest_sha256 != digest
            || parsed.plugin.node_type != self.node_type
            || parsed.plugin.service_id != self.service_id
            || parsed.service_version != self.service_version
        {
            return Err("Preview proof does not describe this Host and running service".into());
        }
        Ok(NodeBindingMetadata {
            definition: parsed.plugin,
            delivery: self.delivery,
            version: parsed.service_version,
            platform: parsed.platform,
            manifest_sha256: digest,
            core_protocol: parsed.core_protocol,
            source: NodeSourceKind::Preview,
            host_public_key: None,
            publication: None,
        })
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use serde_json::json;
    fn host() -> NodeMetadata {
        NodeMetadata {
            schema_version: NODE_METADATA_SCHEMA_VERSION.into(),
            delivery: NodeDelivery::Host,
            node_type: "example-extension".into(),
            service_id: "example-extension".into(),
            service_version: "1.0.0".into(),
            source: NodeSource::Published {
                release_manifest: serde_json::from_str(include_str!(
                    "../fixtures/node-metadata/host.bundle.json"
                ))
                .unwrap(),
            },
        }
    }
    fn verify(bytes: &[u8], signature: &str) -> Result<(), String> {
        let key = minisign_verify::PublicKey::from_base64(
            include_str!("../fixtures/node-metadata/public-key.txt").trim(),
        )
        .unwrap();
        key.verify(
            bytes,
            &minisign_verify::Signature::decode(signature).map_err(|e| e.to_string())?,
            false,
        )
        .map_err(|e| e.to_string())
    }
    #[test]
    fn contribution_reference_is_captured_from_verified_source_and_cannot_bypass_signature() {
        let mut metadata = host();
        let NodeSource::Published { release_manifest } = &mut metadata.source else {
            unreachable!()
        };
        let mut manifest: Value = serde_json::from_str(&release_manifest.manifest).unwrap();
        manifest["component"]["nodeMetadata"]["plugin"]["contributions"] =
            serde_json::json!({"size":128,"sha256":"a".repeat(64)});
        release_manifest.manifest = manifest.to_string();
        assert!(
            metadata.verify(verify).is_err(),
            "an altered installed declaration must fail signature verification"
        );
        // Admission projection is tested separately from cryptographic fixtures.
        let binding = metadata.verify(|_, _| Ok(())).unwrap();
        assert_eq!(
            binding.definition.contributions.unwrap().sha256,
            "a".repeat(64)
        );
    }

    #[test]
    fn community_release_retains_only_verified_publication_identity() {
        let mut metadata = host();
        metadata.node_type = "u-252beb16094f8b00bc706b2b3c6bc819-garden".into();
        metadata.service_id = metadata.node_type.clone();
        metadata.source = NodeSource::Published {
            release_manifest: serde_json::from_str(include_str!(
                "../fixtures/node-metadata/community.bundle.json"
            ))
            .unwrap(),
        };
        let verify = |bytes: &[u8], signature: &str| {
            minisign_verify::PublicKey::from_base64(
                include_str!("../fixtures/node-metadata/community-public-key.txt").trim(),
            )
            .unwrap()
            .verify(
                bytes,
                &minisign_verify::Signature::decode(signature).map_err(|e| e.to_string())?,
                false,
            )
            .map_err(|e| e.to_string())
        };
        let binding = metadata.verify(verify).unwrap();
        assert_eq!(
            binding.publication.unwrap().integrations(),
            &["U-example-publisher_garden.light"]
        );
        let NodeSource::Published { release_manifest } = &mut metadata.source else {
            unreachable!()
        };
        release_manifest.manifest = release_manifest
            .manifest
            .replace("example-publisher", "another-publisher");
        assert!(metadata.verify(verify).is_err());
    }
    #[test]
    fn preview_is_explicit_and_bound_to_host_environment_and_complete_content() {
        use crate::plugin_preview::*;
        let mut metadata = host();
        let published = metadata.verify(verify).unwrap();
        let raw = serde_json::to_string(&PluginPreviewManifest {
            format_version: 1,
            plugin: published.definition,
            platform: "linux-arm64".into(),
            service_version: metadata.service_version.clone(),
            core_protocol: None,
            requires: Default::default(),
            files_sha256: "a".repeat(64),
        })
        .unwrap();
        metadata.source = NodeSource::Preview {
            manifest: raw,
            host_proof: "Host proof".into(),
        };
        assert!(metadata
            .verify(|_, _| panic!("Preview is not a publisher manifest"))
            .is_err());
        let proof = PluginPreviewProof {
            host_id: "desktop".into(),
            env: crate::RuntimeEnv::Prod,
            manifest_sha256: metadata.source.manifest_sha256(),
        };
        let verify = |metadata: &NodeMetadata, proof: PluginPreviewProof| {
            metadata.verify_preview("desktop", crate::RuntimeEnv::Prod, |_| Ok(proof))
        };
        assert_eq!(
            verify(&metadata, proof.clone()).unwrap().source,
            NodeSourceKind::Preview
        );
        let mut wrong = proof.clone();
        wrong.host_id = "other-host".into();
        assert!(verify(&metadata, wrong).is_err());
        let mut wrong = proof.clone();
        wrong.env = crate::RuntimeEnv::Dev;
        assert!(verify(&metadata, wrong).is_err());
        let mut wrong = proof.clone();
        wrong.manifest_sha256 = "b".repeat(64);
        assert!(verify(&metadata, wrong).is_err());
        assert!(metadata
            .verify_preview("desktop", crate::RuntimeEnv::Prod, |_| Err(
                "bad signature".into()
            ))
            .is_err());
        let mut wrong = metadata.clone();
        wrong.node_type = "other".into();
        assert!(verify(&wrong, proof.clone()).is_err());
        let mut wrong = metadata;
        wrong.delivery = NodeDelivery::Firmware;
        assert!(verify(&wrong, proof).is_err());
    }

    #[test]
    fn android_aar_firmware_metadata_uses_its_embedded_release_version() {
        // Generated by Plugin's Android manifest publisher with a disposable test key.
        let bundle: NodeReleaseManifestBundle = serde_json::from_str(include_str!(
            "../fixtures/node-metadata/android.bundle.json"
        ))
        .unwrap();
        let metadata = NodeMetadata {
            schema_version: NODE_METADATA_SCHEMA_VERSION.into(),
            delivery: NodeDelivery::Firmware,
            node_type: "camera".into(),
            service_id: "camera".into(),
            service_version: "1.0.5".into(),
            source: NodeSource::Published {
                release_manifest: bundle,
            },
        };
        let verify_android = |bytes: &[u8], signature: &str| {
            let key = minisign_verify::PublicKey::from_base64(
                include_str!("../fixtures/node-metadata/android-public-key.txt").trim(),
            )
            .unwrap();
            key.verify(
                bytes,
                &minisign_verify::Signature::decode(signature).map_err(|e| e.to_string())?,
                false,
            )
            .map_err(|e| e.to_string())
        };
        let binding = metadata.verify(verify_android).unwrap();
        assert_eq!(binding.delivery, NodeDelivery::Firmware);
        assert_eq!(binding.platform, "android");
        assert_eq!(binding.version, "1.0.5");
        assert_eq!(binding.core_protocol, Some(2));
        assert_eq!(
            binding.definition.binding_cardinality,
            NodeBindingCardinality::Multiple
        );
        let mut wrong_version = metadata;
        wrong_version.service_version = "1.1.0".into();
        assert!(wrong_version.verify(verify_android).is_err());
    }

    #[test]
    fn installed_release_is_verified_without_a_latest_catalog() {
        let metadata = host();
        let binding = metadata.verify(verify).unwrap();
        assert_eq!(binding.definition.kind, PluginKind::Extension);
        assert_eq!(
            binding.definition.binding_cardinality,
            NodeBindingCardinality::Single
        );
        assert_eq!(binding.manifest_sha256.len(), 64);
        assert_eq!(
            binding
                .definition
                .binding_cardinality
                .binding_slot("service-a"),
            "single"
        );
        assert_eq!(
            serde_json::from_str::<NodeBindingMetadata>(&serde_json::to_string(&binding).unwrap())
                .unwrap(),
            binding
        );
    }
    #[test]
    fn wrong_running_identity_version_delivery_and_signature_are_rejected() {
        let original = host();
        for field in ["nodeType", "serviceId", "serviceVersion", "delivery"] {
            let mut value = serde_json::to_value(&original).unwrap();
            value[field] = json!(if field == "delivery" {
                "firmware"
            } else {
                "other"
            });
            assert!(
                serde_json::from_value::<NodeMetadata>(value)
                    .unwrap()
                    .verify(verify)
                    .is_err(),
                "{field}"
            );
        }
        let mut tampered = original;
        let NodeSource::Published { release_manifest } = &mut tampered.source else {
            unreachable!()
        };
        release_manifest.manifest = release_manifest.manifest.replace("single", "multiple");
        assert!(tampered.verify(verify).is_err());
    }
    #[test]
    fn definition_identity_is_independent_of_version_platform_and_display_text() {
        let a = host().verify(verify).unwrap().definition;
        let mut b = a.clone();
        b.display_name = "New name".into();
        assert!(a.same_identity(&b));
        b.binding_cardinality = NodeBindingCardinality::Multiple;
        assert!(!a.same_identity(&b));
        b = a.clone();
        b.kind = PluginKind::Core;
        assert!(!a.same_identity(&b));
    }
    #[test]
    fn authentication_requires_metadata_and_acknowledges_the_exact_release() {
        let metadata = host();
        let binding = metadata.verify(verify).unwrap();
        let mut wire = json!({"metadata":metadata,"hubId":"hub","token":"token","nodeType":metadata.node_type,
            "nodeId":"node","hostId":"host","fingerprint":"fingerprint"});
        let request: crate::NodeAuthRequest = serde_json::from_value(wire.clone()).unwrap();
        wire.as_object_mut().unwrap().remove("metadata");
        assert!(serde_json::from_value::<crate::NodeAuthRequest>(wire).is_err());
        let response: crate::NodeAuthResponse =
            serde_json::from_value(json!({"ok":true,"bindingMetadata":binding})).unwrap();
        assert_eq!(response.admitted_metadata(&request).unwrap(), &binding);
        let envelope = crate::MwsMessage::create(
            None,
            "/node/auth".into(),
            "auth".into(),
            serde_json::to_string(&request).unwrap(),
            "nrq".into(),
        );
        assert!(serde_json::to_vec(&envelope).unwrap().len() < 32768);
        for field in ["version", "manifestSha256", "delivery", "coreProtocol"] {
            let mut bad = serde_json::to_value(&response).unwrap();
            bad["bindingMetadata"][field] = match field {
                "delivery" => json!("firmware"),
                "coreProtocol" => json!(2),
                _ => json!("other"),
            };
            assert!(
                serde_json::from_value::<crate::NodeAuthResponse>(bad)
                    .unwrap()
                    .admitted_metadata(&request)
                    .is_err(),
                "{field}"
            );
        }
        let missing: crate::NodeAuthResponse = serde_json::from_value(json!({"ok":true})).unwrap();
        assert!(missing.admitted_metadata(&request).is_err());
    }
}