diff options
author | Luca Casonato <hello@lcas.dev> | 2024-09-10 20:12:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-10 11:12:24 -0700 |
commit | 7bfcb4dd10d31f5f9566c90a28449c0951f3a48e (patch) | |
tree | fca0dec6e98118418f1712c6e8451a04c7e89988 /tests/unit | |
parent | be5419d479fcae16c8a07dec00ce11b532b7996a (diff) |
feat(cli): use NotCapable error for permission errors (#25431)
Closes #7394
---------
Co-authored-by: snek <snek@deno.com>
Diffstat (limited to 'tests/unit')
32 files changed, 89 insertions, 88 deletions
diff --git a/tests/unit/chmod_test.ts b/tests/unit/chmod_test.ts index df3771bbc..9ff6301e2 100644 --- a/tests/unit/chmod_test.ts +++ b/tests/unit/chmod_test.ts @@ -94,7 +94,7 @@ Deno.test({ permissions: { write: true } }, function chmodSyncFailure() { Deno.test({ permissions: { write: false } }, function chmodSyncPerm() { assertThrows(() => { Deno.chmodSync("/somefile.txt", 0o777); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test( @@ -186,5 +186,5 @@ Deno.test({ permissions: { write: true } }, async function chmodFailure() { Deno.test({ permissions: { write: false } }, async function chmodPerm() { await assertRejects(async () => { await Deno.chmod("/somefile.txt", 0o777); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); diff --git a/tests/unit/chown_test.ts b/tests/unit/chown_test.ts index 033d4592d..eda4d3403 100644 --- a/tests/unit/chown_test.ts +++ b/tests/unit/chown_test.ts @@ -26,7 +26,7 @@ Deno.test( const filePath = "chown_test_file.txt"; await assertRejects(async () => { await Deno.chown(filePath, 1000, 1000); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); diff --git a/tests/unit/command_test.ts b/tests/unit/command_test.ts index c11761fe7..0a7891493 100644 --- a/tests/unit/command_test.ts +++ b/tests/unit/command_test.ts @@ -382,7 +382,7 @@ Deno.test( await new Deno.Command(Deno.execPath(), { args: ["eval", "console.log('hello world')"], }).output(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); @@ -393,7 +393,7 @@ Deno.test( new Deno.Command(Deno.execPath(), { args: ["eval", "console.log('hello world')"], }).outputSync(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); diff --git a/tests/unit/copy_file_test.ts b/tests/unit/copy_file_test.ts index ad467f510..9405184e3 100644 --- a/tests/unit/copy_file_test.ts +++ b/tests/unit/copy_file_test.ts @@ -84,7 +84,7 @@ Deno.test( function copyFileSyncPerm1() { assertThrows(() => { Deno.copyFileSync("/from.txt", "/to.txt"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); @@ -93,7 +93,7 @@ Deno.test( function copyFileSyncPerm2() { assertThrows(() => { Deno.copyFileSync("/from.txt", "/to.txt"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); @@ -197,7 +197,7 @@ Deno.test( async function copyFilePerm1() { await assertRejects(async () => { await Deno.copyFile("/from.txt", "/to.txt"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); @@ -206,7 +206,7 @@ Deno.test( async function copyFilePerm2() { await assertRejects(async () => { await Deno.copyFile("/from.txt", "/to.txt"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); diff --git a/tests/unit/dir_test.ts b/tests/unit/dir_test.ts index 4aaadfb12..1e702f549 100644 --- a/tests/unit/dir_test.ts +++ b/tests/unit/dir_test.ts @@ -43,7 +43,7 @@ Deno.test({ permissions: { read: false } }, function dirCwdPermError() { () => { Deno.cwd(); }, - Deno.errors.PermissionDenied, + Deno.errors.NotCapable, "Requires read access to <CWD>, run again with the --allow-read flag", ); }); diff --git a/tests/unit/error_test.ts b/tests/unit/error_test.ts index 9ba09ce0d..bf0ef5062 100644 --- a/tests/unit/error_test.ts +++ b/tests/unit/error_test.ts @@ -22,6 +22,7 @@ Deno.test("Errors work", () => { assert(new Deno.errors.Http("msg") instanceof Error); assert(new Deno.errors.Busy("msg") instanceof Error); assert(new Deno.errors.NotSupported("msg") instanceof Error); + assert(new Deno.errors.NotCapable("msg") instanceof Error); }); Deno.test("Errors have some tamper resistance", () => { diff --git a/tests/unit/fetch_test.ts b/tests/unit/fetch_test.ts index 35d5e563f..35517911c 100644 --- a/tests/unit/fetch_test.ts +++ b/tests/unit/fetch_test.ts @@ -124,7 +124,7 @@ Deno.test({ permissions: { net: true } }, async function fetchJsonSuccess() { Deno.test({ permissions: { net: false } }, async function fetchPerm() { await assertRejects(async () => { await fetch("http://localhost:4545/assets/fixture.json"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { net: true } }, async function fetchUrl() { @@ -1637,7 +1637,7 @@ Deno.test( Deno.test({ permissions: { read: false } }, async function fetchFilePerm() { await assertRejects(async () => { await fetch(import.meta.resolve("../testdata/subdir/json_1.json")); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test( @@ -1645,7 +1645,7 @@ Deno.test( async function fetchFilePermDoesNotExist() { await assertRejects(async () => { await fetch(import.meta.resolve("./bad.json")); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); diff --git a/tests/unit/ffi_test.ts b/tests/unit/ffi_test.ts index 70a914c0a..98338b15e 100644 --- a/tests/unit/ffi_test.ts +++ b/tests/unit/ffi_test.ts @@ -24,10 +24,10 @@ Deno.test({ permissions: { ffi: true } }, function dlopenInvalidArguments() { }, TypeError); }); -Deno.test({ permissions: { ffi: false } }, function ffiPermissionDenied() { +Deno.test({ permissions: { ffi: false } }, function ffiNotCapable() { assertThrows(() => { Deno.dlopen("/usr/lib/libc.so.6", {}); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); const fnptr = new Deno.UnsafeFnPointer( // @ts-expect-error: Not NonNullable but null check is after permissions check. null, @@ -38,44 +38,44 @@ Deno.test({ permissions: { ffi: false } }, function ffiPermissionDenied() { ); assertThrows(() => { fnptr.call(123, null); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); assertThrows(() => { Deno.UnsafePointer.of(new Uint8Array(0)); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); const ptrView = new Deno.UnsafePointerView( // @ts-expect-error: Not NonNullable but null check is after permissions check. null, ); assertThrows(() => { ptrView.copyInto(new Uint8Array(0)); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); assertThrows(() => { ptrView.getCString(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); assertThrows(() => { ptrView.getUint8(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); assertThrows(() => { ptrView.getInt8(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); assertThrows(() => { ptrView.getUint16(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); assertThrows(() => { ptrView.getInt16(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); assertThrows(() => { ptrView.getUint32(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); assertThrows(() => { ptrView.getInt32(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); assertThrows(() => { ptrView.getFloat32(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); assertThrows(() => { ptrView.getFloat64(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { ffi: true } }, function pointerOf() { diff --git a/tests/unit/files_test.ts b/tests/unit/files_test.ts index c79397109..6692415d4 100644 --- a/tests/unit/files_test.ts +++ b/tests/unit/files_test.ts @@ -127,7 +127,7 @@ Deno.test( for (const options of openOptions) { await assertRejects(async () => { await Deno.open(filename, options); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); } }, ); @@ -170,7 +170,7 @@ Deno.test(async function openOptions() { Deno.test({ permissions: { read: false } }, async function readPermFailure() { await assertRejects(async () => { await Deno.open("package.json", { read: true }); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test( @@ -229,7 +229,7 @@ Deno.test( const filename = "tests/hello.txt"; await assertRejects(async () => { await Deno.open(filename, { read: true }); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); diff --git a/tests/unit/fs_events_test.ts b/tests/unit/fs_events_test.ts index 3a867f07e..148688215 100644 --- a/tests/unit/fs_events_test.ts +++ b/tests/unit/fs_events_test.ts @@ -7,7 +7,7 @@ import { assert, assertEquals, assertThrows, delay } from "./test_util.ts"; Deno.test({ permissions: { read: false } }, function watchFsPermissions() { assertThrows(() => { Deno.watchFs("."); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { read: true } }, function watchFsInvalidPath() { diff --git a/tests/unit/link_test.ts b/tests/unit/link_test.ts index 6048b8add..dfa72479c 100644 --- a/tests/unit/link_test.ts +++ b/tests/unit/link_test.ts @@ -87,7 +87,7 @@ Deno.test( function linkSyncReadPerm() { assertThrows(() => { Deno.linkSync("oldbaddir", "newbaddir"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); @@ -96,7 +96,7 @@ Deno.test( function linkSyncWritePerm() { assertThrows(() => { Deno.linkSync("oldbaddir", "newbaddir"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); @@ -181,7 +181,7 @@ Deno.test( async function linkReadPerm() { await assertRejects(async () => { await Deno.link("oldbaddir", "newbaddir"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); @@ -190,6 +190,6 @@ Deno.test( async function linkWritePerm() { await assertRejects(async () => { await Deno.link("oldbaddir", "newbaddir"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); diff --git a/tests/unit/make_temp_test.ts b/tests/unit/make_temp_test.ts index 2c771177b..32383387b 100644 --- a/tests/unit/make_temp_test.ts +++ b/tests/unit/make_temp_test.ts @@ -42,7 +42,7 @@ Deno.test({ permissions: { write: false } }, function makeTempDirSyncPerm() { // makeTempDirSync should require write permissions (for now). assertThrows(() => { Deno.makeTempDirSync({ dir: "/baddir" }); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test( @@ -117,7 +117,7 @@ Deno.test({ permissions: { write: false } }, function makeTempFileSyncPerm() { // makeTempFileSync should require write permissions (for now). assertThrows(() => { Deno.makeTempFileSync({ dir: "/baddir" }); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test( diff --git a/tests/unit/mkdir_test.ts b/tests/unit/mkdir_test.ts index 0948a1a84..def77cd3e 100644 --- a/tests/unit/mkdir_test.ts +++ b/tests/unit/mkdir_test.ts @@ -36,7 +36,7 @@ Deno.test( Deno.test({ permissions: { write: false } }, function mkdirSyncPerm() { assertThrows(() => { Deno.mkdirSync("/baddir"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test( diff --git a/tests/unit/net_test.ts b/tests/unit/net_test.ts index 6265579a2..b7230da25 100644 --- a/tests/unit/net_test.ts +++ b/tests/unit/net_test.ts @@ -100,7 +100,7 @@ Deno.test( assert(socket.addr.transport === "unix"); assertEquals(socket.addr.path, filePath); socket.close(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); @@ -119,7 +119,7 @@ Deno.test( assert(socket.addr.transport === "unixpacket"); assertEquals(socket.addr.path, filePath); socket.close(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); diff --git a/tests/unit/os_test.ts b/tests/unit/os_test.ts index 52aa2ce77..4f760ecf8 100644 --- a/tests/unit/os_test.ts +++ b/tests/unit/os_test.ts @@ -48,16 +48,16 @@ Deno.test({ permissions: { env: true } }, function avoidEmptyNamedEnv() { assertThrows(() => Deno.env.delete("a\0a"), TypeError); }); -Deno.test({ permissions: { env: false } }, function envPermissionDenied1() { +Deno.test({ permissions: { env: false } }, function envPerm1() { assertThrows(() => { Deno.env.toObject(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); -Deno.test({ permissions: { env: false } }, function envPermissionDenied2() { +Deno.test({ permissions: { env: false } }, function envPerm2() { assertThrows(() => { Deno.env.get("PATH"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); // This test verifies that on Windows, environment variables are @@ -191,7 +191,7 @@ Deno.test({ permissions: { read: false } }, function execPathPerm() { () => { Deno.execPath(); }, - Deno.errors.PermissionDenied, + Deno.errors.NotCapable, "Requires read access to <exec_path>, run again with the --allow-read flag", ); }); @@ -206,7 +206,7 @@ Deno.test( () => { Deno.readTextFileSync("/proc/net/dev"); }, - Deno.errors.PermissionDenied, + Deno.errors.NotCapable, `Requires all access to "/proc/net/dev", run again with the --allow-all flag`, ); }, @@ -223,7 +223,7 @@ Deno.test( Deno.test({ permissions: { sys: false } }, function loadavgPerm() { assertThrows(() => { Deno.loadavg(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test( @@ -253,7 +253,7 @@ Deno.test( Deno.test({ permissions: { sys: false } }, function hostnamePerm() { assertThrows(() => { Deno.hostname(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test( @@ -266,7 +266,7 @@ Deno.test( Deno.test({ permissions: { sys: false } }, function releasePerm() { assertThrows(() => { Deno.osRelease(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { sys: ["osUptime"] } }, function osUptime() { @@ -278,7 +278,7 @@ Deno.test({ permissions: { sys: ["osUptime"] } }, function osUptime() { Deno.test({ permissions: { sys: false } }, function osUptimePerm() { assertThrows(() => { Deno.osUptime(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test( diff --git a/tests/unit/process_test.ts b/tests/unit/process_test.ts index 0d14c9ce7..93736e9ba 100644 --- a/tests/unit/process_test.ts +++ b/tests/unit/process_test.ts @@ -17,7 +17,7 @@ Deno.test( Deno.run({ cmd: [Deno.execPath(), "eval", "console.log('hello world')"], }); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); @@ -517,7 +517,7 @@ Deno.test({ permissions: { run: false } }, function killPermissions() { // process - assuming that Deno does not have a special handler set for it // and will just continue even if a signal is erroneously sent. Deno.kill(Deno.pid, "SIGCONT"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test( diff --git a/tests/unit/read_dir_test.ts b/tests/unit/read_dir_test.ts index cba9647e5..b00495eb4 100644 --- a/tests/unit/read_dir_test.ts +++ b/tests/unit/read_dir_test.ts @@ -35,7 +35,7 @@ Deno.test({ permissions: { read: true } }, function readDirSyncWithUrl() { Deno.test({ permissions: { read: false } }, function readDirSyncPerm() { assertThrows(() => { Deno.readDirSync("tests/"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { read: true } }, function readDirSyncNotDir() { @@ -79,7 +79,7 @@ Deno.test({ permissions: { read: true } }, async function readDirWithUrl() { Deno.test({ permissions: { read: false } }, async function readDirPerm() { await assertRejects(async () => { await Deno.readDir("tests/")[Symbol.asyncIterator]().next(); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test( diff --git a/tests/unit/read_file_test.ts b/tests/unit/read_file_test.ts index 6aea6f7af..7123833e9 100644 --- a/tests/unit/read_file_test.ts +++ b/tests/unit/read_file_test.ts @@ -31,7 +31,7 @@ Deno.test({ permissions: { read: true } }, function readFileSyncUrl() { Deno.test({ permissions: { read: false } }, function readFileSyncPerm() { assertThrows(() => { Deno.readFileSync("tests/testdata/assets/fixture.json"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { read: true } }, function readFileSyncNotFound() { @@ -63,7 +63,7 @@ Deno.test({ permissions: { read: true } }, async function readFileSuccess() { Deno.test({ permissions: { read: false } }, async function readFilePerm() { await assertRejects(async () => { await Deno.readFile("tests/testdata/assets/fixture.json"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { read: true } }, function readFileSyncLoop() { diff --git a/tests/unit/read_link_test.ts b/tests/unit/read_link_test.ts index 3ed1817bb..c89ffe492 100644 --- a/tests/unit/read_link_test.ts +++ b/tests/unit/read_link_test.ts @@ -39,7 +39,7 @@ Deno.test( Deno.test({ permissions: { read: false } }, function readLinkSyncPerm() { assertThrows(() => { Deno.readLinkSync("/symlink"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { read: true } }, function readLinkSyncNotFound() { @@ -85,7 +85,7 @@ Deno.test( Deno.test({ permissions: { read: false } }, async function readLinkPerm() { await assertRejects(async () => { await Deno.readLink("/symlink"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { read: true } }, async function readLinkNotFound() { diff --git a/tests/unit/read_text_file_test.ts b/tests/unit/read_text_file_test.ts index cab75fd47..1ec57bde3 100644 --- a/tests/unit/read_text_file_test.ts +++ b/tests/unit/read_text_file_test.ts @@ -28,7 +28,7 @@ Deno.test({ permissions: { read: true } }, function readTextFileSyncByUrl() { Deno.test({ permissions: { read: false } }, function readTextFileSyncPerm() { assertThrows(() => { Deno.readTextFileSync("tests/testdata/assets/fixture.json"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { read: true } }, function readTextFileSyncNotFound() { @@ -61,7 +61,7 @@ Deno.test({ permissions: { read: true } }, async function readTextFileByUrl() { Deno.test({ permissions: { read: false } }, async function readTextFilePerm() { await assertRejects(async () => { await Deno.readTextFile("tests/testdata/assets/fixture.json"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { read: true } }, function readTextFileSyncLoop() { diff --git a/tests/unit/real_path_test.ts b/tests/unit/real_path_test.ts index b3656a927..783284630 100644 --- a/tests/unit/real_path_test.ts +++ b/tests/unit/real_path_test.ts @@ -50,7 +50,7 @@ Deno.test( Deno.test({ permissions: { read: false } }, function realPathSyncPerm() { assertThrows(() => { Deno.realPathSync("some_file"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { read: true } }, function realPathSyncNotFound() { @@ -104,7 +104,7 @@ Deno.test( Deno.test({ permissions: { read: false } }, async function realPathPerm() { await assertRejects(async () => { await Deno.realPath("some_file"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { read: true } }, async function realPathNotFound() { diff --git a/tests/unit/remove_test.ts b/tests/unit/remove_test.ts index f4e54dc52..261ff6bd0 100644 --- a/tests/unit/remove_test.ts +++ b/tests/unit/remove_test.ts @@ -153,7 +153,7 @@ Deno.test({ permissions: { write: false } }, async function removePerm() { for (const method of REMOVE_METHODS) { await assertRejects(async () => { await Deno[method]("/baddir"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); } }); @@ -233,7 +233,7 @@ Deno.test({ permissions: { write: false } }, async function removeAllPerm() { for (const method of REMOVE_METHODS) { await assertRejects(async () => { await Deno[method]("/baddir", { recursive: true }); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); } }); diff --git a/tests/unit/rename_test.ts b/tests/unit/rename_test.ts index 4f6bb09cf..3162c699c 100644 --- a/tests/unit/rename_test.ts +++ b/tests/unit/rename_test.ts @@ -70,7 +70,7 @@ Deno.test( const oldpath = "/oldbaddir"; const newpath = "/newbaddir"; Deno.renameSync(oldpath, newpath); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); @@ -81,7 +81,7 @@ Deno.test( const oldpath = "/oldbaddir"; const newpath = "/newbaddir"; Deno.renameSync(oldpath, newpath); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); diff --git a/tests/unit/stat_test.ts b/tests/unit/stat_test.ts index 950ffa81b..59831a069 100644 --- a/tests/unit/stat_test.ts +++ b/tests/unit/stat_test.ts @@ -74,7 +74,7 @@ Deno.test( Deno.test({ permissions: { read: false } }, function statSyncPerm() { assertThrows(() => { Deno.statSync("README.md"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { read: true } }, function statSyncNotFound() { @@ -118,7 +118,7 @@ Deno.test({ permissions: { read: true } }, function lstatSyncSuccess() { Deno.test({ permissions: { read: false } }, function lstatSyncPerm() { assertThrows(() => { Deno.lstatSync("assets/hello.txt"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { read: true } }, function lstatSyncNotFound() { @@ -200,7 +200,7 @@ Deno.test( Deno.test({ permissions: { read: false } }, async function statPerm() { await assertRejects(async () => { await Deno.stat("README.md"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { read: true } }, async function statNotFound() { @@ -244,7 +244,7 @@ Deno.test({ permissions: { read: true } }, async function lstatSuccess() { Deno.test({ permissions: { read: false } }, async function lstatPerm() { await assertRejects(async () => { await Deno.lstat("README.md"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { read: true } }, async function lstatNotFound() { diff --git a/tests/unit/symlink_test.ts b/tests/unit/symlink_test.ts index 0ee4a36fd..47a685ec6 100644 --- a/tests/unit/symlink_test.ts +++ b/tests/unit/symlink_test.ts @@ -62,7 +62,7 @@ Deno.test( function symlinkSyncPerm() { assertThrows(() => { Deno.symlinkSync("oldbaddir", "newbaddir"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); @@ -152,11 +152,11 @@ Deno.test( async function symlinkNoFullWritePermissions() { await assertRejects( () => Deno.symlink("old", "new"), - Deno.errors.PermissionDenied, + Deno.errors.NotCapable, ); assertThrows( () => Deno.symlinkSync("old", "new"), - Deno.errors.PermissionDenied, + Deno.errors.NotCapable, ); }, ); @@ -166,11 +166,11 @@ Deno.test( async function symlinkNoFullReadPermissions() { await assertRejects( () => Deno.symlink("old", "new"), - Deno.errors.PermissionDenied, + Deno.errors.NotCapable, ); assertThrows( () => Deno.symlinkSync("old", "new"), - Deno.errors.PermissionDenied, + Deno.errors.NotCapable, ); }, ); diff --git a/tests/unit/tls_test.ts b/tests/unit/tls_test.ts index 7dcc9abaf..6e80c984a 100644 --- a/tests/unit/tls_test.ts +++ b/tests/unit/tls_test.ts @@ -55,7 +55,7 @@ function unreachable(): never { Deno.test({ permissions: { net: false } }, async function connectTLSNoPerm() { await assertRejects(async () => { await Deno.connectTls({ hostname: "deno.land", port: 443 }); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test( @@ -76,7 +76,7 @@ Deno.test( port: 443, certFile: "tests/testdata/tls/RootCA.crt", }); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); @@ -116,7 +116,7 @@ Deno.test( certFile: "tests/testdata/tls/localhost.crt", keyFile: "tests/testdata/tls/localhost.key", }); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); diff --git a/tests/unit/truncate_test.ts b/tests/unit/truncate_test.ts index 95b76052d..cebd6e8ee 100644 --- a/tests/unit/truncate_test.ts +++ b/tests/unit/truncate_test.ts @@ -76,13 +76,13 @@ Deno.test( Deno.test({ permissions: { write: false } }, function truncateSyncPerm() { assertThrows(() => { Deno.truncateSync("/test_truncateSyncPermission.txt"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test({ permissions: { write: false } }, async function truncatePerm() { await assertRejects(async () => { await Deno.truncate("/test_truncatePermission.txt"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test( diff --git a/tests/unit/utime_test.ts b/tests/unit/utime_test.ts index 5bbb378cc..7a1fee74e 100644 --- a/tests/unit/utime_test.ts +++ b/tests/unit/utime_test.ts @@ -176,7 +176,7 @@ Deno.test( assertThrows(() => { Deno.utimeSync("/some_dir", atime, mtime); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); @@ -291,6 +291,6 @@ Deno.test( await assertRejects(async () => { await Deno.utime("/some_dir", atime, mtime); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); diff --git a/tests/unit/websocket_test.ts b/tests/unit/websocket_test.ts index 362957b2d..7db876b17 100644 --- a/tests/unit/websocket_test.ts +++ b/tests/unit/websocket_test.ts @@ -7,7 +7,7 @@ const serveUrl = `ws://localhost:${servePort}/`; Deno.test({ permissions: "none" }, function websocketPermissionless() { assertThrows( () => new WebSocket("ws://localhost"), - Deno.errors.PermissionDenied, + Deno.errors.NotCapable, ); }); diff --git a/tests/unit/worker_test.ts b/tests/unit/worker_test.ts index 700f57b6b..88c6ca4c6 100644 --- a/tests/unit/worker_test.ts +++ b/tests/unit/worker_test.ts @@ -546,7 +546,7 @@ Deno.test({ ); worker.terminate(); }, - Deno.errors.PermissionDenied, + Deno.errors.NotCapable, "Can't escalate parent thread permissions", ); }, diff --git a/tests/unit/write_file_test.ts b/tests/unit/write_file_test.ts index 29780446c..15e462cca 100644 --- a/tests/unit/write_file_test.ts +++ b/tests/unit/write_file_test.ts @@ -57,7 +57,7 @@ Deno.test({ permissions: { write: false } }, function writeFileSyncPerm() { // The following should fail due to no write permission assertThrows(() => { Deno.writeFileSync(filename, data); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test( @@ -190,7 +190,7 @@ Deno.test( // The following should fail due to no write permission await assertRejects(async () => { await Deno.writeFile(filename, data); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); diff --git a/tests/unit/write_text_file_test.ts b/tests/unit/write_text_file_test.ts index a58d91997..9e1b75326 100644 --- a/tests/unit/write_text_file_test.ts +++ b/tests/unit/write_text_file_test.ts @@ -45,7 +45,7 @@ Deno.test({ permissions: { write: false } }, function writeTextFileSyncPerm() { // The following should fail due to no write permission assertThrows(() => { Deno.writeTextFileSync(filename, "Hello"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }); Deno.test( @@ -144,7 +144,7 @@ Deno.test( // The following should fail due to no write permission await assertRejects(async () => { await Deno.writeTextFile(filename, "Hello"); - }, Deno.errors.PermissionDenied); + }, Deno.errors.NotCapable); }, ); |