diff options
-rw-r--r-- | cli/js/permissions_test.ts | 31 | ||||
-rw-r--r-- | cli/js/unit_tests.ts | 6 | ||||
-rw-r--r-- | cli/tests/057_revoke_permissions.out | 10 | ||||
-rw-r--r-- | cli/tests/057_revoke_permissions.ts | 36 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 5 |
5 files changed, 53 insertions, 35 deletions
diff --git a/cli/js/permissions_test.ts b/cli/js/permissions_test.ts index 6d79cfec0..7a36ee901 100644 --- a/cli/js/permissions_test.ts +++ b/cli/js/permissions_test.ts @@ -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; diff --git a/cli/js/unit_tests.ts b/cli/js/unit_tests.ts index 2495c938b..f20e2f137 100644 --- a/cli/js/unit_tests.ts +++ b/cli/js/unit_tests.ts @@ -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(); } diff --git a/cli/tests/057_revoke_permissions.out b/cli/tests/057_revoke_permissions.out new file mode 100644 index 000000000..1f12d3b93 --- /dev/null +++ b/cli/tests/057_revoke_permissions.out @@ -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]
\ No newline at end of file diff --git a/cli/tests/057_revoke_permissions.ts b/cli/tests/057_revoke_permissions.ts new file mode 100644 index 000000000..4481dbfd9 --- /dev/null +++ b/cli/tests/057_revoke_permissions.ts @@ -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)); +} diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 843f56a7f..434a55c08 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -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", |