mirror of
https://github.com/denoland/deno.git
synced 2025-10-02 23:24:37 +00:00
Add --allow-read (#1689)
Co-authored-by: Greg Altman <g.s.altman@gmail.com>
This commit is contained in:
parent
3abaf9edb6
commit
9ab03389f0
25 changed files with 395 additions and 118 deletions
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue