mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 12:49:10 +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
|
@ -20,7 +20,7 @@ function assertSameContent(filename1: string, filename2: string) {
|
|||
assertEqual(data1, data2);
|
||||
}
|
||||
|
||||
testPerm({ write: true }, function copyFileSyncSuccess() {
|
||||
testPerm({ read: true, write: true }, function copyFileSyncSuccess() {
|
||||
const tempDir = deno.makeTempDirSync();
|
||||
const fromFilename = tempDir + "/from.txt";
|
||||
const toFilename = tempDir + "/to.txt";
|
||||
|
@ -32,7 +32,7 @@ testPerm({ write: true }, function copyFileSyncSuccess() {
|
|||
assertSameContent(fromFilename, toFilename);
|
||||
});
|
||||
|
||||
testPerm({ write: true }, function copyFileSyncFailure() {
|
||||
testPerm({ write: true, read: true }, function copyFileSyncFailure() {
|
||||
const tempDir = deno.makeTempDirSync();
|
||||
const fromFilename = tempDir + "/from.txt";
|
||||
const toFilename = tempDir + "/to.txt";
|
||||
|
@ -48,7 +48,31 @@ testPerm({ write: true }, function copyFileSyncFailure() {
|
|||
assertEqual(err.name, "NotFound");
|
||||
});
|
||||
|
||||
testPerm({ write: true }, function copyFileSyncOverwrite() {
|
||||
testPerm({ write: true, read: false }, function copyFileSyncPerm1() {
|
||||
let caughtError = false;
|
||||
try {
|
||||
deno.copyFileSync("/from.txt", "/to.txt");
|
||||
} catch (e) {
|
||||
caughtError = true;
|
||||
assertEqual(e.kind, deno.ErrorKind.PermissionDenied);
|
||||
assertEqual(e.name, "PermissionDenied");
|
||||
}
|
||||
assert(caughtError);
|
||||
});
|
||||
|
||||
testPerm({ write: false, read: true }, function copyFileSyncPerm2() {
|
||||
let caughtError = false;
|
||||
try {
|
||||
deno.copyFileSync("/from.txt", "/to.txt");
|
||||
} catch (e) {
|
||||
caughtError = true;
|
||||
assertEqual(e.kind, deno.ErrorKind.PermissionDenied);
|
||||
assertEqual(e.name, "PermissionDenied");
|
||||
}
|
||||
assert(caughtError);
|
||||
});
|
||||
|
||||
testPerm({ read: true, write: true }, function copyFileSyncOverwrite() {
|
||||
const tempDir = deno.makeTempDirSync();
|
||||
const fromFilename = tempDir + "/from.txt";
|
||||
const toFilename = tempDir + "/to.txt";
|
||||
|
@ -62,19 +86,7 @@ testPerm({ write: true }, function copyFileSyncOverwrite() {
|
|||
assertSameContent(fromFilename, toFilename);
|
||||
});
|
||||
|
||||
testPerm({ write: false }, function copyFileSyncPerm() {
|
||||
let err;
|
||||
try {
|
||||
deno.copyFileSync("/from.txt", "/to.txt");
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
assert(!!err);
|
||||
assertEqual(err.kind, deno.ErrorKind.PermissionDenied);
|
||||
assertEqual(err.name, "PermissionDenied");
|
||||
});
|
||||
|
||||
testPerm({ write: true }, async function copyFileSuccess() {
|
||||
testPerm({ read: true, write: true }, async function copyFileSuccess() {
|
||||
const tempDir = deno.makeTempDirSync();
|
||||
const fromFilename = tempDir + "/from.txt";
|
||||
const toFilename = tempDir + "/to.txt";
|
||||
|
@ -86,7 +98,7 @@ testPerm({ write: true }, async function copyFileSuccess() {
|
|||
assertSameContent(fromFilename, toFilename);
|
||||
});
|
||||
|
||||
testPerm({ write: true }, async function copyFileFailure() {
|
||||
testPerm({ read: true, write: true }, async function copyFileFailure() {
|
||||
const tempDir = deno.makeTempDirSync();
|
||||
const fromFilename = tempDir + "/from.txt";
|
||||
const toFilename = tempDir + "/to.txt";
|
||||
|
@ -102,7 +114,7 @@ testPerm({ write: true }, async function copyFileFailure() {
|
|||
assertEqual(err.name, "NotFound");
|
||||
});
|
||||
|
||||
testPerm({ write: true }, async function copyFileOverwrite() {
|
||||
testPerm({ read: true, write: true }, async function copyFileOverwrite() {
|
||||
const tempDir = deno.makeTempDirSync();
|
||||
const fromFilename = tempDir + "/from.txt";
|
||||
const toFilename = tempDir + "/to.txt";
|
||||
|
@ -116,14 +128,26 @@ testPerm({ write: true }, async function copyFileOverwrite() {
|
|||
assertSameContent(fromFilename, toFilename);
|
||||
});
|
||||
|
||||
testPerm({ write: false }, async function copyFilePerm() {
|
||||
let err;
|
||||
testPerm({ read: false, write: true }, async function copyFilePerm1() {
|
||||
let caughtError = false;
|
||||
try {
|
||||
await deno.copyFile("/from.txt", "/to.txt");
|
||||
} catch (e) {
|
||||
err = e;
|
||||
caughtError = true;
|
||||
assertEqual(e.kind, deno.ErrorKind.PermissionDenied);
|
||||
assertEqual(e.name, "PermissionDenied");
|
||||
}
|
||||
assert(!!err);
|
||||
assertEqual(err.kind, deno.ErrorKind.PermissionDenied);
|
||||
assertEqual(err.name, "PermissionDenied");
|
||||
assert(caughtError);
|
||||
});
|
||||
|
||||
testPerm({ read: true, write: false }, async function copyFilePerm2() {
|
||||
let caughtError = false;
|
||||
try {
|
||||
await deno.copyFile("/from.txt", "/to.txt");
|
||||
} 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