summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/045_programmatic_proxy_client.ts16
-rw-r--r--cli/tests/045_proxy_test.ts24
-rw-r--r--cli/tests/045_proxy_test.ts.out2
3 files changed, 42 insertions, 0 deletions
diff --git a/cli/tests/045_programmatic_proxy_client.ts b/cli/tests/045_programmatic_proxy_client.ts
new file mode 100644
index 000000000..50884407d
--- /dev/null
+++ b/cli/tests/045_programmatic_proxy_client.ts
@@ -0,0 +1,16 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+
+const client = Deno.createHttpClient({
+ proxy: {
+ url: "http://localhost:4555",
+ basicAuth: { username: "username", password: "password" },
+ },
+});
+
+const res = await fetch(
+ "http://localhost:4545/test_util/std/examples/colors.ts",
+ { client },
+);
+console.log(`Response http: ${await res.text()}`);
+
+client.close();
diff --git a/cli/tests/045_proxy_test.ts b/cli/tests/045_proxy_test.ts
index c7ba5e967..6e338f4fc 100644
--- a/cli/tests/045_proxy_test.ts
+++ b/cli/tests/045_proxy_test.ts
@@ -15,6 +15,11 @@ async function proxyServer(): Promise<void> {
async function proxyRequest(req: ServerRequest): Promise<void> {
console.log(`Proxy request to: ${req.url}`);
+ const proxyAuthorization = req.headers.get("proxy-authorization");
+ if (proxyAuthorization) {
+ console.log(`proxy-authorization: ${proxyAuthorization}`);
+ req.headers.delete("proxy-authorization");
+ }
const resp = await fetch(req.url, {
method: req.method,
headers: req.headers,
@@ -110,9 +115,28 @@ async function testModuleDownloadNoProxy(): Promise<void> {
http.close();
}
+async function testFetchProgrammaticProxy(): Promise<void> {
+ const c = Deno.run({
+ cmd: [
+ Deno.execPath(),
+ "run",
+ "--quiet",
+ "--reload",
+ "--allow-net=localhost:4545,localhost:4555",
+ "--unstable",
+ "045_programmatic_proxy_client.ts",
+ ],
+ stdout: "piped",
+ });
+ const status = await c.status();
+ assertEquals(status.code, 0);
+ c.close();
+}
+
proxyServer();
await testFetch();
await testModuleDownload();
await testFetchNoProxy();
await testModuleDownloadNoProxy();
+await testFetchProgrammaticProxy();
Deno.exit(0);
diff --git a/cli/tests/045_proxy_test.ts.out b/cli/tests/045_proxy_test.ts.out
index 4b07438ec..4957c9307 100644
--- a/cli/tests/045_proxy_test.ts.out
+++ b/cli/tests/045_proxy_test.ts.out
@@ -2,3 +2,5 @@ Proxy server listening on [WILDCARD]
Proxy request to: http://localhost:4545/test_util/std/examples/colors.ts
Proxy request to: http://localhost:4545/test_util/std/examples/colors.ts
Proxy request to: http://localhost:4545/test_util/std/fmt/colors.ts
+Proxy request to: http://localhost:4545/test_util/std/examples/colors.ts
+proxy-authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=