1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -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 GitHub
parent deed07e1d9
commit 1b001d1b18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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));