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
//! Registry-driven per-rule matrix for `ComplianceLevel::FdaMedicalDevice`
//! (audit P3: the FDA framework previously had zero behavioral tests).
//!
//! Every rule id in `FDA_SARIF_RULE_IDS` gets a firing fixture (a minimal
//! CycloneDX document, parsed through the real parser, that must surface the
//! rule) and a silent fixture (one that must not), or an explicit
//! skip-with-reason. The runner enforces exhaustiveness against the
//! registry's FDA SARIF slice, so a new FDA rule cannot land untested.
#[path = "common/rule_matrix.rs"]
mod rule_matrix;
use rule_matrix::{
ComponentFixture, MD5_FILLER, RuleEntry, SbomFixture, assert_no_violations, run_matrix,
};
use sbom_tools::quality::{ComplianceLevel, FDA_SARIF_RULE_IDS, ViolationSeverity as Sev};
const LEVEL: ComplianceLevel = ComplianceLevel::FdaMedicalDevice;
/// A fixture that satisfies every FDA premarket element the engine checks:
/// timestamp, tool + manufacturer creators with a contact email, serial
/// number, named primary product with end-of-support evidence, and fully
/// attributed/hashed/connected components.
fn base() -> SbomFixture {
let mut primary = ComponentFixture::conforming("acme-device");
// Level-of-support evidence: the parser lifts this primary-component
// property into document.support_end_date.
primary
.properties
.push(("endOfSupport".to_string(), "2030-01-01".to_string()));
SbomFixture {
spec_version: "1.5".to_string(),
timestamp: Some("2026-01-15T10:00:00Z".to_string()),
serial_number: Some("urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79".to_string()),
tools: vec![("acme-sbom-tool".to_string(), "1.0.0".to_string())],
authors: Vec::new(),
manufacturer: Some((
"Acme Medical Inc".to_string(),
Some("security@acme.example".to_string()),
)),
primary: Some(primary),
components: vec![
ComponentFixture::conforming("libalpha"),
ComponentFixture::conforming("libbeta"),
],
dependencies: vec![(
"ref-acme-device".to_string(),
vec!["ref-libalpha".to_string(), "ref-libbeta".to_string()],
)],
vulnerabilities: Vec::new(),
}
}
/// Clone the conforming baseline and break exactly one aspect.
fn broken(mutate: impl FnOnce(&mut SbomFixture)) -> SbomFixture {
let mut fixture = base();
mutate(&mut fixture);
fixture
}
/// The conforming FDA fixture must pass with a clean verdict — no test in the
/// repo previously observed `is_compliant == true` for FdaMedicalDevice.
#[test]
fn fda_conforming_fixture_is_compliant_with_zero_violations() {
assert_no_violations(LEVEL, &base());
}
#[test]
fn fda_rule_matrix_is_exhaustive_with_firing_and_silent_cases() {
let entries = vec![
// FDA incorporates the NTIA baseline: a missing/invalid source
// timestamp (epoch sentinel) must gate.
RuleEntry::tested(
"SBOM-NTIA-TIMESTAMP",
Sev::Error,
broken(|s| s.timestamp = None),
base(),
),
// Registry default is Warning; the shared creator gate escalates a
// fully creator-less SBOM to Error for every non-Minimum level.
RuleEntry::tested_departing(
"SBOM-FDA-CREATOR",
Sev::Error,
broken(|s| {
s.tools.clear();
s.manufacturer = None;
}),
base(),
),
RuleEntry::tested(
"SBOM-FDA-NAMESPACE",
Sev::Warning,
broken(|s| s.serial_number = None),
base(),
),
// Component-level missing supplier is the gating Error; the
// document-level "manufacturer should be an organization creator"
// site shares the rule id at Warning.
RuleEntry::tested(
"SBOM-FDA-SUPPLIER",
Sev::Error,
broken(|s| s.component_mut("libalpha").supplier = None),
base(),
)
.with_departing_firing(
"no organization creator (document-level site)",
Sev::Warning,
broken(|s| {
s.manufacturer = None;
// Person author keeps creators non-empty (no FDA-CREATOR) and
// carries the contact email (no FDA-SUPPORT).
s.authors = vec![(
"Dana Author".to_string(),
Some("dana@acme.example".to_string()),
)];
}),
),
// Missing hash is the gating Error; a weak-only (MD5) hash relaxes
// to Warning at the same rule id.
RuleEntry::tested(
"SBOM-FDA-HASH",
Sev::Error,
broken(|s| s.component_mut("libalpha").hashes.clear()),
base(),
)
.with_departing_firing(
"weak hash only (MD5)",
Sev::Warning,
broken(|s| {
s.component_mut("libalpha").hashes =
vec![("MD5".to_string(), MD5_FILLER.to_string())];
}),
),
RuleEntry::tested(
"SBOM-FDA-IDENTIFIER",
Sev::Error,
broken(|s| s.component_mut("libalpha").purl = None),
base(),
),
RuleEntry::tested(
"SBOM-FDA-VERSION",
Sev::Error,
broken(|s| s.component_mut("libalpha").version = None),
base(),
),
// No dependencies at all is the gating Error; FDA keeps any-orphan
// sensitivity, so a single disconnected component warns at the same
// rule id.
RuleEntry::tested(
"SBOM-FDA-DEPENDENCY",
Sev::Error,
broken(|s| s.dependencies.clear()),
base(),
)
.with_departing_firing(
"one orphan component (any-orphan sensitivity)",
Sev::Warning,
broken(|s| {
// libbeta loses its only incoming edge and becomes an orphan.
s.dependencies = vec![(
"ref-acme-device".to_string(),
vec!["ref-libalpha".to_string()],
)];
}),
),
// Two sites share SBOM-FDA-SUPPORT at Warning: creator contact email
// and level-of-support / end-of-support evidence.
RuleEntry::tested(
"SBOM-FDA-SUPPORT",
Sev::Warning,
broken(|s| {
// Drop the only contact email; end-of-support evidence stays.
s.manufacturer = Some(("Acme Medical Inc".to_string(), None));
}),
base(),
)
.with_firing(
"no level-of-support / end-of-support evidence",
Sev::Warning,
broken(|s| {
if let Some(primary) = &mut s.primary {
primary.properties.clear();
}
}),
),
// Fires on unresolved critical/high vulnerabilities; medium ones must
// stay silent.
RuleEntry::tested(
"SBOM-FDA-SECURITY",
Sev::Warning,
broken(|s| {
s.vulnerabilities = vec![(
"CVE-2026-0001".to_string(),
"critical".to_string(),
"ref-libalpha".to_string(),
)];
}),
broken(|s| {
s.vulnerabilities = vec![(
"CVE-2026-0002".to_string(),
"medium".to_string(),
"ref-libalpha".to_string(),
)];
}),
),
// The FDA generic bucket: a missing document name emits the aliased
// SBOM-FDA-NAME key at Warning; a placeholder component name emits
// SBOM-FDA-GENERAL directly, escalated to Error.
RuleEntry::tested(
"SBOM-FDA-GENERAL",
Sev::Warning,
broken(|s| s.primary = None),
base(),
)
.with_departing_firing(
"placeholder component name",
Sev::Error,
broken(|s| {
// "unknown" without a corroborating PURL name segment does
// not count as a real component name.
s.component_mut("libalpha").name = "unknown".to_string();
}),
),
];
run_matrix(LEVEL, FDA_SARIF_RULE_IDS, &entries);
}