Skip to content

Commit

Permalink
fix: don't prompt when using Deno.permissions.request with `--no-pr…
Browse files Browse the repository at this point in the history
…ompt` (#25811)
  • Loading branch information
lowlighter authored Oct 3, 2024
1 parent 19a9990 commit da7edf1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion runtime/permissions/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,9 @@ impl<TQuery: QueryDescriptor> UnaryPermission<TQuery> {
if state != PermissionState::Prompt {
return state;
}
if !self.prompt {
return PermissionState::Denied;
}
let mut message = String::with_capacity(40);
message.push_str(&format!("{} access", TQuery::flag_name()));
if let Some(desc) = desc {
Expand Down Expand Up @@ -3906,7 +3909,8 @@ mod tests {
fn test_request() {
set_prompter(Box::new(TestPrompter));
let parser = TestPermissionDescriptorParser;
let mut perms: Permissions = Permissions::none_without_prompt();
let mut perms: Permissions = Permissions::none_with_prompt();
let mut perms_no_prompt: Permissions = Permissions::none_without_prompt();
let read_query =
|path: &str| parser.parse_path_query(path).unwrap().into_read();
let write_query =
Expand Down Expand Up @@ -3955,6 +3959,7 @@ mod tests {
assert_eq!(perms.run.query(None), PermissionState::Prompt);
prompt_value.set(false);
assert_eq!(perms.run.request(Some(&run_query)), PermissionState::Granted);
assert_eq!(perms_no_prompt.read.request(Some(&read_query("/foo"))), PermissionState::Denied);
};
}

Expand Down
16 changes: 16 additions & 0 deletions tests/integration/run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3512,6 +3512,22 @@ itest!(no_prompt_flag {
output_str: Some(""),
});

#[test]
fn permission_request_with_no_prompt() {
TestContext::default()
.new_command()
.env("NO_COLOR", "1")
.args_vec([
"run",
"--quiet",
"--no-prompt",
"run/permission_request_no_prompt.ts",
])
.with_pty(|mut console| {
console.expect("PermissionStatus { state: \"denied\", onchange: null }");
});
}

#[test]
fn deno_no_prompt_environment_variable() {
let output = util::deno_cmd()
Expand Down
1 change: 1 addition & 0 deletions tests/testdata/run/permission_request_no_prompt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(await Deno.permissions.request({ name: "read" }));

0 comments on commit da7edf1

Please sign in to comment.