diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/os_test.ts | 44 | ||||
-rw-r--r-- | tests/unit/read_file_test.ts | 2 | ||||
-rw-r--r-- | tests/unit/read_text_file_test.ts | 2 |
3 files changed, 16 insertions, 32 deletions
diff --git a/tests/unit/os_test.ts b/tests/unit/os_test.ts index 80b421e63..42b598511 100644 --- a/tests/unit/os_test.ts +++ b/tests/unit/os_test.ts @@ -3,7 +3,6 @@ import { assert, assertEquals, assertNotEquals, - assertStringIncludes, assertThrows, } from "./test_util.ts"; @@ -197,36 +196,21 @@ Deno.test({ permissions: { read: false } }, function execPathPerm() { ); }); -Deno.test(async function execPathPerm() { - if (Deno.build.os !== "linux") return; - // This is hack to bypass a bug in deno test runner, - // Currently if you specify {read: true} permission, it will stil pass --allow-all (tests are run with deno test --allow-all) implicitly, so this test won't work - // The workaround is to spawn a deno executable with the needed permissions - // TODO(#25085): remove this hack when the bug is fixed - const cmd = new Deno.Command(Deno.execPath(), { - args: ["run", "--allow-read", "-"], - stdin: "piped", - stderr: "piped", - }).spawn(); - const stdinWriter = cmd.stdin.getWriter(); - await stdinWriter - .write( - new TextEncoder().encode('Deno.readTextFileSync("/proc/net/dev")'), +Deno.test( + { + ignore: Deno.build.os !== "linux", + permissions: { read: true, run: false }, + }, + function procRequiresAllowAll() { + assertThrows( + () => { + Deno.readTextFileSync("/proc/net/dev"); + }, + Deno.errors.PermissionDenied, + `Requires all access to "/proc/net/dev", run again with the --allow-all flag`, ); - await stdinWriter.close(); - await cmd.status; - - const stderrReder = cmd.stderr.getReader(); - const error = await stderrReder - .read() - .then((r) => new TextDecoder().decode(r.value)); - await stderrReder.cancel(); - - assertStringIncludes( - error, - `PermissionDenied: Requires all access to "/proc/net/dev", run again with the --allow-all flag`, - ); -}); + }, +); Deno.test( { permissions: { sys: ["loadavg"] } }, diff --git a/tests/unit/read_file_test.ts b/tests/unit/read_file_test.ts index 562bf9969..67944813b 100644 --- a/tests/unit/read_file_test.ts +++ b/tests/unit/read_file_test.ts @@ -148,7 +148,7 @@ Deno.test( ); Deno.test( - { permissions: { read: true }, ignore: Deno.build.os !== "linux" }, + { ignore: Deno.build.os !== "linux" }, async function readFileProcFs() { const data = await Deno.readFile("/proc/self/stat"); assert(data.byteLength > 0); diff --git a/tests/unit/read_text_file_test.ts b/tests/unit/read_text_file_test.ts index 94aa5f0a8..cab75fd47 100644 --- a/tests/unit/read_text_file_test.ts +++ b/tests/unit/read_text_file_test.ts @@ -146,7 +146,7 @@ Deno.test( ); Deno.test( - { permissions: { read: true }, ignore: Deno.build.os !== "linux" }, + { ignore: Deno.build.os !== "linux" }, async function readTextFileProcFs() { const data = await Deno.readTextFile("/proc/self/stat"); assert(data.length > 0); |