From 52c13fb3ed94e41d90bbe08d1bc299ca90505755 Mon Sep 17 00:00:00 2001 From: "Kevin (Kun) \"Kassimo\" Qian" Date: Sat, 3 Aug 2019 18:34:13 -0700 Subject: Enforce env permission on homeDir() and execPath (#2714) --- js/os_test.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/os_test.ts b/js/os_test.ts index 766cd1c3f..b2f511b5e 100644 --- a/js/os_test.ts +++ b/js/os_test.ts @@ -39,6 +39,26 @@ test(function osIsTTYSmoke(): void { console.log(Deno.isTTY()); }); -test(function homeDir(): void { +testPerm({ env: true }, function homeDir(): void { assertNotEquals(Deno.homeDir(), ""); }); + +testPerm({ env: false }, function homeDirPerm(): void { + let caughtError = false; + try { + Deno.homeDir(); + } catch (err) { + caughtError = true; + assertEquals(err.kind, Deno.ErrorKind.PermissionDenied); + assertEquals(err.name, "PermissionDenied"); + } + assert(caughtError); +}); + +testPerm({ env: true }, function execPath(): void { + assertNotEquals(Deno.execPath, ""); +}); + +testPerm({ env: false }, function execPathPerm(): void { + assertEquals(Deno.execPath, ""); +}); -- cgit v1.2.3