1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

fix(cli): Only set allow net flag for deno serve if not already allowed all (#25743)

Fixes #25740
This commit is contained in:
Nathan Whitaker 2024-09-19 15:03:57 -07:00 committed by GitHub
parent dad5678baa
commit 6a04bbe076
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4738,7 +4738,10 @@ fn serve_parse(
format!("{host}:{port}")
}])?;
match &mut flags.permissions.allow_net {
None => flags.permissions.allow_net = Some(allowed),
None if !flags.permissions.allow_all => {
flags.permissions.allow_net = Some(allowed)
}
None => {}
Some(v) => {
if !v.is_empty() {
v.extend(allowed);
@ -10747,6 +10750,31 @@ mod tests {
);
}
#[test]
fn serve_with_allow_all() {
let r = flags_from_vec(svec!["deno", "serve", "--allow-all", "./main.ts"]);
let flags = r.unwrap();
assert_eq!(
&flags,
&Flags {
subcommand: DenoSubcommand::Serve(ServeFlags::new_default(
"./main.ts".into(),
8000,
"0.0.0.0"
)),
permissions: PermissionFlags {
allow_all: true,
allow_net: None,
..Default::default()
},
code_cache_enabled: true,
..Default::default()
}
);
// just make sure this doesn't panic
let _ = flags.permissions.to_options();
}
#[test]
fn escape_and_split_commas_test() {
assert_eq!(escape_and_split_commas("foo".to_string()).unwrap(), ["foo"]);