Skip to content

Commit 789a2fb

Browse files
committed
test: verify permissions bits are preserved when unpacking
This is not secure and will be fixed in the next commit.
1 parent 336b443 commit 789a2fb

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/testsuite/registry.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3403,3 +3403,58 @@ Caused by:
34033403
Please slow down
34043404
").run();
34053405
}
3406+
3407+
#[cfg(unix)]
3408+
#[cargo_test]
3409+
fn set_mask_during_unpacking() {
3410+
use std::os::unix::fs::MetadataExt;
3411+
3412+
Package::new("bar", "1.0.0")
3413+
.file_with_mode("example.sh", 0o777, "#!/bin/sh")
3414+
.file_with_mode("src/lib.rs", 0o666, "")
3415+
.publish();
3416+
3417+
let p = project()
3418+
.file(
3419+
"Cargo.toml",
3420+
r#"
3421+
[package]
3422+
name = "foo"
3423+
version = "0.1.0"
3424+
3425+
[dependencies]
3426+
bar = "1.0"
3427+
"#,
3428+
)
3429+
.file("src/lib.rs", "")
3430+
.build();
3431+
3432+
p.cargo("fetch")
3433+
.with_stderr(
3434+
"\
3435+
[UPDATING] `dummy-registry` index
3436+
[DOWNLOADING] crates ...
3437+
[DOWNLOADED] bar v1.0.0 (registry `dummy-registry`)
3438+
",
3439+
)
3440+
.run();
3441+
let src_file_path = |path: &str| {
3442+
glob::glob(
3443+
paths::home()
3444+
.join(".cargo/registry/src/*/bar-1.0.0/")
3445+
.join(path)
3446+
.to_str()
3447+
.unwrap(),
3448+
)
3449+
.unwrap()
3450+
.next()
3451+
.unwrap()
3452+
.unwrap()
3453+
};
3454+
3455+
// Assuming umask is `0o022`.
3456+
let metadata = fs::metadata(src_file_path("src/lib.rs")).unwrap();
3457+
assert_eq!(metadata.mode() & 0o777, 0o666);
3458+
let metadata = fs::metadata(src_file_path("example.sh")).unwrap();
3459+
assert_eq!(metadata.mode() & 0o777, 0o777);
3460+
}

0 commit comments

Comments
 (0)