mirror of
https://github.com/denoland/deno.git
synced 2024-12-26 00:59:24 -05:00
fix(permissions): lock stdio streams when prompt is shown (#17392)
This commit changes permission prompt to lock stdio streams when prompt is shown.
This commit is contained in:
parent
9c4327f9d1
commit
0e5c7404f2
4 changed files with 31 additions and 0 deletions
|
@ -3723,3 +3723,23 @@ fn file_fetcher_preserves_permissions() {
|
||||||
assert_contains!(output, "true");
|
assert_contains!(output, "true");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn stdio_streams_are_locked_in_permission_prompt() {
|
||||||
|
let _guard = util::http_server();
|
||||||
|
util::with_pty(&[
|
||||||
|
"repl",
|
||||||
|
"--allow-read=run/stdio_streams_are_locked_in_permission_prompt/worker.js,run/stdio_streams_are_locked_in_permission_prompt/text.txt"
|
||||||
|
], |mut console| {
|
||||||
|
console.write_line(
|
||||||
|
r#"new Worker(`${Deno.cwd()}/run/stdio_streams_are_locked_in_permissions_prompt/worker.js`, { type: "module" });
|
||||||
|
await Deno.writeTextFile("./run/stdio_streams_are_locked_in_permissions_prompt/text.txt", "some code");"#,
|
||||||
|
);
|
||||||
|
console.write_line("y");
|
||||||
|
console.write_line("close();");
|
||||||
|
let output = console.read_all_output();
|
||||||
|
|
||||||
|
let expected_output = r#"\x1b[1;1H\x1b[0JAre you sure you want to continue?"#;
|
||||||
|
assert_eq!(output, expected_output);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
1
cli/tests/testdata/run/stdio_streams_are_locked_in_permission_prompt/text.txt
vendored
Normal file
1
cli/tests/testdata/run/stdio_streams_are_locked_in_permission_prompt/text.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
\x1B[2J\x1B[1;1H
|
2
cli/tests/testdata/run/stdio_streams_are_locked_in_permission_prompt/worker.js
vendored
Normal file
2
cli/tests/testdata/run/stdio_streams_are_locked_in_permission_prompt/worker.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
console.clear();
|
||||||
|
console.log("Are you sure you want to continue?");
|
|
@ -192,6 +192,11 @@ impl PermissionPrompter for TtyPrompter {
|
||||||
return PromptResponse::Deny; // don't grant permission if this fails
|
return PromptResponse::Deny; // don't grant permission if this fails
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lock stdio streams, so no other output is written while the prompt is
|
||||||
|
// displayed.
|
||||||
|
let _stdout_guard = std::io::stdout().lock();
|
||||||
|
let _stderr_guard = std::io::stderr().lock();
|
||||||
|
|
||||||
// print to stderr so that if stdout is piped this is still displayed.
|
// print to stderr so that if stdout is piped this is still displayed.
|
||||||
const OPTS: &str = "[y/n] (y = yes, allow; n = no, deny)";
|
const OPTS: &str = "[y/n] (y = yes, allow; n = no, deny)";
|
||||||
eprint!("{} ┌ ", PERMISSION_EMOJI);
|
eprint!("{} ┌ ", PERMISSION_EMOJI);
|
||||||
|
@ -238,6 +243,9 @@ impl PermissionPrompter for TtyPrompter {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
drop(_stdout_guard);
|
||||||
|
drop(_stderr_guard);
|
||||||
|
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue