mirror of
https://github.com/denoland/deno.git
synced 2025-09-29 21:54:48 +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
|
@ -8,7 +8,7 @@ test(function filesStdioFileDescriptors() {
|
|||
assertEqual(deno.stderr.rid, 2);
|
||||
});
|
||||
|
||||
test(async function filesCopyToStdout() {
|
||||
testPerm({ read: true }, async function filesCopyToStdout() {
|
||||
const filename = "package.json";
|
||||
const file = await deno.open(filename);
|
||||
assert(file.rid > 2);
|
||||
|
@ -18,7 +18,7 @@ test(async function filesCopyToStdout() {
|
|||
console.log("bytes written", bytesWritten);
|
||||
});
|
||||
|
||||
test(async function filesToAsyncIterator() {
|
||||
testPerm({ read: true }, async function filesToAsyncIterator() {
|
||||
const filename = "tests/hello.txt";
|
||||
const file = await deno.open(filename);
|
||||
|
||||
|
@ -32,7 +32,7 @@ test(async function filesToAsyncIterator() {
|
|||
|
||||
testPerm({ write: false }, async function writePermFailure() {
|
||||
const filename = "tests/hello.txt";
|
||||
const writeModes: deno.OpenMode[] = ["r+", "w", "w+", "a", "a+", "x", "x+"];
|
||||
const writeModes: deno.OpenMode[] = ["w", "a", "x"];
|
||||
for (const mode of writeModes) {
|
||||
let err;
|
||||
try {
|
||||
|
@ -46,7 +46,35 @@ testPerm({ write: false }, async function writePermFailure() {
|
|||
}
|
||||
});
|
||||
|
||||
testPerm({ write: true }, async function createFile() {
|
||||
testPerm({ read: false }, async function readPermFailure() {
|
||||
let caughtError = false;
|
||||
try {
|
||||
await deno.open("package.json", "r");
|
||||
} catch (e) {
|
||||
caughtError = true;
|
||||
assertEqual(e.kind, deno.ErrorKind.PermissionDenied);
|
||||
assertEqual(e.name, "PermissionDenied");
|
||||
}
|
||||
assert(caughtError);
|
||||
});
|
||||
|
||||
testPerm({ write: false, read: false }, async function readWritePermFailure() {
|
||||
const filename = "tests/hello.txt";
|
||||
const writeModes: deno.OpenMode[] = ["r+", "w+", "a+", "x+"];
|
||||
for (const mode of writeModes) {
|
||||
let err;
|
||||
try {
|
||||
await deno.open(filename, mode);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
assert(!!err);
|
||||
assertEqual(err.kind, deno.ErrorKind.PermissionDenied);
|
||||
assertEqual(err.name, "PermissionDenied");
|
||||
}
|
||||
});
|
||||
|
||||
testPerm({ read: true, write: true }, async function createFile() {
|
||||
const tempDir = await deno.makeTempDir();
|
||||
const filename = tempDir + "/test.txt";
|
||||
const f = await deno.open(filename, "w");
|
||||
|
@ -64,7 +92,7 @@ testPerm({ write: true }, async function createFile() {
|
|||
await deno.remove(tempDir, { recursive: true });
|
||||
});
|
||||
|
||||
testPerm({ write: true }, async function openModeWrite() {
|
||||
testPerm({ read: true, write: true }, async function openModeWrite() {
|
||||
const tempDir = deno.makeTempDirSync();
|
||||
const encoder = new TextEncoder();
|
||||
const filename = tempDir + "hello.txt";
|
||||
|
@ -98,7 +126,7 @@ testPerm({ write: true }, async function openModeWrite() {
|
|||
await deno.remove(tempDir, { recursive: true });
|
||||
});
|
||||
|
||||
testPerm({ write: true }, async function openModeWriteRead() {
|
||||
testPerm({ read: true, write: true }, async function openModeWriteRead() {
|
||||
const tempDir = deno.makeTempDirSync();
|
||||
const encoder = new TextEncoder();
|
||||
const filename = tempDir + "hello.txt";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue