mirror of
https://github.com/usestrix/firewall.git
synced 2026-11-09 05:19:35 -10:00
31 lines
1.1 KiB
Rust
31 lines
1.1 KiB
Rust
use firewall::policies::filters::osv::mal_ids;
|
|
use firewall::policies::screen;
|
|
use firewall::Firewall;
|
|
use rama::rt::blocking::Runtime;
|
|
use serde_json::json;
|
|
|
|
#[test]
|
|
#[ignore = "queries api.osv.dev"]
|
|
fn osv_separates_a_flagged_crate_from_a_clean_one() {
|
|
let runtime = Runtime::try_new().expect("runtime");
|
|
runtime.block_on(async {
|
|
let firewall = Firewall::default();
|
|
let flagged = screen("https://static.crates.io/crates/rustdecimal/1.0.0", &firewall).await;
|
|
assert!(flagged.unwrap_or_default().contains("MAL-2022-1"));
|
|
assert_eq!(screen("https://static.crates.io/crates/serde/1.0.200", &firewall).await, None);
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn each_mal_id_is_reported_once_from_ids_and_aliases() {
|
|
let body = json!({"vulns": [
|
|
{"id": "MAL-2022-1", "aliases": ["GHSA-x"]},
|
|
{"id": "RUSTSEC-2022-0005"},
|
|
{"id": "MAL-2022-1"},
|
|
{"id": "GHSA-y", "aliases": ["MAL-2023-9"]},
|
|
]});
|
|
assert_eq!(mal_ids(&body), vec!["MAL-2022-1", "MAL-2023-9"]);
|
|
assert!(mal_ids(&json!({"vulns": [{"id": "RUSTSEC-2022-0005"}]})).is_empty());
|
|
assert!(mal_ids(&json!({})).is_empty());
|
|
}
|