uv-sbom 2.2.0

SBOM generation tool for uv projects - Generate CycloneDX SBOMs from uv.lock files
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
626
627
628
629
630
631
use super::super::vulnerability::{PackageVulnerabilities, Severity, Vulnerability};
use super::cve_filter::CveFilter;
use crate::config::IgnoreCve;

/// Configuration for threshold evaluation
#[derive(Debug, Clone, PartialEq)]
pub enum ThresholdConfig {
    /// No threshold - all vulnerabilities trigger exit code 1
    None,
    /// Threshold based on severity level
    Severity(Severity),
    /// Threshold based on CVSS score
    Cvss(f32),
}

impl ThresholdConfig {
    /// Returns true if the vulnerability meets or exceeds this threshold
    pub fn is_above_threshold(&self, vuln: &Vulnerability) -> bool {
        match self {
            ThresholdConfig::None => true,
            ThresholdConfig::Severity(min_severity) => vuln.severity() >= *min_severity,
            ThresholdConfig::Cvss(min_cvss) => {
                // N/A CVSS scores are excluded from threshold evaluation
                match vuln.cvss_score() {
                    Some(score) => score.value() >= *min_cvss,
                    None => false,
                }
            }
        }
    }
}

/// Result of vulnerability threshold check
#[derive(Debug, Clone)]
pub struct VulnerabilityCheckResult {
    /// Packages with vulnerabilities above the threshold
    pub above_threshold: Vec<PackageVulnerabilities>,
    /// Packages with vulnerabilities below the threshold
    pub below_threshold: Vec<PackageVulnerabilities>,
    /// Whether any vulnerability exceeded the threshold
    pub threshold_exceeded: bool,
}

impl VulnerabilityCheckResult {
    /// Returns total count of actionable vulnerabilities
    pub fn actionable_count(&self) -> usize {
        self.above_threshold
            .iter()
            .map(|pv| pv.vulnerabilities().len())
            .sum()
    }

    /// Returns total count of informational vulnerabilities
    pub fn informational_count(&self) -> usize {
        self.below_threshold
            .iter()
            .map(|pv| pv.vulnerabilities().len())
            .sum()
    }
}

/// Domain service for evaluating vulnerabilities against thresholds
pub struct VulnerabilityChecker;

impl VulnerabilityChecker {
    /// Checks vulnerabilities against the specified threshold, after filtering ignored CVEs
    ///
    /// # Arguments
    /// * `vulnerabilities` - List of package vulnerabilities to check
    /// * `threshold` - Threshold configuration
    /// * `ignore_cves` - List of CVE IDs to ignore (excluded before threshold evaluation)
    ///
    /// # Returns
    /// VulnerabilityCheckResult with above/below threshold separation
    pub fn check(
        vulnerabilities: Vec<PackageVulnerabilities>,
        threshold: ThresholdConfig,
        ignore_cves: &[IgnoreCve],
    ) -> VulnerabilityCheckResult {
        // Step 1: Filter out ignored CVEs
        let filtered = CveFilter::apply(vulnerabilities, ignore_cves);

        // Step 2: Apply threshold evaluation
        let mut above_threshold = Vec::new();
        let mut below_threshold = Vec::new();

        for pkg_vulns in filtered {
            let mut above = Vec::new();
            let mut below = Vec::new();

            for vuln in pkg_vulns.vulnerabilities() {
                if threshold.is_above_threshold(vuln) {
                    above.push(vuln.clone());
                } else {
                    below.push(vuln.clone());
                }
            }

            if !above.is_empty() {
                above_threshold.push(PackageVulnerabilities::new(
                    pkg_vulns.package_name().to_string(),
                    pkg_vulns.current_version().to_string(),
                    above,
                ));
            }

            if !below.is_empty() {
                below_threshold.push(PackageVulnerabilities::new(
                    pkg_vulns.package_name().to_string(),
                    pkg_vulns.current_version().to_string(),
                    below,
                ));
            }
        }

        let threshold_exceeded = !above_threshold.is_empty();

        VulnerabilityCheckResult {
            above_threshold,
            below_threshold,
            threshold_exceeded,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::sbom_generation::domain::vulnerability::CvssScore;

    fn create_vulnerability(id: &str, cvss: Option<f32>, severity: Severity) -> Vulnerability {
        let cvss_score = cvss.map(|s| CvssScore::new(s).unwrap());
        Vulnerability::new(id.to_string(), cvss_score, severity, None, None).unwrap()
    }

    fn create_package_vulnerabilities(
        name: &str,
        vulnerabilities: Vec<Vulnerability>,
    ) -> PackageVulnerabilities {
        PackageVulnerabilities::new(name.to_string(), "1.0.0".to_string(), vulnerabilities)
    }

    #[test]
    fn test_threshold_none_all_above() {
        let vuln1 = create_vulnerability("CVE-2024-001", Some(3.0), Severity::Low);
        let vuln2 = create_vulnerability("CVE-2024-002", Some(9.8), Severity::Critical);
        let pkg = create_package_vulnerabilities("test-pkg", vec![vuln1, vuln2]);

        let result = VulnerabilityChecker::check(vec![pkg], ThresholdConfig::None, &[]);

        assert!(result.threshold_exceeded);
        assert_eq!(result.above_threshold.len(), 1);
        assert_eq!(result.above_threshold[0].vulnerabilities().len(), 2);
        assert!(result.below_threshold.is_empty());
    }

    #[test]
    fn test_threshold_severity_high() {
        let vuln_low = create_vulnerability("CVE-2024-001", Some(3.0), Severity::Low);
        let vuln_medium = create_vulnerability("CVE-2024-002", Some(5.0), Severity::Medium);
        let vuln_high = create_vulnerability("CVE-2024-003", Some(7.5), Severity::High);
        let vuln_critical = create_vulnerability("CVE-2024-004", Some(9.8), Severity::Critical);
        let pkg = create_package_vulnerabilities(
            "test-pkg",
            vec![vuln_low, vuln_medium, vuln_high, vuln_critical],
        );

        let result =
            VulnerabilityChecker::check(vec![pkg], ThresholdConfig::Severity(Severity::High), &[]);

        assert!(result.threshold_exceeded);
        assert_eq!(result.above_threshold.len(), 1);
        assert_eq!(result.above_threshold[0].vulnerabilities().len(), 2); // High and Critical
        assert_eq!(result.below_threshold.len(), 1);
        assert_eq!(result.below_threshold[0].vulnerabilities().len(), 2); // Low and Medium
    }

    #[test]
    fn test_threshold_severity_critical_only() {
        let vuln_high = create_vulnerability("CVE-2024-001", Some(8.0), Severity::High);
        let vuln_critical = create_vulnerability("CVE-2024-002", Some(9.8), Severity::Critical);
        let pkg = create_package_vulnerabilities("test-pkg", vec![vuln_high, vuln_critical]);

        let result = VulnerabilityChecker::check(
            vec![pkg],
            ThresholdConfig::Severity(Severity::Critical),
            &[],
        );

        assert!(result.threshold_exceeded);
        assert_eq!(result.above_threshold.len(), 1);
        assert_eq!(result.above_threshold[0].vulnerabilities().len(), 1); // Critical only
        assert_eq!(result.below_threshold.len(), 1);
        assert_eq!(result.below_threshold[0].vulnerabilities().len(), 1); // High only
    }

    #[test]
    fn test_threshold_cvss() {
        let vuln_low = create_vulnerability("CVE-2024-001", Some(3.0), Severity::Low);
        let vuln_high = create_vulnerability("CVE-2024-002", Some(7.5), Severity::High);
        let vuln_critical = create_vulnerability("CVE-2024-003", Some(9.8), Severity::Critical);
        let pkg =
            create_package_vulnerabilities("test-pkg", vec![vuln_low, vuln_high, vuln_critical]);

        let result = VulnerabilityChecker::check(vec![pkg], ThresholdConfig::Cvss(7.0), &[]);

        assert!(result.threshold_exceeded);
        assert_eq!(result.above_threshold.len(), 1);
        assert_eq!(result.above_threshold[0].vulnerabilities().len(), 2); // 7.5 and 9.8
        assert_eq!(result.below_threshold.len(), 1);
        assert_eq!(result.below_threshold[0].vulnerabilities().len(), 1); // 3.0
    }

    #[test]
    fn test_threshold_cvss_na_excluded() {
        let vuln_with_cvss = create_vulnerability("CVE-2024-001", Some(9.0), Severity::Critical);
        let vuln_without_cvss = create_vulnerability("CVE-2024-002", None, Severity::High);
        let pkg =
            create_package_vulnerabilities("test-pkg", vec![vuln_with_cvss, vuln_without_cvss]);

        let result = VulnerabilityChecker::check(vec![pkg], ThresholdConfig::Cvss(7.0), &[]);

        assert!(result.threshold_exceeded);
        assert_eq!(result.above_threshold.len(), 1);
        assert_eq!(result.above_threshold[0].vulnerabilities().len(), 1); // Only with CVSS
        assert_eq!(result.below_threshold.len(), 1);
        assert_eq!(result.below_threshold[0].vulnerabilities().len(), 1); // N/A excluded
    }

    #[test]
    fn test_no_vulnerabilities_above_threshold() {
        let vuln_low = create_vulnerability("CVE-2024-001", Some(3.0), Severity::Low);
        let pkg = create_package_vulnerabilities("test-pkg", vec![vuln_low]);

        let result =
            VulnerabilityChecker::check(vec![pkg], ThresholdConfig::Severity(Severity::High), &[]);

        assert!(!result.threshold_exceeded);
        assert!(result.above_threshold.is_empty());
        assert_eq!(result.below_threshold.len(), 1);
    }

    #[test]
    fn test_empty_input() {
        let result = VulnerabilityChecker::check(vec![], ThresholdConfig::None, &[]);

        assert!(!result.threshold_exceeded);
        assert!(result.above_threshold.is_empty());
        assert!(result.below_threshold.is_empty());
    }

    #[test]
    fn test_multiple_packages() {
        let vuln1 = create_vulnerability("CVE-2024-001", Some(9.0), Severity::Critical);
        let vuln2 = create_vulnerability("CVE-2024-002", Some(3.0), Severity::Low);
        let pkg1 = create_package_vulnerabilities("pkg-1", vec![vuln1]);
        let pkg2 = create_package_vulnerabilities("pkg-2", vec![vuln2]);

        let result = VulnerabilityChecker::check(
            vec![pkg1, pkg2],
            ThresholdConfig::Severity(Severity::High),
            &[],
        );

        assert!(result.threshold_exceeded);
        assert_eq!(result.above_threshold.len(), 1);
        assert_eq!(result.above_threshold[0].package_name(), "pkg-1");
        assert_eq!(result.below_threshold.len(), 1);
        assert_eq!(result.below_threshold[0].package_name(), "pkg-2");
    }

    #[test]
    fn test_threshold_cvss_boundary() {
        let vuln_at_threshold = create_vulnerability("CVE-2024-001", Some(7.0), Severity::High);
        let vuln_below_threshold =
            create_vulnerability("CVE-2024-002", Some(6.9), Severity::Medium);
        let pkg = create_package_vulnerabilities(
            "test-pkg",
            vec![vuln_at_threshold, vuln_below_threshold],
        );

        let result = VulnerabilityChecker::check(vec![pkg], ThresholdConfig::Cvss(7.0), &[]);

        assert!(result.threshold_exceeded);
        assert_eq!(result.above_threshold[0].vulnerabilities().len(), 1); // 7.0 is >= 7.0
        assert_eq!(result.below_threshold[0].vulnerabilities().len(), 1); // 6.9 is < 7.0
    }

    #[test]
    fn test_actionable_count_single_package() {
        let vuln1 = create_vulnerability("CVE-2024-001", Some(9.0), Severity::Critical);
        let vuln2 = create_vulnerability("CVE-2024-002", Some(8.0), Severity::High);
        let pkg = create_package_vulnerabilities("test-pkg", vec![vuln1, vuln2]);

        let result = VulnerabilityCheckResult {
            above_threshold: vec![pkg],
            below_threshold: vec![],
            threshold_exceeded: true,
        };

        assert_eq!(result.actionable_count(), 2);
    }

    #[test]
    fn test_actionable_count_multiple_packages() {
        let vuln1 = create_vulnerability("CVE-2024-001", Some(9.0), Severity::Critical);
        let vuln2 = create_vulnerability("CVE-2024-002", Some(8.0), Severity::High);
        let vuln3 = create_vulnerability("CVE-2024-003", Some(7.5), Severity::High);
        let pkg1 = create_package_vulnerabilities("pkg-1", vec![vuln1, vuln2]);
        let pkg2 = create_package_vulnerabilities("pkg-2", vec![vuln3]);

        let result = VulnerabilityCheckResult {
            above_threshold: vec![pkg1, pkg2],
            below_threshold: vec![],
            threshold_exceeded: true,
        };

        assert_eq!(result.actionable_count(), 3);
    }

    #[test]
    fn test_actionable_count_empty() {
        let result = VulnerabilityCheckResult {
            above_threshold: vec![],
            below_threshold: vec![],
            threshold_exceeded: false,
        };

        assert_eq!(result.actionable_count(), 0);
    }

    #[test]
    fn test_informational_count_single_package() {
        let vuln1 = create_vulnerability("CVE-2024-001", Some(3.0), Severity::Low);
        let vuln2 = create_vulnerability("CVE-2024-002", Some(2.0), Severity::Low);
        let pkg = create_package_vulnerabilities("test-pkg", vec![vuln1, vuln2]);

        let result = VulnerabilityCheckResult {
            above_threshold: vec![],
            below_threshold: vec![pkg],
            threshold_exceeded: false,
        };

        assert_eq!(result.informational_count(), 2);
    }

    #[test]
    fn test_informational_count_multiple_packages() {
        let vuln1 = create_vulnerability("CVE-2024-001", Some(3.0), Severity::Low);
        let vuln2 = create_vulnerability("CVE-2024-002", Some(5.0), Severity::Medium);
        let vuln3 = create_vulnerability("CVE-2024-003", Some(4.0), Severity::Medium);
        let pkg1 = create_package_vulnerabilities("pkg-1", vec![vuln1]);
        let pkg2 = create_package_vulnerabilities("pkg-2", vec![vuln2, vuln3]);

        let result = VulnerabilityCheckResult {
            above_threshold: vec![],
            below_threshold: vec![pkg1, pkg2],
            threshold_exceeded: false,
        };

        assert_eq!(result.informational_count(), 3);
    }

    #[test]
    fn test_actionable_package_count() {
        let vuln1 = create_vulnerability("CVE-2024-001", Some(9.0), Severity::Critical);
        let vuln2 = create_vulnerability("CVE-2024-002", Some(8.0), Severity::High);
        let pkg1 = create_package_vulnerabilities("pkg-1", vec![vuln1]);
        let pkg2 = create_package_vulnerabilities("pkg-2", vec![vuln2]);

        let result = VulnerabilityCheckResult {
            above_threshold: vec![pkg1, pkg2],
            below_threshold: vec![],
            threshold_exceeded: true,
        };

        assert_eq!(result.above_threshold.len(), 2);
    }

    #[test]
    fn test_actionable_package_count_empty() {
        let result = VulnerabilityCheckResult {
            above_threshold: vec![],
            below_threshold: vec![],
            threshold_exceeded: false,
        };

        assert_eq!(result.above_threshold.len(), 0);
    }

    #[test]
    fn test_informational_package_count() {
        let vuln1 = create_vulnerability("CVE-2024-001", Some(3.0), Severity::Low);
        let vuln2 = create_vulnerability("CVE-2024-002", Some(4.0), Severity::Medium);
        let vuln3 = create_vulnerability("CVE-2024-003", Some(2.0), Severity::Low);
        let pkg1 = create_package_vulnerabilities("pkg-1", vec![vuln1]);
        let pkg2 = create_package_vulnerabilities("pkg-2", vec![vuln2]);
        let pkg3 = create_package_vulnerabilities("pkg-3", vec![vuln3]);

        let result = VulnerabilityCheckResult {
            above_threshold: vec![],
            below_threshold: vec![pkg1, pkg2, pkg3],
            threshold_exceeded: false,
        };

        assert_eq!(result.below_threshold.len(), 3);
    }

    #[test]
    fn test_semantic_methods_with_mixed_result() {
        let vuln_critical = create_vulnerability("CVE-2024-001", Some(9.0), Severity::Critical);
        let vuln_high = create_vulnerability("CVE-2024-002", Some(8.0), Severity::High);
        let vuln_low = create_vulnerability("CVE-2024-003", Some(3.0), Severity::Low);
        let vuln_medium = create_vulnerability("CVE-2024-004", Some(5.0), Severity::Medium);

        let above_pkg =
            create_package_vulnerabilities("critical-pkg", vec![vuln_critical, vuln_high]);
        let below_pkg1 = create_package_vulnerabilities("low-pkg", vec![vuln_low]);
        let below_pkg2 = create_package_vulnerabilities("medium-pkg", vec![vuln_medium]);

        let result = VulnerabilityCheckResult {
            above_threshold: vec![above_pkg],
            below_threshold: vec![below_pkg1, below_pkg2],
            threshold_exceeded: true,
        };

        assert!(!result.above_threshold.is_empty());
        assert!(!result.below_threshold.is_empty());
        assert_eq!(result.actionable_count(), 2);
        assert_eq!(result.informational_count(), 2);
        assert_eq!(result.above_threshold.len(), 1);
        assert_eq!(result.below_threshold.len(), 2);
    }

    // Tests for CVE ignore filtering

    #[test]
    fn test_ignore_single_cve() {
        let vuln1 = create_vulnerability("CVE-2024-001", Some(9.0), Severity::Critical);
        let vuln2 = create_vulnerability("CVE-2024-002", Some(7.5), Severity::High);
        let pkg = create_package_vulnerabilities("test-pkg", vec![vuln1, vuln2]);

        let ignore = vec![IgnoreCve {
            id: "CVE-2024-001".to_string(),
            reason: Some("False positive".to_string()),
        }];

        let result = VulnerabilityChecker::check(vec![pkg], ThresholdConfig::None, &ignore);

        // Only CVE-2024-002 should remain
        assert!(result.threshold_exceeded);
        assert_eq!(result.above_threshold.len(), 1);
        assert_eq!(result.above_threshold[0].vulnerabilities().len(), 1);
        assert_eq!(
            result.above_threshold[0].vulnerabilities()[0].id(),
            "CVE-2024-002"
        );
    }

    #[test]
    fn test_ignore_multiple_cves() {
        let vuln1 = create_vulnerability("CVE-2024-001", Some(9.0), Severity::Critical);
        let vuln2 = create_vulnerability("CVE-2024-002", Some(7.5), Severity::High);
        let vuln3 = create_vulnerability("CVE-2024-003", Some(3.0), Severity::Low);
        let pkg = create_package_vulnerabilities("test-pkg", vec![vuln1, vuln2, vuln3]);

        let ignore = vec![
            IgnoreCve {
                id: "CVE-2024-001".to_string(),
                reason: None,
            },
            IgnoreCve {
                id: "CVE-2024-002".to_string(),
                reason: Some("Accepted risk".to_string()),
            },
        ];

        let result = VulnerabilityChecker::check(vec![pkg], ThresholdConfig::None, &ignore);

        // Only CVE-2024-003 should remain
        assert!(result.threshold_exceeded);
        assert_eq!(result.above_threshold.len(), 1);
        assert_eq!(result.above_threshold[0].vulnerabilities().len(), 1);
        assert_eq!(
            result.above_threshold[0].vulnerabilities()[0].id(),
            "CVE-2024-003"
        );
    }

    #[test]
    fn test_ignore_cve_with_reason() {
        let vuln = create_vulnerability("CVE-2024-001", Some(9.0), Severity::Critical);
        let pkg = create_package_vulnerabilities("test-pkg", vec![vuln]);

        let ignore = vec![IgnoreCve {
            id: "CVE-2024-001".to_string(),
            reason: Some("Code path not reachable".to_string()),
        }];

        let result = VulnerabilityChecker::check(vec![pkg], ThresholdConfig::None, &ignore);

        // All vulnerabilities ignored, threshold should NOT be exceeded
        assert!(!result.threshold_exceeded);
        assert!(result.above_threshold.is_empty());
        assert!(result.below_threshold.is_empty());
    }

    #[test]
    fn test_ignore_cve_no_match() {
        let vuln = create_vulnerability("CVE-2024-001", Some(9.0), Severity::Critical);
        let pkg = create_package_vulnerabilities("test-pkg", vec![vuln]);

        let ignore = vec![IgnoreCve {
            id: "CVE-2024-999".to_string(),
            reason: None,
        }];

        let result = VulnerabilityChecker::check(vec![pkg], ThresholdConfig::None, &ignore);

        // No CVE matched, so CVE-2024-001 should still be present
        assert!(result.threshold_exceeded);
        assert_eq!(result.above_threshold.len(), 1);
        assert_eq!(result.above_threshold[0].vulnerabilities().len(), 1);
    }

    #[test]
    fn test_ignore_cves_empty_list() {
        let vuln = create_vulnerability("CVE-2024-001", Some(9.0), Severity::Critical);
        let pkg = create_package_vulnerabilities("test-pkg", vec![vuln]);

        let result = VulnerabilityChecker::check(vec![pkg], ThresholdConfig::None, &[]);

        // Empty ignore list should be a no-op
        assert!(result.threshold_exceeded);
        assert_eq!(result.above_threshold.len(), 1);
    }

    #[test]
    fn test_ignore_all_cves_in_package_removes_package() {
        let vuln1 = create_vulnerability("CVE-2024-001", Some(9.0), Severity::Critical);
        let vuln2 = create_vulnerability("CVE-2024-002", Some(7.5), Severity::High);
        let pkg = create_package_vulnerabilities("test-pkg", vec![vuln1, vuln2]);

        let ignore = vec![
            IgnoreCve {
                id: "CVE-2024-001".to_string(),
                reason: None,
            },
            IgnoreCve {
                id: "CVE-2024-002".to_string(),
                reason: None,
            },
        ];

        let result = VulnerabilityChecker::check(vec![pkg], ThresholdConfig::None, &ignore);

        // All CVEs ignored → no packages in result
        assert!(!result.threshold_exceeded);
        assert!(result.above_threshold.is_empty());
        assert!(result.below_threshold.is_empty());
    }

    #[test]
    fn test_ignore_cve_case_sensitive() {
        let vuln = create_vulnerability("CVE-2024-001", Some(9.0), Severity::Critical);
        let pkg = create_package_vulnerabilities("test-pkg", vec![vuln]);

        // Lowercase should NOT match
        let ignore = vec![IgnoreCve {
            id: "cve-2024-001".to_string(),
            reason: None,
        }];

        let result = VulnerabilityChecker::check(vec![pkg], ThresholdConfig::None, &ignore);

        // Case mismatch → no filtering applied
        assert!(result.threshold_exceeded);
        assert_eq!(result.above_threshold.len(), 1);
    }

    #[test]
    fn test_ignore_cve_does_not_trigger_threshold() {
        let vuln_critical = create_vulnerability("CVE-2024-001", Some(9.8), Severity::Critical);
        let vuln_low = create_vulnerability("CVE-2024-002", Some(3.0), Severity::Low);
        let pkg = create_package_vulnerabilities("test-pkg", vec![vuln_critical, vuln_low]);

        // Ignore the critical CVE
        let ignore = vec![IgnoreCve {
            id: "CVE-2024-001".to_string(),
            reason: Some("False positive".to_string()),
        }];

        let result = VulnerabilityChecker::check(
            vec![pkg],
            ThresholdConfig::Severity(Severity::High),
            &ignore,
        );

        // Only Low remains, which is below High threshold
        assert!(!result.threshold_exceeded);
        assert!(result.above_threshold.is_empty());
        assert_eq!(result.below_threshold.len(), 1);
    }

    #[test]
    fn test_ignore_cve_across_multiple_packages() {
        let vuln1 = create_vulnerability("CVE-2024-001", Some(9.0), Severity::Critical);
        let vuln2 = create_vulnerability("CVE-2024-001", Some(9.0), Severity::Critical);
        let vuln3 = create_vulnerability("CVE-2024-002", Some(7.5), Severity::High);
        let pkg1 = create_package_vulnerabilities("pkg-1", vec![vuln1]);
        let pkg2 = create_package_vulnerabilities("pkg-2", vec![vuln2, vuln3]);

        let ignore = vec![IgnoreCve {
            id: "CVE-2024-001".to_string(),
            reason: None,
        }];

        let result = VulnerabilityChecker::check(vec![pkg1, pkg2], ThresholdConfig::None, &ignore);

        // pkg-1 should be completely removed (only had CVE-2024-001)
        // pkg-2 should remain with only CVE-2024-002
        assert!(result.threshold_exceeded);
        assert_eq!(result.above_threshold.len(), 1);
        assert_eq!(result.above_threshold[0].package_name(), "pkg-2");
        assert_eq!(result.above_threshold[0].vulnerabilities().len(), 1);
        assert_eq!(
            result.above_threshold[0].vulnerabilities()[0].id(),
            "CVE-2024-002"
        );
    }
}