2024-02-13 11:22:49 -05:00
|
|
|
import { assertEquals } from "../../../tests/util/std/assert/mod.ts";
|
2021-04-25 17:38:59 -04:00
|
|
|
|
|
|
|
const permissions: Deno.PermissionName[] = [
|
|
|
|
"read",
|
|
|
|
"write",
|
|
|
|
"net",
|
|
|
|
"env",
|
|
|
|
"run",
|
2021-08-06 17:28:10 -04:00
|
|
|
"ffi",
|
2021-04-25 17:38:59 -04:00
|
|
|
"hrtime",
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const name of permissions) {
|
|
|
|
Deno.test({
|
|
|
|
name: `${name} false`,
|
|
|
|
permissions: {
|
|
|
|
[name]: false,
|
|
|
|
},
|
|
|
|
async fn() {
|
2022-03-20 17:46:39 -04:00
|
|
|
for await (const n of permissions) {
|
|
|
|
const status = await Deno.permissions.query({ name: n });
|
|
|
|
assertEquals(status.state, "prompt");
|
|
|
|
}
|
2021-04-25 17:38:59 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: `${name} true`,
|
|
|
|
permissions: {
|
|
|
|
[name]: true,
|
|
|
|
},
|
|
|
|
async fn() {
|
2022-03-20 17:46:39 -04:00
|
|
|
for await (const n of permissions) {
|
|
|
|
const status = await Deno.permissions.query({ name: n });
|
|
|
|
if (n === name) {
|
|
|
|
assertEquals(status.state, "granted");
|
|
|
|
} else {
|
|
|
|
assertEquals(status.state, "prompt");
|
|
|
|
}
|
|
|
|
}
|
2021-04-25 17:38:59 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|