mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
fix(permissions): process URL
in Deno.FfiPermissionDescriptor.path
for revoke()
and request()
(#17094)
Previously, `Deno.permissions.[revoke|request]()` wouldn't correctly process the `path: URL` when `name` was `ffi`. This change fixes that behaviour and adds a new function, `formDescriptor()`, to ensure `URL` arguments are consistently handled across `Deno.permissions.[query|revoke|request]()`.
This commit is contained in:
parent
43e8b51316
commit
63ca68d058
2 changed files with 24 additions and 29 deletions
|
@ -75,19 +75,14 @@ Deno.test(function permissionStatusIllegalConstructor() {
|
|||
assertEquals(Deno.PermissionStatus.length, 0);
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/denoland/deno/issues/17020
|
||||
Deno.test(async function permissionURL() {
|
||||
await Deno.permissions.query({
|
||||
name: "read",
|
||||
path: new URL(".", import.meta.url),
|
||||
});
|
||||
await Deno.permissions.query({
|
||||
name: "write",
|
||||
path: new URL(".", import.meta.url),
|
||||
});
|
||||
await Deno.permissions.query({
|
||||
name: "run",
|
||||
command: new URL(".", import.meta.url),
|
||||
});
|
||||
const path = new URL(".", import.meta.url);
|
||||
|
||||
await Deno.permissions.query({ name: "read", path });
|
||||
await Deno.permissions.query({ name: "write", path });
|
||||
await Deno.permissions.query({ name: "ffi", path });
|
||||
await Deno.permissions.query({ name: "run", command: path });
|
||||
});
|
||||
|
||||
Deno.test(async function permissionDescriptorValidation() {
|
||||
|
|
|
@ -161,6 +161,20 @@
|
|||
ArrayPrototypeIncludes(permissionNames, desc.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Deno.PermissionDescriptor} desc
|
||||
* @returns {desc is Deno.PermissionDescriptor}
|
||||
*/
|
||||
function formDescriptor(desc) {
|
||||
if (
|
||||
desc.name === "read" || desc.name === "write" || desc.name === "ffi"
|
||||
) {
|
||||
desc.path = pathFromURL(desc.path);
|
||||
} else if (desc.name === "run") {
|
||||
desc.command = pathFromURL(desc.command);
|
||||
}
|
||||
}
|
||||
|
||||
class Permissions {
|
||||
constructor(key = null) {
|
||||
if (key != illegalConstructorKey) {
|
||||
|
@ -177,13 +191,7 @@
|
|||
);
|
||||
}
|
||||
|
||||
if (
|
||||
desc.name === "read" || desc.name === "write" || desc.name === "ffi"
|
||||
) {
|
||||
desc.path = pathFromURL(desc.path);
|
||||
} else if (desc.name === "run") {
|
||||
desc.command = pathFromURL(desc.command);
|
||||
}
|
||||
formDescriptor(desc);
|
||||
|
||||
const state = opQuery(desc);
|
||||
return PromiseResolve(cache(desc, state));
|
||||
|
@ -198,11 +206,7 @@
|
|||
);
|
||||
}
|
||||
|
||||
if (desc.name === "read" || desc.name === "write") {
|
||||
desc.path = pathFromURL(desc.path);
|
||||
} else if (desc.name === "run") {
|
||||
desc.command = pathFromURL(desc.command);
|
||||
}
|
||||
formDescriptor(desc);
|
||||
|
||||
const state = opRevoke(desc);
|
||||
return PromiseResolve(cache(desc, state));
|
||||
|
@ -217,11 +221,7 @@
|
|||
);
|
||||
}
|
||||
|
||||
if (desc.name === "read" || desc.name === "write") {
|
||||
desc.path = pathFromURL(desc.path);
|
||||
} else if (desc.name === "run") {
|
||||
desc.command = pathFromURL(desc.command);
|
||||
}
|
||||
formDescriptor(desc);
|
||||
|
||||
const state = opRequest(desc);
|
||||
return PromiseResolve(cache(desc, state));
|
||||
|
|
Loading…
Reference in a new issue