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`
  • Loading branch information
lowlighter committed Sep 22, 2024
1 parent ef3e4a8 commit 5cfd12e
Show file tree
Hide file tree
Showing 4 changed files with 12 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 @@ -3438,7 +3441,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 @@ -3486,6 +3490,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
4 changes: 4 additions & 0 deletions tests/specs/permission/request_no_prompt/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"args": "run --no-prompt main.ts",
"output": "main.out"
}
1 change: 1 addition & 0 deletions tests/specs/permission/request_no_prompt/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PermissionStatus { state: "denied", onchange: null }
1 change: 1 addition & 0 deletions tests/specs/permission/request_no_prompt/main.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 5cfd12e

Please sign in to comment.