mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
fix: add permission name when accessing a special file errors (#25085)
This commit is contained in:
parent
0f2e47dd69
commit
ee2b6899a1
2 changed files with 35 additions and 3 deletions
|
@ -89,9 +89,9 @@ impl FsPermissions for deno_permissions::PermissionsContainer {
|
||||||
api_name: &str,
|
api_name: &str,
|
||||||
) -> Result<Cow<'a, Path>, FsError> {
|
) -> Result<Cow<'a, Path>, FsError> {
|
||||||
if resolved {
|
if resolved {
|
||||||
self.check_special_file(path, api_name).map_err(|_| {
|
self
|
||||||
std::io::Error::from(std::io::ErrorKind::PermissionDenied)
|
.check_special_file(path, api_name)
|
||||||
})?;
|
.map_err(FsError::PermissionDenied)?;
|
||||||
return Ok(Cow::Borrowed(path));
|
return Ok(Cow::Borrowed(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
assert,
|
assert,
|
||||||
assertEquals,
|
assertEquals,
|
||||||
assertNotEquals,
|
assertNotEquals,
|
||||||
|
assertStringIncludes,
|
||||||
assertThrows,
|
assertThrows,
|
||||||
} from "./test_util.ts";
|
} from "./test_util.ts";
|
||||||
|
|
||||||
|
@ -196,6 +197,37 @@ Deno.test({ permissions: { read: false } }, function execPathPerm() {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test(async function execPathPerm() {
|
||||||
|
if (Deno.build.os !== "linux") return;
|
||||||
|
// This is hack to bypass a bug in deno test runner,
|
||||||
|
// Currently if you specify {read: true} permission, it will stil pass --allow-all (tests are run with deno test --allow-all) implicitly, so this test won't work
|
||||||
|
// The workaround is to spawn a deno executable with the needed permissions
|
||||||
|
// TODO(#25085): remove this hack when the bug is fixed
|
||||||
|
const cmd = new Deno.Command(Deno.execPath(), {
|
||||||
|
args: ["run", "--allow-read", "-"],
|
||||||
|
stdin: "piped",
|
||||||
|
stderr: "piped",
|
||||||
|
}).spawn();
|
||||||
|
const stdinWriter = cmd.stdin.getWriter();
|
||||||
|
await stdinWriter
|
||||||
|
.write(
|
||||||
|
new TextEncoder().encode('Deno.readTextFileSync("/proc/net/dev")'),
|
||||||
|
);
|
||||||
|
await stdinWriter.close();
|
||||||
|
await cmd.status;
|
||||||
|
|
||||||
|
const stderrReder = cmd.stderr.getReader();
|
||||||
|
const error = await stderrReder
|
||||||
|
.read()
|
||||||
|
.then((r) => new TextDecoder().decode(r.value));
|
||||||
|
await stderrReder.cancel();
|
||||||
|
|
||||||
|
assertStringIncludes(
|
||||||
|
error,
|
||||||
|
`PermissionDenied: Requires all access to "/proc/net/dev", run again with the --allow-all flag`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
Deno.test(
|
Deno.test(
|
||||||
{ permissions: { sys: ["loadavg"] } },
|
{ permissions: { sys: ["loadavg"] } },
|
||||||
function loadavgSuccess() {
|
function loadavgSuccess() {
|
||||||
|
|
Loading…
Reference in a new issue