From 988790834e9611b45663e48a7bea49219da7511f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E6=9D=89?= Date: Wed, 12 Aug 2020 23:38:25 +0800 Subject: feat(std/http): add --no-dir-listing flag to file_server (#6808) --- std/http/file_server_test.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'std/http/file_server_test.ts') diff --git a/std/http/file_server_test.ts b/std/http/file_server_test.ts index a25c13a7d..818fd5ecb 100644 --- a/std/http/file_server_test.ts +++ b/std/http/file_server_test.ts @@ -3,17 +3,15 @@ import { assert, assertEquals } from "../testing/asserts.ts"; import { BufReader } from "../io/bufio.ts"; import { TextProtoReader } from "../textproto/mod.ts"; import { ServerRequest } from "./server.ts"; -import { serveFile } from "./file_server.ts"; +import { serveFile, FileServerArgs } from "./file_server.ts"; let fileServer: Deno.Process; -type FileServerCfg = { - target?: string; - port?: number; -}; +type FileServerCfg = Omit & { target?: string }; async function startFileServer({ target = ".", port = 4507, + "dir-listing": dirListing = true, }: FileServerCfg = {}): Promise { fileServer = Deno.run({ cmd: [ @@ -26,6 +24,7 @@ async function startFileServer({ "--cors", "-p", `${port}`, + `${dirListing ? "" : "--no-dir-listing"}`, ], stdout: "piped", stderr: "null", @@ -100,7 +99,6 @@ Deno.test( const localFile = new TextDecoder().decode( await Deno.readFile("./http/README.md"), ); - console.log(downloadedFile, localFile); assertEquals(downloadedFile, localFile); } finally { await killFileServer(); @@ -288,3 +286,16 @@ Deno.test("partial TLS arguments fail", async function (): Promise { await killFileServer(); } }); + +Deno.test("file_server disable dir listings", async function (): Promise { + await startFileServer({ "dir-listing": false }); + try { + const res = await fetch("http://localhost:4507/"); + assert(res.headers.has("access-control-allow-origin")); + assert(res.headers.has("access-control-allow-headers")); + assertEquals(res.status, 404); + const _ = await res.text(); + } finally { + await killFileServer(); + } +}); -- cgit v1.2.3