mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 21:50:00 -05:00
rewrite permission revoke test as integration test (#4164)
This commit is contained in:
parent
7255cc9bc0
commit
a13b0e2727
5 changed files with 53 additions and 35 deletions
|
@ -1,34 +1,5 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { test, testPerm, assert, assertEquals } from "./test_util.ts";
|
||||
|
||||
const knownPermissions: Deno.PermissionName[] = [
|
||||
"run",
|
||||
"read",
|
||||
"write",
|
||||
"net",
|
||||
"env",
|
||||
"plugin",
|
||||
"hrtime"
|
||||
];
|
||||
|
||||
function genFunc(grant: Deno.PermissionName): () => Promise<void> {
|
||||
const gen: () => Promise<void> = async function Granted(): Promise<void> {
|
||||
const status0 = await Deno.permissions.query({ name: grant });
|
||||
assert(status0 != null);
|
||||
assertEquals(status0.state, "granted");
|
||||
|
||||
const status1 = await Deno.permissions.revoke({ name: grant });
|
||||
assert(status1 != null);
|
||||
assertEquals(status1.state, "prompt");
|
||||
};
|
||||
// Properly name these generated functions.
|
||||
Object.defineProperty(gen, "name", { value: grant + "Granted" });
|
||||
return gen;
|
||||
}
|
||||
|
||||
for (const grant of knownPermissions) {
|
||||
testPerm({ [grant]: true }, genFunc(grant));
|
||||
}
|
||||
import { test, assert } from "./test_util.ts";
|
||||
|
||||
test(async function permissionInvalidName(): Promise<void> {
|
||||
let thrown = false;
|
||||
|
|
|
@ -37,6 +37,7 @@ import "./mixins/dom_iterable_test.ts";
|
|||
import "./mkdir_test.ts";
|
||||
import "./net_test.ts";
|
||||
import "./os_test.ts";
|
||||
import "./permissions_test.ts";
|
||||
import "./process_test.ts";
|
||||
import "./realpath_test.ts";
|
||||
import "./read_dir_test.ts";
|
||||
|
@ -63,11 +64,6 @@ import "./performance_test.ts";
|
|||
import "./version_test.ts";
|
||||
import "./workers_test.ts";
|
||||
|
||||
// FIXME(bartlomieju):
|
||||
// This test file revokes permissions, it must be run last,
|
||||
// otherwise it might revoke permission for tests that need them.
|
||||
import "./permissions_test.ts";
|
||||
|
||||
if (import.meta.main) {
|
||||
await Deno.runTests();
|
||||
}
|
||||
|
|
10
cli/tests/057_revoke_permissions.out
Normal file
10
cli/tests/057_revoke_permissions.out
Normal file
|
@ -0,0 +1,10 @@
|
|||
running 7 tests
|
||||
OK runGranted [WILDCARD]
|
||||
OK readGranted [WILDCARD]
|
||||
OK writeGranted [WILDCARD]
|
||||
OK netGranted [WILDCARD]
|
||||
OK envGranted [WILDCARD]
|
||||
OK pluginGranted [WILDCARD]
|
||||
OK hrtimeGranted [WILDCARD]
|
||||
|
||||
test result: OK 7 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out [WILDCARD]
|
36
cli/tests/057_revoke_permissions.ts
Normal file
36
cli/tests/057_revoke_permissions.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
const knownPermissions: Deno.PermissionName[] = [
|
||||
"run",
|
||||
"read",
|
||||
"write",
|
||||
"net",
|
||||
"env",
|
||||
"plugin",
|
||||
"hrtime"
|
||||
];
|
||||
|
||||
export function assert(cond: unknown): asserts cond {
|
||||
if (!cond) {
|
||||
throw Error("Assertion failed");
|
||||
}
|
||||
}
|
||||
|
||||
function genFunc(grant: Deno.PermissionName): () => Promise<void> {
|
||||
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");
|
||||
};
|
||||
// Properly name these generated functions.
|
||||
Object.defineProperty(gen, "name", { value: grant + "Granted" });
|
||||
return gen;
|
||||
}
|
||||
|
||||
for (const grant of knownPermissions) {
|
||||
Deno.test(genFunc(grant));
|
||||
}
|
|
@ -936,6 +936,11 @@ itest!(_056_make_temp_file_write_perm {
|
|||
output: "056_make_temp_file_write_perm.out",
|
||||
});
|
||||
|
||||
itest!(_057_revoke_permissions {
|
||||
args: "test -A 057_revoke_permissions.ts",
|
||||
output: "057_revoke_permissions.out",
|
||||
});
|
||||
|
||||
itest!(js_import_detect {
|
||||
args: "run --reload js_import_detect.ts",
|
||||
output: "js_import_detect.ts.out",
|
||||
|
|
Loading…
Add table
Reference in a new issue