use extrasafe::*;
use extrasafe::builtins::{danger_zone::Threads, Networking, SystemIO};
fn main() {
let runtime = tokio::runtime::Builder::new_current_thread()
.worker_threads(1)
.enable_all()
.build().unwrap();
let client = reqwest::Client::new();
let ctx = SafetyContext::new()
.enable(Networking::nothing()
.allow_start_udp_servers().yes_really()
.allow_start_tcp_clients()
).unwrap()
.enable(Threads::nothing()
.allow_create()
).unwrap();
#[cfg(feature = "landlock")]
let ctx = ctx.enable(
SystemIO::nothing()
.allow_dns_files()
.allow_ssl_files()
).unwrap();
#[cfg(not(feature = "landlock"))]
let ctx = ctx.enable(
SystemIO::nothing()
.allow_open_readonly()
.allow_read()
.allow_metadata()
.allow_close(),
).unwrap();
ctx.apply_to_current_thread()
.unwrap();
runtime.block_on(async {
let resp = client.get("https://example.org").send().await.unwrap();
let res = resp.text().await;
assert!(
res.is_ok(),
"failed getting example.org response: {:?}",
res.unwrap_err()
);
let text = res.unwrap();
println!("first 10 bytes of response from example.org {}", &text[..10]);
});
}
#[test]
fn run_main() {
main();
}