1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

stabilize Deno.cwd and require --allow-read (#5068)

This commit is contained in:
Ryan Dahl 2020-05-04 14:23:06 -04:00 committed by GitHub
parent 191c59a591
commit 6c02b061ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 23 additions and 59 deletions

View file

@ -19,7 +19,7 @@ export {
DiagnosticItem,
DiagnosticMessageChain,
} from "./diagnostics.ts";
export { chdir } from "./ops/fs/dir.ts";
export { chdir, cwd } from "./ops/fs/dir.ts";
export { errors } from "./errors.ts";
export {
File,

View file

@ -14,7 +14,6 @@ export { setRaw } from "./ops/tty.ts";
export { utimeSync, utime } from "./ops/fs/utime.ts";
export { ShutdownMode, shutdown } from "./net.ts";
export { listen, listenDatagram, connect } from "./net_unstable.ts";
export { cwd } from "./ops/fs/dir.ts";
export { startTls } from "./tls.ts";
export { kill } from "./ops/process.ts";
export {

View file

@ -144,6 +144,20 @@ declare namespace Deno {
*/
export function chdir(directory: string): void;
/**
* Return a string representing the current working directory.
*
* If the current directory can be reached via multiple paths (due to symbolic
* links), `cwd()` may return any one of them.
*
* const currentWorkingDirectory = Deno.cwd();
*
* Throws `Deno.errors.NotFound` if directory not available.
*
* Requires --allow-read
*/
export function cwd(): string;
export enum SeekMode {
Start = 0,
Current = 1,

View file

@ -1024,21 +1024,6 @@ declare namespace Deno {
options: ConnectOptions | UnixConnectOptions
): Promise<Conn>;
/**
* **UNSTABLE**: Currently under evaluation to decide if explicit permission is
* required to get the value of the current working directory.
*
* Return a string representing the current working directory.
*
* If the current directory can be reached via multiple paths (due to symbolic
* links), `cwd()` may return any one of them.
*
* const currentWorkingDirectory = Deno.cwd();
*
* Throws `Deno.errors.NotFound` if directory not available.
*/
export function cwd(): string;
export interface StartTlsOptions {
/** A literal IP address or host name that can be resolved to an IP address.
* If not specified, defaults to `127.0.0.1`. */

View file

@ -1,7 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { unitTest, assert, assertEquals } from "./test_util.ts";
unitTest(function dirCwdNotNull(): void {
unitTest({ perms: { read: true } }, function dirCwdNotNull(): void {
assert(Deno.cwd() != null);
});

View file

@ -905,11 +905,12 @@ fn op_utime(
}
fn op_cwd(
_state: &State,
state: &State,
_args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError> {
let path = current_dir()?;
state.check_read(&path)?;
let path_str = into_string(path.into_os_string())?;
Ok(JsonOp::Sync(json!(path_str)))
}

View file

@ -1146,10 +1146,9 @@ itest!(_055_import_wasm_via_network {
http_server: true,
});
// TODO(lucacasonato): remove --unstable when cwd goes stable
itest!(_056_make_temp_file_write_perm {
args:
"run --allow-write=./subdir/ --unstable 056_make_temp_file_write_perm.ts",
"run --allow-read --allow-write=./subdir/ 056_make_temp_file_write_perm.ts",
output: "056_make_temp_file_write_perm.out",
});

View file

@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, assertStrContains } from "../testing/asserts.ts";
import { assert, assertEquals } from "../testing/asserts.ts";
import { BufReader } from "../io/bufio.ts";
import { TextProtoReader } from "../textproto/mod.ts";
import { ServerRequest } from "./server.ts";
@ -12,7 +12,6 @@ async function startFileServer(): Promise<void> {
cmd: [
Deno.execPath(),
"run",
"--unstable",
"--allow-read",
"--allow-net",
"http/file_server.ts",
@ -104,47 +103,14 @@ test("serveWithUnorthodoxFilename", async function (): Promise<void> {
}
});
test("servePermissionDenied", async function (): Promise<void> {
const deniedServer = Deno.run({
// TODO(lucacasonato): remove unstable when stabilized
cmd: [
Deno.execPath(),
"run",
"--unstable",
"--allow-net",
"http/file_server.ts",
],
stdout: "piped",
stderr: "piped",
});
assert(deniedServer.stdout != null);
const reader = new TextProtoReader(new BufReader(deniedServer.stdout));
assert(deniedServer.stderr != null);
const errReader = new TextProtoReader(new BufReader(deniedServer.stderr));
const s = await reader.readLine();
assert(s !== null && s.includes("server listening"));
try {
const res = await fetch("http://localhost:4500/");
const _ = await res.text();
assertStrContains(
(await errReader.readLine()) as string,
"run again with the --allow-read flag"
);
} finally {
deniedServer.close();
deniedServer.stdout.close();
deniedServer.stderr.close();
}
});
test("printHelp", async function (): Promise<void> {
const helpProcess = Deno.run({
// TODO(lucacasonato): remove unstable when stabilized
cmd: [
Deno.execPath(),
"run",
"--unstable",
// TODO(ry) It ought to be possible to get the help output without
// --allow-read.
"--allow-read",
"http/file_server.ts",
"--help",
],