summaryrefslogtreecommitdiff
path: root/std/http/server_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/http/server_test.ts')
-rw-r--r--std/http/server_test.ts51
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);