summaryrefslogtreecommitdiff
path: root/js/read_file_test.ts
diff options
context:
space:
mode:
authorDmitry Sharshakov <sh7dm@outlook.com>2019-02-08 23:59:38 +0300
committerRyan Dahl <ry@tinyclouds.org>2019-02-08 15:59:38 -0500
commit9ab03389f047e5520c184b9fce4cd5fb2e4804bd (patch)
treec1b3295aa6788595e4b73d28aeba0b8fdc8f3205 /js/read_file_test.ts
parent3abaf9edb6877c328402b94fa0bcb6a9e0bbe86d (diff)
Add --allow-read (#1689)
Co-authored-by: Greg Altman <g.s.altman@gmail.com>
Diffstat (limited to 'js/read_file_test.ts')
-rw-r--r--js/read_file_test.ts32
1 files changed, 28 insertions, 4 deletions
diff --git a/js/read_file_test.ts b/js/read_file_test.ts
index db35dd702..34b391345 100644
--- a/js/read_file_test.ts
+++ b/js/read_file_test.ts
@@ -1,8 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { test, assert, assertEqual } from "./test_util.ts";
+import { testPerm, assert, assertEqual } from "./test_util.ts";
import * as deno from "deno";
-test(function readFileSyncSuccess() {
+testPerm({ read: true }, function readFileSyncSuccess() {
const data = deno.readFileSync("package.json");
assert(data.byteLength > 0);
const decoder = new TextDecoder("utf-8");
@@ -11,7 +11,19 @@ test(function readFileSyncSuccess() {
assertEqual(pkg.name, "deno");
});
-test(function readFileSyncNotFound() {
+testPerm({ read: false }, function readFileSyncPerm() {
+ let caughtError = false;
+ try {
+ const data = deno.readFileSync("package.json");
+ } catch (e) {
+ caughtError = true;
+ assertEqual(e.kind, deno.ErrorKind.PermissionDenied);
+ assertEqual(e.name, "PermissionDenied");
+ }
+ assert(caughtError);
+});
+
+testPerm({ read: true }, function readFileSyncNotFound() {
let caughtError = false;
let data;
try {
@@ -24,7 +36,7 @@ test(function readFileSyncNotFound() {
assert(data === undefined);
});
-test(async function readFileSuccess() {
+testPerm({ read: true }, async function readFileSuccess() {
const data = await deno.readFile("package.json");
assert(data.byteLength > 0);
const decoder = new TextDecoder("utf-8");
@@ -32,3 +44,15 @@ test(async function readFileSuccess() {
const pkg = JSON.parse(json);
assertEqual(pkg.name, "deno");
});
+
+testPerm({ read: false }, async function readFilePerm() {
+ let caughtError = false;
+ try {
+ await deno.readFile("package.json");
+ } catch (e) {
+ caughtError = true;
+ assertEqual(e.kind, deno.ErrorKind.PermissionDenied);
+ assertEqual(e.name, "PermissionDenied");
+ }
+ assert(caughtError);
+});