diff options
author | Yusuke Sakurai <kerokerokerop@gmail.com> | 2019-10-13 23:37:37 +0900 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-10-13 10:37:37 -0400 |
commit | 605659535794ca0d8fe3ee4ea5857b418d7ce091 (patch) | |
tree | c2eb7a7b5fdb2df108a631507f1843ae1dfee84b /cli/js/tls_test.ts | |
parent | b3331e81d920ac6654545094c31bfe07abc750d5 (diff) |
fix: [tls] op_dial_tls is not registerd and broken (#3121)
Diffstat (limited to 'cli/js/tls_test.ts')
-rw-r--r-- | cli/js/tls_test.ts | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/cli/js/tls_test.ts b/cli/js/tls_test.ts index 25900f876..79e6bcad8 100644 --- a/cli/js/tls_test.ts +++ b/cli/js/tls_test.ts @@ -1,6 +1,8 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import { test, testPerm, assert, assertEquals } from "./test_util.ts"; - +import { BufWriter, BufReader } from "../../std/io/bufio.ts"; +import { TextProtoReader } from "../../std/textproto/mod.ts"; +import { runIfMain } from "../../std/testing/mod.ts"; // TODO(ry) The tests in this file use github.com:443, but it would be better to // not rely on an internet connection and rather use a localhost TLS server. @@ -18,8 +20,28 @@ test(async function dialTLSNoPerm(): Promise<void> { testPerm({ net: true }, async function dialTLSBasic(): Promise<void> { const conn = await Deno.dialTLS({ hostname: "github.com", port: 443 }); assert(conn.rid > 0); - const body = new TextEncoder().encode("GET / HTTP/1.0\r\n\r\n"); - const writeResult = await conn.write(body); + const w = new BufWriter(conn); + const r = new BufReader(conn); + let body = "GET / HTTP/1.1\r\n"; + body += "Host: github.com\r\n"; + body += "\r\n"; + const writeResult = await w.write(new TextEncoder().encode(body)); assertEquals(body.length, writeResult); + await w.flush(); + const tpr = new TextProtoReader(r); + const statusLine = await tpr.readLine(); + assert(!!statusLine, "line must be read: " + statusLine); + const m = statusLine.match(/^(.+?) (.+?) (.+?)$/); + assert(m !== null, "must be matched"); + const [_, proto, status, ok] = m; + assertEquals(proto, "HTTP/1.1"); + assertEquals(status, "200"); + assertEquals(ok, "OK"); + const headers = await tpr.readMIMEHeader(); + const contentLength = parseInt(headers.get("content-length")); + const bodyBuf = new Uint8Array(contentLength); + await r.readFull(bodyBuf); conn.close(); }); + +runIfMain(import.meta); |