diff options
-rw-r--r-- | Cargo.lock | 155 | ||||
-rw-r--r-- | cli/Cargo.toml | 1 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 60 | ||||
-rw-r--r-- | runtime/inspector.rs | 34 |
4 files changed, 235 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock index 87994f6d9..55f3172a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -308,6 +308,22 @@ dependencies = [ ] [[package]] +name = "core-foundation" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" + +[[package]] name = "cpuid-bool" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -432,6 +448,7 @@ dependencies = [ "os_pipe", "percent-encoding", "regex", + "reqwest", "ring", "rustyline", "rustyline-derive", @@ -790,6 +807,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] name = "form_urlencoded" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1133,6 +1165,19 @@ dependencies = [ ] [[package]] +name = "hyper-tls" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed" +dependencies = [ + "bytes 0.5.6", + "hyper", + "native-tls", + "tokio 0.2.22", + "tokio-tls", +] + +[[package]] name = "ident_case" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1505,6 +1550,24 @@ dependencies = [ ] [[package]] +name = "native-tls" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] name = "net2" version = "0.2.35" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1627,6 +1690,39 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] +name = "openssl" +version = "0.10.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038d43985d1ddca7a9900630d8cd031b56e4794eecc2e9ea39dd17aa04399a70" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "foreign-types", + "lazy_static", + "libc", + "openssl-sys", +] + +[[package]] +name = "openssl-probe" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" + +[[package]] +name = "openssl-sys" +version = "0.9.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "921fc71883267538946025deffb622905ecad223c28efbfdef9bb59a0175f3e6" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] name = "ordered-float" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1799,6 +1895,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] +name = "pkg-config" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" + +[[package]] name = "pmutil" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2021,19 +2123,23 @@ dependencies = [ "http-body", "hyper", "hyper-rustls", + "hyper-tls", "ipnet", "js-sys", "lazy_static", "log", "mime", "mime_guess", + "native-tls", "percent-encoding", "pin-project-lite 0.1.7", "rustls", "serde", + "serde_json", "serde_urlencoded", "tokio 0.2.22", "tokio-rustls", + "tokio-tls", "url", "wasm-bindgen", "wasm-bindgen-futures", @@ -2145,6 +2251,16 @@ dependencies = [ ] [[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi 0.3.9", +] + +[[package]] name = "scoped-tls" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2167,6 +2283,29 @@ dependencies = [ ] [[package]] +name = "security-framework" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1759c2e3c8580017a484a7ac56d3abc5a6c1feadf88db2f3633f12ae4268c69" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f99b9d5e26d2a71633cc4f2ebae7cc9f874044e0c351a27e17892d76dce5678b" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] name = "semver" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2902,6 +3041,16 @@ dependencies = [ ] [[package]] +name = "tokio-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" +dependencies = [ + "native-tls", + "tokio 0.2.22", +] + +[[package]] name = "tokio-tungstenite" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3106,6 +3255,12 @@ dependencies = [ ] [[package]] +name = "vcpkg" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" + +[[package]] name = "vec_map" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 5b715ba9d..0349491cb 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -86,6 +86,7 @@ os_pipe = "0.9.2" test_util = { path = "../test_util" } tokio-tungstenite = "0.11.0" tower-test = "0.3.0" +reqwest = {version = "0.10.8", features = ["json"]} [target.'cfg(unix)'.dev-dependencies] exec = "0.3.1" # Used in test_raw_tty diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 9400db4ad..2383db0da 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -4345,6 +4345,66 @@ async fn inspector_runtime_evaluate_does_not_crash() { child.wait().unwrap(); } +#[tokio::test] +async fn inspector_json() { + let script = util::tests_path().join("inspector1.js"); + let mut child = util::deno_cmd() + .arg("run") + .arg(inspect_flag_with_unique_port("--inspect")) + .arg(script) + .stderr(std::process::Stdio::piped()) + .spawn() + .unwrap(); + + let stderr = child.stderr.as_mut().unwrap(); + let mut stderr_lines = + std::io::BufReader::new(stderr).lines().map(|r| r.unwrap()); + let ws_url = extract_ws_url_from_stderr(&mut stderr_lines); + let mut url = ws_url.clone(); + let _ = url.set_scheme("http"); + url.set_path("/json"); + let resp = reqwest::get(url).await.unwrap(); + assert_eq!(resp.status(), reqwest::StatusCode::OK); + let endpoint_list = resp + .json::<Vec<deno_core::serde_json::Value>>() + .await + .unwrap(); + let matching_endpoint = endpoint_list + .iter() + .find(|e| e["webSocketDebuggerUrl"] == ws_url.as_str()); + assert!(matching_endpoint.is_some()); +} + +#[tokio::test] +async fn inspector_json_list() { + let script = util::tests_path().join("inspector1.js"); + let mut child = util::deno_cmd() + .arg("run") + .arg(inspect_flag_with_unique_port("--inspect")) + .arg(script) + .stderr(std::process::Stdio::piped()) + .spawn() + .unwrap(); + + let stderr = child.stderr.as_mut().unwrap(); + let mut stderr_lines = + std::io::BufReader::new(stderr).lines().map(|r| r.unwrap()); + let ws_url = extract_ws_url_from_stderr(&mut stderr_lines); + let mut url = ws_url.clone(); + let _ = url.set_scheme("http"); + url.set_path("/json/list"); + let resp = reqwest::get(url).await.unwrap(); + assert_eq!(resp.status(), reqwest::StatusCode::OK); + let endpoint_list = resp + .json::<Vec<deno_core::serde_json::Value>>() + .await + .unwrap(); + let matching_endpoint = endpoint_list + .iter() + .find(|e| e["webSocketDebuggerUrl"] == ws_url.as_str()); + assert!(matching_endpoint.is_some()); +} + #[test] fn websocket() { let _g = util::http_server(); diff --git a/runtime/inspector.rs b/runtime/inspector.rs index 58df05c54..befaaebee 100644 --- a/runtime/inspector.rs +++ b/runtime/inspector.rs @@ -182,20 +182,21 @@ fn handle_ws_request( .status(http::StatusCode::BAD_REQUEST) .body("Not a valid Websocket Request".into()), }); - tokio::task::spawn_local(async move { - let upgraded = body.on_upgrade().await.unwrap(); - let websocket = tokio_tungstenite::WebSocketStream::from_raw_socket( - upgraded, - tungstenite::protocol::Role::Server, - None, - ) - .await; - let (proxy, pump) = create_websocket_proxy(websocket); - - let _ = new_websocket_tx.unbounded_send(proxy); - pump.await; - }); + if resp.is_ok() { + tokio::task::spawn_local(async move { + let upgraded = body.on_upgrade().await.unwrap(); + let websocket = tokio_tungstenite::WebSocketStream::from_raw_socket( + upgraded, + tungstenite::protocol::Role::Server, + None, + ) + .await; + let (proxy, pump) = create_websocket_proxy(websocket); + let _ = new_websocket_tx.unbounded_send(proxy); + pump.await; + }); + } resp } else { http::Response::builder() @@ -275,11 +276,14 @@ async fn server( (&http::Method::GET, path) if path.starts_with("/ws/") => { handle_ws_request(req, inspector_map.clone()) } + (&http::Method::GET, "/json/version") => { + handle_json_version_request(json_version_response.clone()) + } (&http::Method::GET, "/json") => { handle_json_request(inspector_map.clone()) } - (&http::Method::GET, "/json/version") => { - handle_json_version_request(json_version_response.clone()) + (&http::Method::GET, "/json/list") => { + handle_json_request(inspector_map.clone()) } _ => http::Response::builder() .status(http::StatusCode::NOT_FOUND) |