2020-02-28 09:47:54 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
const knownPermissions: Deno.PermissionName[] = [
|
|
|
|
"run",
|
|
|
|
"read",
|
|
|
|
"write",
|
|
|
|
"net",
|
|
|
|
"env",
|
|
|
|
"plugin",
|
2020-03-28 13:03:49 -04:00
|
|
|
"hrtime",
|
2020-02-28 09:47:54 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
export function assert(cond: unknown): asserts cond {
|
|
|
|
if (!cond) {
|
|
|
|
throw Error("Assertion failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-28 06:33:09 -04:00
|
|
|
function genFunc(grant: Deno.PermissionName): [string, () => Promise<void>] {
|
2020-02-28 09:47:54 -05:00
|
|
|
const gen: () => Promise<void> = async function Granted(): Promise<void> {
|
|
|
|
const status0 = await Deno.permissions.query({ name: grant });
|
|
|
|
assert(status0 != null);
|
|
|
|
assert(status0.state === "granted");
|
|
|
|
|
|
|
|
const status1 = await Deno.permissions.revoke({ name: grant });
|
|
|
|
assert(status1 != null);
|
|
|
|
assert(status1.state === "prompt");
|
|
|
|
};
|
2020-04-28 06:33:09 -04:00
|
|
|
const name = grant + "Granted";
|
|
|
|
return [name, gen];
|
2020-02-28 09:47:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const grant of knownPermissions) {
|
2020-04-28 06:33:09 -04:00
|
|
|
const [name, fn] = genFunc(grant);
|
|
|
|
Deno.test(name, fn);
|
2020-02-28 09:47:54 -05:00
|
|
|
}
|