mirror of
https://github.com/usestrix/firewall.git
synced 2026-11-09 05:19:35 -10:00
* Hold a held-back download open so allowing it lets it through * Allow a held-back package once from the app, releasing the waiting download
28 lines
1.2 KiB
Rust
28 lines
1.2 KiB
Rust
use firewall::blocks::{answer, block};
|
|
use firewall::policies::Package;
|
|
use firewall::Firewall;
|
|
use std::path::Path;
|
|
use std::time::Duration;
|
|
|
|
#[tokio::test]
|
|
async fn allowing_once_releases_the_held_download() {
|
|
let firewall = Firewall::default();
|
|
let config = Path::new("/nonexistent/config.json");
|
|
let pkg = Package { name: "left-pad".into(), version: Some("1.3.0".into()) };
|
|
assert!(!block("npm", &pkg, "age", "is new").await, "held while nothing was asking");
|
|
answer(&firewall, config, "blocks");
|
|
|
|
let held = tokio::spawn(async move { block("npm", &pkg, "age", "is new").await });
|
|
let id = loop {
|
|
let blocks: serde_json::Value = serde_json::from_str(&answer(&firewall, config, "blocks")).unwrap();
|
|
if let Some(id) = blocks[0]["id"].as_u64() {
|
|
break id;
|
|
}
|
|
tokio::time::sleep(Duration::from_millis(10)).await;
|
|
};
|
|
assert_eq!(answer(&firewall, config, &format!("allow-once {id}")), "ok");
|
|
assert!(held.await.unwrap(), "the waiting download goes through");
|
|
assert!(firewall.age_check_lifted("npm", |p| p.name == "left-pad"), "and the rest of the install");
|
|
assert!(!block("npm", &Package { name: "evil".into(), version: None }, "denylist", "is malware").await);
|
|
}
|