fix: make --allow-env stronger that --deny-env (#29079)

This commit is contained in:
Bartek Iwańczuk 2025-04-28 19:28:38 +02:00 committed by GitHub
parent e0813f2255
commit f2ae7a19f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 1 deletions

View file

@ -1944,7 +1944,7 @@ impl UnaryPermission<EnvQueryDescriptor> {
pub fn check_all(&mut self) -> Result<(), PermissionDeniedError> { pub fn check_all(&mut self) -> Result<(), PermissionDeniedError> {
skip_check_if_is_permission_fully_granted!(self); skip_check_if_is_permission_fully_granted!(self);
self.check_desc(None, false, None) self.check_desc(None, true, None)
} }
} }
@ -5263,4 +5263,21 @@ mod tests {
); );
} }
} }
#[test]
fn test_env_check_all() {
set_prompter(Box::new(TestPrompter));
let parser = TestPermissionDescriptorParser;
let mut perms = Permissions::from_options(
&parser,
&PermissionsOptions {
allow_env: Some(vec![]),
deny_env: Some(svec!["FOO"]),
..Default::default()
},
)
.unwrap();
assert!(perms.env.check_all().is_err());
}
} }

View file

@ -0,0 +1,8 @@
{
"args": "run --allow-env --deny-env=FOOBAR main.ts",
"output": "main.out",
"exitCode": 1,
"envs": {
"FOOBAR": "FOOBAR"
}
}

View file

@ -0,0 +1,4 @@
error: Uncaught (in promise) NotCapable: Requires env access, run again with the --allow-env flag
console.log(Deno.env.toObject());
^
[WILDCARD]main.ts:1:22

View file

@ -0,0 +1 @@
console.log(Deno.env.toObject());