summaryrefslogtreecommitdiff
path: root/cli/tests/unit/dir_test.ts
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-05-29 16:27:43 +0100
committerGitHub <noreply@github.com>2020-05-29 17:27:43 +0200
commit8e39275429c36ff5dfa5d62a80713c5b288fe26a (patch)
tree1d6d2781682bed1c29f81366f08db65c604fef2c /cli/tests/unit/dir_test.ts
parentad6d2a7734aafb4a64837abc6abd1d1d0fb20017 (diff)
fix(cli/permissions): Fix CWD and exec path leaks (#5642)
Diffstat (limited to 'cli/tests/unit/dir_test.ts')
-rw-r--r--cli/tests/unit/dir_test.ts37
1 files changed, 18 insertions, 19 deletions
diff --git a/cli/tests/unit/dir_test.ts b/cli/tests/unit/dir_test.ts
index dc05d9564..5b60b3dba 100644
--- a/cli/tests/unit/dir_test.ts
+++ b/cli/tests/unit/dir_test.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { unitTest, assert, assertEquals } from "./test_util.ts";
+import { unitTest, assert, assertEquals, assertThrows } from "./test_util.ts";
unitTest({ perms: { read: true } }, function dirCwdNotNull(): void {
assert(Deno.cwd() != null);
@@ -29,32 +29,31 @@ unitTest({ perms: { read: true, write: true } }, function dirCwdError(): void {
Deno.chdir(path);
Deno.removeSync(path);
try {
- Deno.cwd();
- throw Error("current directory removed, should throw error");
- } catch (err) {
- if (err instanceof Deno.errors.NotFound) {
- assert(err.name === "NotFound");
- } else {
- throw Error("raised different exception");
- }
+ assertThrows(() => {
+ Deno.cwd();
+ }, Deno.errors.NotFound);
+ } finally {
+ Deno.chdir(initialdir);
}
- Deno.chdir(initialdir);
}
});
+unitTest({ perms: { read: false } }, function dirCwdPermError(): void {
+ assertThrows(
+ () => {
+ Deno.cwd();
+ },
+ Deno.errors.PermissionDenied,
+ "read access to <CWD>, run again with the --allow-read flag"
+ );
+});
+
unitTest(
{ perms: { read: true, write: true } },
function dirChdirError(): void {
const path = Deno.makeTempDirSync() + "test";
- try {
+ assertThrows(() => {
Deno.chdir(path);
- throw Error("directory not available, should throw error");
- } catch (err) {
- if (err instanceof Deno.errors.NotFound) {
- assert(err.name === "NotFound");
- } else {
- throw Error("raised different exception");
- }
- }
+ }, Deno.errors.NotFound);
}
);