Expand $PWD in config paths to the launch directory
This commit is contained in:
@@ -741,6 +741,79 @@ fn build_tilde_expansion_in_config_paths() {
|
||||
assert_eq!(config.extra_rw, vec![same_bind(Path::new(&home))]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_pwd_expands_to_current_dir_in_config_paths() {
|
||||
let cwd = std::env::current_dir().unwrap();
|
||||
let file_config = FileConfig {
|
||||
options: Options {
|
||||
rw: vec!["$PWD".into()],
|
||||
ro: vec!["$PWD/src".into()],
|
||||
..Options::default()
|
||||
},
|
||||
..FileConfig::default()
|
||||
};
|
||||
let config = build(args_with_command(), Some(file_config)).unwrap();
|
||||
assert_eq!(config.extra_rw, vec![same_bind(&cwd)]);
|
||||
assert_eq!(config.extra_ro, vec![same_bind(&cwd.join("src"))]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_braced_pwd_expands_to_current_dir_in_config_paths() {
|
||||
let cwd = std::env::current_dir().unwrap();
|
||||
let file_config = FileConfig {
|
||||
options: Options {
|
||||
rw: vec!["${PWD}".into()],
|
||||
ro: vec!["${PWD}/src".into()],
|
||||
..Options::default()
|
||||
},
|
||||
..FileConfig::default()
|
||||
};
|
||||
let config = build(args_with_command(), Some(file_config)).unwrap();
|
||||
assert_eq!(config.extra_rw, vec![same_bind(&cwd)]);
|
||||
assert_eq!(config.extra_ro, vec![same_bind(&cwd.join("src"))]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_pwd_expands_in_target() {
|
||||
let home = std::env::var("HOME").unwrap();
|
||||
let cwd = std::env::current_dir().unwrap();
|
||||
let file_config = FileConfig {
|
||||
options: Options {
|
||||
rw: vec!["~/:$PWD/mounted".into()],
|
||||
..Options::default()
|
||||
},
|
||||
..FileConfig::default()
|
||||
};
|
||||
let config = build(args_with_command(), Some(file_config)).unwrap();
|
||||
assert_eq!(
|
||||
config.extra_rw,
|
||||
vec![BindSpec {
|
||||
source: PathBuf::from(&home),
|
||||
target: cwd.join("mounted"),
|
||||
}]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_other_variables_in_config_paths_rejected() {
|
||||
for raw in ["$HOME/x", "${HOME}", "$PWDX", "${PWD}x", "$"] {
|
||||
let file_config = FileConfig {
|
||||
options: Options {
|
||||
rw: vec![raw.into()],
|
||||
..Options::default()
|
||||
},
|
||||
..FileConfig::default()
|
||||
};
|
||||
assert!(
|
||||
matches!(
|
||||
build(args_with_command(), Some(file_config)),
|
||||
Err(SandboxError::UnsupportedConfigVariable(_))
|
||||
),
|
||||
"{raw} should be rejected"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_preserves_symlinks_in_config_paths() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user