Skip to content

Commit

Permalink
fix: [tls] op_dial_tls is not registerd and broken (#3121)
Browse files Browse the repository at this point in the history
  • Loading branch information
keroxp authored and ry committed Oct 13, 2019
1 parent b3331e8 commit 6056595
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
28 changes: 25 additions & 3 deletions cli/js/tls_test.ts
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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);
1 change: 1 addition & 0 deletions cli/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ pub mod random;
pub mod repl;
pub mod resources;
pub mod timers;
pub mod tls;
pub mod workers;
1 change: 0 additions & 1 deletion cli/ops/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use tokio::net::TcpStream;
pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
i.register_op("accept", s.core_op(json_op(s.stateful_op(op_accept))));
i.register_op("dial", s.core_op(json_op(s.stateful_op(op_dial))));
i.register_op("dial_tls", s.core_op(json_op(s.stateful_op(op_dial))));
i.register_op("shutdown", s.core_op(json_op(s.stateful_op(op_shutdown))));
i.register_op("listen", s.core_op(json_op(s.stateful_op(op_listen))));
}
Expand Down
4 changes: 4 additions & 0 deletions cli/ops/tls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use super::dispatch_json::{Deserialize, JsonOp, Value};
use crate::ops::json_op;
use crate::resolve_addr::resolve_addr;
use crate::resources;
use crate::state::ThreadSafeState;
Expand All @@ -20,6 +21,9 @@ struct DialTLSArgs {
hostname: String,
port: u16,
}
pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
i.register_op("dial_tls", s.core_op(json_op(s.stateful_op(op_dial_tls))));
}

pub fn op_dial_tls(
state: &ThreadSafeState,
Expand Down
1 change: 1 addition & 0 deletions cli/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl Worker {
ops::fs::init(&mut i, &state);
ops::io::init(&mut i, &state);
ops::net::init(&mut i, &state);
ops::tls::init(&mut i, &state);
ops::os::init(&mut i, &state);
ops::permissions::init(&mut i, &state);
ops::process::init(&mut i, &state);
Expand Down

0 comments on commit 6056595

Please sign in to comment.