Skip to content

Commit 3b5fbfd

Browse files
test_crates: Verify that pmacro-1 is running in a sandbox
1 parent 914cbe8 commit 3b5fbfd

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

test_crates/cackle.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ build.allow_apis = [
8888
[pkg.pmacro-1]
8989
allow_apis = [
9090
"env",
91+
"fs",
9192
]
9293
allow_proc_macro = true
9394

test_crates/crab-bin/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ pmacro-1 = { path = "../pmacro-1" }
1515
res-1 = { path = "../res-1" }
1616

1717
[features]
18-
crash-if-not-sandboxed = [ "crab-2/crash-if-not-sandboxed" ]
18+
crash-if-not-sandboxed = [
19+
"crab-2/crash-if-not-sandboxed",
20+
"pmacro-1/crash-if-not-sandboxed",
21+
]
1922
foo = []

test_crates/pmacro-1/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ edition = "2021"
77
proc-macro = true
88

99
[dependencies]
10+
[features]
11+
crash-if-not-sandboxed = []

test_crates/pmacro-1/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ use proc_macro::TokenStream;
33

44
#[proc_macro]
55
pub fn create_write_to_file(_item: TokenStream) -> TokenStream {
6+
if cfg!(feature = "crash-if-not-sandboxed")
7+
&& std::fs::write("a.txt", "pmacro-1 wrote this").is_ok()
8+
{
9+
panic!("pmacro-1 running without sandbox (was able to write a.txt)");
10+
}
611
if std::env::var("PWD").as_deref() == Ok("/foo/bar") {
712
println!("This seems unlikely");
813
}

0 commit comments

Comments
 (0)