diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2019-11-04 13:45:29 -0500 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2019-11-04 13:45:29 -0500 |
commit | 0644f9c1a6fd85831dac459f50306781ac2b08e3 (patch) | |
tree | 677ed1199280db6c1b5b7535883055ededd9a0a8 /std/http/server_test.ts | |
parent | 0049d4e50c9dd945f25f69b08b08fbf492001f96 (diff) |
std/http: add serveTLS and listenAndServeTLS (#3257)
Diffstat (limited to 'std/http/server_test.ts')
-rw-r--r-- | std/http/server_test.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/std/http/server_test.ts b/std/http/server_test.ts index 7917aeddd..5baeaa144 100644 --- a/std/http/server_test.ts +++ b/std/http/server_test.ts @@ -529,4 +529,55 @@ test({ } }); +test({ + name: "[http] serveTLS", + async fn(): Promise<void> { + // Runs a simple server as another process + const p = Deno.run({ + args: [ + Deno.execPath(), + "http/testdata/simple_https_server.ts", + "--allow-net", + "--allow-read" + ], + stdout: "piped" + }); + + try { + const r = new TextProtoReader(new BufReader(p.stdout!)); + const s = await r.readLine(); + assert(s !== Deno.EOF && s.includes("server listening")); + + let serverIsRunning = true; + p.status() + .then( + (): void => { + serverIsRunning = false; + } + ) + .catch((_): void => {}); // Ignores the error when closing the process. + + // Requests to the server and immediately closes the connection + const conn = await Deno.dialTLS({ + hostname: "localhost", + port: 4503, + certFile: "http/testdata/tls/RootCA.pem" + }); + await Deno.writeAll( + conn, + new TextEncoder().encode("GET / HTTP/1.0\r\n\r\n") + ); + const res = new Uint8Array(100); + const nread = assertNotEOF(await conn.read(res)); + conn.close(); + const resStr = new TextDecoder().decode(res.subarray(0, nread)); + assert(resStr.includes("Hello HTTPS")); + assert(serverIsRunning); + } finally { + // Stops the sever. + p.close(); + } + } +}); + runIfMain(import.meta); |