diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2019-09-25 00:52:01 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-09-24 18:52:01 -0400 |
commit | 112ce0df1f9e36a57b520aa59dc1767ba0716bb0 (patch) | |
tree | fa667d29c9cb433f4d09396a36cab43d4421db6c | |
parent | a497f87b59a5271d89cf50063154c46c4e52c523 (diff) |
test: add HTTP_PROXY tests (#2977)
-rw-r--r-- | cli/flags.rs | 4 | ||||
-rw-r--r-- | cli/tests/045_proxy_client.ts | 7 | ||||
-rw-r--r-- | cli/tests/045_proxy_test.ts | 75 | ||||
-rw-r--r-- | cli/tests/045_proxy_test.ts.out | 3 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 5 | ||||
-rw-r--r-- | website/manual.md | 10 |
6 files changed, 99 insertions, 5 deletions
diff --git a/cli/flags.rs b/cli/flags.rs index 2811c2c20..c00137b4f 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -62,7 +62,9 @@ pub struct DenoFlags { static ENV_VARIABLES_HELP: &str = "ENVIRONMENT VARIABLES: DENO_DIR Set deno's base directory - NO_COLOR Set to disable color"; + NO_COLOR Set to disable color + HTTP_PROXY Set proxy address for HTTP requests (module downloads, fetch) + HTTPS_PROXY Set proxy address for HTTPS requests (module downloads, fetch)"; fn add_run_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> { app diff --git a/cli/tests/045_proxy_client.ts b/cli/tests/045_proxy_client.ts new file mode 100644 index 000000000..4fb3db83b --- /dev/null +++ b/cli/tests/045_proxy_client.ts @@ -0,0 +1,7 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +async function main(): Promise<void> { + const res = await fetch("http://deno.land/welcome.ts"); + console.log(`Response http: ${await res.text()}`); +} + +main(); diff --git a/cli/tests/045_proxy_test.ts b/cli/tests/045_proxy_test.ts new file mode 100644 index 000000000..51a17f7a5 --- /dev/null +++ b/cli/tests/045_proxy_test.ts @@ -0,0 +1,75 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +import { + serve, + ServerRequest +} from "../../js/deps/https/deno.land/std/http/server.ts"; +import { assertEquals } from "../../js/deps/https/deno.land/std/testing/asserts.ts"; + +const addr = Deno.args[1] || "127.0.0.1:4555"; + +async function proxyServer(): Promise<void> { + const server = serve(addr); + + console.log(`Proxy server listening on http://${addr}/`); + for await (const req of server) { + proxyRequest(req); + } +} + +async function proxyRequest(req: ServerRequest): Promise<void> { + console.log(`Proxy request to: ${req.url}`); + const resp = await fetch(req.url, { + method: req.method, + headers: req.headers + }); + req.respond(resp); +} + +async function testFetch(): Promise<void> { + const c = Deno.run({ + args: [ + Deno.execPath(), + "--no-prompt", + "--reload", + "--allow-net", + "045_proxy_client.ts" + ], + stdout: "piped", + env: { + HTTP_PROXY: `http://${addr}` + } + }); + + const status = await c.status(); + assertEquals(status.code, 0); + c.close(); +} + +async function testModuleDownload(): Promise<void> { + const http = Deno.run({ + args: [ + Deno.execPath(), + "--no-prompt", + "--reload", + "fetch", + "http://deno.land/welcome.ts" + ], + stdout: "piped", + env: { + HTTP_PROXY: `http://${addr}` + } + }); + + const httpStatus = await http.status(); + assertEquals(httpStatus.code, 0); + http.close(); +} + +async function main(): Promise<void> { + proxyServer(); + await testFetch(); + await testModuleDownload(); + Deno.exit(0); +} + +main(); diff --git a/cli/tests/045_proxy_test.ts.out b/cli/tests/045_proxy_test.ts.out new file mode 100644 index 000000000..7b898bcf1 --- /dev/null +++ b/cli/tests/045_proxy_test.ts.out @@ -0,0 +1,3 @@ +Proxy server listening on [WILDCARD] +Proxy request to: http://deno.land/welcome.ts +Proxy request to: http://deno.land/welcome.ts diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index fd5efca18..4bb7fbe6e 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -317,6 +317,11 @@ itest!(_044_bad_resource { exit_code: 1, }); +itest!(_045_proxy { + args: "run --allow-net --allow-env --allow-run --reload 045_proxy_test.ts", + output: "045_proxy_test.ts.out", +}); + itest!(async_error { exit_code: 1, args: "run --reload async_error.ts", diff --git a/website/manual.md b/website/manual.md index ead3dddac..7a659460c 100644 --- a/website/manual.md +++ b/website/manual.md @@ -712,6 +712,8 @@ SUBCOMMANDS: ENVIRONMENT VARIABLES: DENO_DIR Set deno's base directory NO_COLOR Set to disable color + HTTP_PROXY Set proxy address for HTTP requests (module downloads, fetch) + HTTPS_PROXY Set proxy address for HTTPS requests (module downloads, fetch) ``` ### Environmental variables @@ -876,12 +878,12 @@ $ deno install awesome_cli https://example.com/awesome/cli.ts ## Proxies -Deno supports proxies. +Deno supports proxies for module downloads and `fetch` API. -`HTTP_PROXY` and `HTTPS_PROXY` environmental variables are used to configure -them. +Proxy configuration is read from environmental variables: `HTTP_PROXY` and +`HTTPS_PROXY`. -For Windows if environmental variables are not found Deno will fall back to +In case of Windows if environmental variables are not found Deno falls back to reading proxies from registry. ## Import maps |