1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -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:
Asher Gomez 2023-01-04 07:50:14 +11:00 committed by Bartek Iwańczuk
parent 43e8b51316
commit 63ca68d058
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
2 changed files with 24 additions and 29 deletions

View file

@ -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() {

View file

@ -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));