diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2023-06-13 04:15:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-13 04:15:08 +0200 |
commit | b4ae37a617e5e2a1c248d0d1ac66dcead11e04cd (patch) | |
tree | 7d604b5dcc37f054e1de37eb50afe1cb3571a9de /cli/tests | |
parent | d2c638464d108b945440429cfba0594c20089d76 (diff) |
feat(node): HTTPS server (#19362)
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/unit_node/http_test.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/cli/tests/unit_node/http_test.ts b/cli/tests/unit_node/http_test.ts index 8f87b1fd2..0d15bf889 100644 --- a/cli/tests/unit_node/http_test.ts +++ b/cli/tests/unit_node/http_test.ts @@ -6,6 +6,7 @@ import https from "node:https"; import { assert, assertEquals, + fail, } from "../../../test_util/std/testing/asserts.ts"; import { assertSpyCalls, spy } from "../../../test_util/std/testing/mock.ts"; import { deferred } from "../../../test_util/std/async/deferred.ts"; @@ -617,3 +618,34 @@ Deno.test("[node/http] ClientRequest search params", async () => { await def; assertEquals(body, "foo=bar"); }); + +Deno.test("[node/http] HTTPS server", async () => { + const promise = deferred<void>(); + const promise2 = deferred<void>(); + const client = Deno.createHttpClient({ + caCerts: [Deno.readTextFileSync("cli/tests/testdata/tls/RootCA.pem")], + }); + const server = https.createServer({ + cert: Deno.readTextFileSync("cli/tests/testdata/tls/localhost.crt"), + key: Deno.readTextFileSync("cli/tests/testdata/tls/localhost.key"), + }, (_req, res) => { + res.end("success!"); + }); + server.listen(() => { + // deno-lint-ignore no-explicit-any + fetch(`https://localhost:${(server.address() as any).port}`, { + client, + }).then(async (res) => { + assertEquals(res.status, 200); + assertEquals(await res.text(), "success!"); + server.close(); + promise2.resolve(); + }); + }) + .on("error", () => fail()); + server.on("close", () => { + promise.resolve(); + }); + await Promise.all([promise, promise2]); + client.close(); +}); |