mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
fix: install shim with --allow-all
should not output each permission individually (#13325)
This commit is contained in:
parent
c487b7ed54
commit
ea86c0818a
3 changed files with 46 additions and 0 deletions
|
@ -214,6 +214,7 @@ pub struct Flags {
|
|||
pub argv: Vec<String>,
|
||||
pub subcommand: DenoSubcommand,
|
||||
|
||||
pub allow_all: bool,
|
||||
pub allow_env: Option<Vec<String>>,
|
||||
pub allow_hrtime: bool,
|
||||
pub allow_net: Option<Vec<String>>,
|
||||
|
@ -269,6 +270,11 @@ impl Flags {
|
|||
pub fn to_permission_args(&self) -> Vec<String> {
|
||||
let mut args = vec![];
|
||||
|
||||
if self.allow_all {
|
||||
args.push("--allow-all".to_string());
|
||||
return args;
|
||||
}
|
||||
|
||||
match &self.allow_read {
|
||||
Some(read_allowlist) if read_allowlist.is_empty() => {
|
||||
args.push("--allow-read".to_string());
|
||||
|
@ -2252,6 +2258,7 @@ fn permission_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
|
|||
flags.allow_hrtime = true;
|
||||
}
|
||||
if matches.is_present("allow-all") {
|
||||
flags.allow_all = true;
|
||||
flags.allow_read = Some(vec![]);
|
||||
flags.allow_env = Some(vec![]);
|
||||
flags.allow_net = Some(vec![]);
|
||||
|
@ -2647,6 +2654,7 @@ mod tests {
|
|||
subcommand: DenoSubcommand::Run(RunFlags {
|
||||
script: "gist.ts".to_string(),
|
||||
}),
|
||||
allow_all: true,
|
||||
allow_net: Some(vec![]),
|
||||
allow_env: Some(vec![]),
|
||||
allow_run: Some(vec![]),
|
||||
|
|
|
@ -729,6 +729,43 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn install_allow_all() {
|
||||
let temp_dir = TempDir::new().expect("tempdir fail");
|
||||
let bin_dir = temp_dir.path().join("bin");
|
||||
std::fs::create_dir(&bin_dir).unwrap();
|
||||
|
||||
install(
|
||||
Flags {
|
||||
allow_all: true,
|
||||
..Flags::default()
|
||||
},
|
||||
InstallFlags {
|
||||
module_url: "http://localhost:4545/echo_server.ts".to_string(),
|
||||
args: vec![],
|
||||
name: Some("echo_test".to_string()),
|
||||
root: Some(temp_dir.path().to_path_buf()),
|
||||
force: false,
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut file_path = bin_dir.join("echo_test");
|
||||
if cfg!(windows) {
|
||||
file_path = file_path.with_extension("cmd");
|
||||
}
|
||||
|
||||
let content = fs::read_to_string(file_path).unwrap();
|
||||
if cfg!(windows) {
|
||||
assert!(content.contains(
|
||||
r#""run" "--allow-all" "http://localhost:4545/echo_server.ts""#
|
||||
));
|
||||
} else {
|
||||
assert!(content
|
||||
.contains(r#"run --allow-all 'http://localhost:4545/echo_server.ts'"#));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn install_local_module() {
|
||||
let temp_dir = TempDir::new().expect("tempdir fail");
|
||||
|
|
|
@ -204,6 +204,7 @@ pub fn compile_to_runtime_flags(
|
|||
subcommand: DenoSubcommand::Run(RunFlags {
|
||||
script: "placeholder".to_string(),
|
||||
}),
|
||||
allow_all: flags.allow_all,
|
||||
allow_env: flags.allow_env,
|
||||
allow_hrtime: flags.allow_hrtime,
|
||||
allow_net: flags.allow_net,
|
||||
|
|
Loading…
Reference in a new issue