diff options
author | Dmitry Sharshakov <sh7dm@outlook.com> | 2019-02-08 23:59:38 +0300 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-02-08 15:59:38 -0500 |
commit | 9ab03389f047e5520c184b9fce4cd5fb2e4804bd (patch) | |
tree | c1b3295aa6788595e4b73d28aeba0b8fdc8f3205 /js/copy_file_test.ts | |
parent | 3abaf9edb6877c328402b94fa0bcb6a9e0bbe86d (diff) |
Add --allow-read (#1689)
Co-authored-by: Greg Altman <g.s.altman@gmail.com>
Diffstat (limited to 'js/copy_file_test.ts')
-rw-r--r-- | js/copy_file_test.ts | 72 |
1 files changed, 48 insertions, 24 deletions
diff --git a/js/copy_file_test.ts b/js/copy_file_test.ts index bdc455f45..3bd1f7229 100644 --- a/js/copy_file_test.ts +++ b/js/copy_file_test.ts @@ -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); }); |