2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2021-06-27 13:27:36 -04:00
|
|
|
|
|
|
|
use crate::itest;
|
|
|
|
use deno_core::url;
|
2021-09-26 14:26:16 -04:00
|
|
|
use deno_runtime::deno_fetch::reqwest;
|
2021-06-28 19:43:03 -04:00
|
|
|
use deno_runtime::deno_net::ops_tls::TlsStream;
|
2021-08-07 08:49:38 -04:00
|
|
|
use deno_runtime::deno_tls::rustls;
|
2021-12-06 18:48:11 -05:00
|
|
|
use deno_runtime::deno_tls::rustls_pemfile;
|
2021-06-27 13:27:36 -04:00
|
|
|
use std::fs;
|
|
|
|
use std::io::BufReader;
|
|
|
|
use std::io::Cursor;
|
|
|
|
use std::io::{Read, Write};
|
|
|
|
use std::process::Command;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use test_util as util;
|
2022-04-01 11:15:37 -04:00
|
|
|
use test_util::TempDir;
|
2021-06-27 13:27:36 -04:00
|
|
|
use tokio::task::LocalSet;
|
2022-05-14 08:08:35 -04:00
|
|
|
use trust_dns_client::serialize::txt::Lexer;
|
|
|
|
use trust_dns_client::serialize::txt::Parser;
|
2021-06-27 13:27:36 -04:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! itest(
|
|
|
|
($name:ident {$( $key:ident: $value:expr,)*}) => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
|
|
|
(test_util::CheckOutputIntegrationTest {
|
|
|
|
$(
|
|
|
|
$key: $value,
|
|
|
|
)*
|
|
|
|
.. Default::default()
|
|
|
|
}).run()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-08-11 11:38:07 -04:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! itest_flaky(
|
|
|
|
($name:ident {$( $key:ident: $value:expr,)*}) => {
|
|
|
|
#[flaky_test::flaky_test]
|
|
|
|
fn $name() {
|
|
|
|
(test_util::CheckOutputIntegrationTest {
|
|
|
|
$(
|
|
|
|
$key: $value,
|
|
|
|
)*
|
|
|
|
.. Default::default()
|
|
|
|
}).run()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2021-06-27 13:27:36 -04:00
|
|
|
// These files have `_tests.rs` suffix to make it easier to tell which file is
|
|
|
|
// the test (ex. `lint_tests.rs`) and which is the implementation (ex. `lint.rs`)
|
|
|
|
// when both are open, especially for two tabs in VS Code
|
|
|
|
|
2022-03-11 17:07:02 -05:00
|
|
|
#[path = "bench_tests.rs"]
|
|
|
|
mod bench;
|
2021-06-27 13:27:36 -04:00
|
|
|
#[path = "bundle_tests.rs"]
|
|
|
|
mod bundle;
|
|
|
|
#[path = "cache_tests.rs"]
|
|
|
|
mod cache;
|
2022-04-10 19:12:51 -04:00
|
|
|
#[path = "check_tests.rs"]
|
|
|
|
mod check;
|
2021-10-04 19:35:55 -04:00
|
|
|
#[path = "compat_tests.rs"]
|
|
|
|
mod compat;
|
2021-06-27 13:27:36 -04:00
|
|
|
#[path = "compile_tests.rs"]
|
|
|
|
mod compile;
|
|
|
|
#[path = "coverage_tests.rs"]
|
|
|
|
mod coverage;
|
|
|
|
#[path = "doc_tests.rs"]
|
|
|
|
mod doc;
|
|
|
|
#[path = "eval_tests.rs"]
|
|
|
|
mod eval;
|
|
|
|
#[path = "fmt_tests.rs"]
|
|
|
|
mod fmt;
|
|
|
|
#[path = "info_tests.rs"]
|
|
|
|
mod info;
|
|
|
|
#[path = "inspector_tests.rs"]
|
|
|
|
mod inspector;
|
|
|
|
#[path = "install_tests.rs"]
|
|
|
|
mod install;
|
|
|
|
#[path = "lint_tests.rs"]
|
|
|
|
mod lint;
|
|
|
|
#[path = "lsp_tests.rs"]
|
|
|
|
mod lsp;
|
|
|
|
#[path = "repl_tests.rs"]
|
|
|
|
mod repl;
|
|
|
|
#[path = "run_tests.rs"]
|
|
|
|
mod run;
|
2022-03-10 20:56:14 -05:00
|
|
|
#[path = "task_tests.rs"]
|
|
|
|
mod task;
|
2021-06-27 13:27:36 -04:00
|
|
|
#[path = "test_tests.rs"]
|
|
|
|
mod test;
|
|
|
|
#[path = "upgrade_tests.rs"]
|
|
|
|
mod upgrade;
|
2022-02-16 13:14:19 -05:00
|
|
|
#[path = "vendor_tests.rs"]
|
|
|
|
mod vendor;
|
2021-06-27 13:27:36 -04:00
|
|
|
#[path = "watcher_tests.rs"]
|
|
|
|
mod watcher;
|
|
|
|
#[path = "worker_tests.rs"]
|
|
|
|
mod worker;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn help_flag() {
|
|
|
|
let status = util::deno_cmd()
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("--help")
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
assert!(status.success());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn version_short_flag() {
|
|
|
|
let status = util::deno_cmd()
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("-V")
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
assert!(status.success());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn version_long_flag() {
|
|
|
|
let status = util::deno_cmd()
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("--version")
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
assert!(status.success());
|
|
|
|
}
|
|
|
|
|
|
|
|
itest!(types {
|
|
|
|
args: "types",
|
|
|
|
output: "types.out",
|
|
|
|
});
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cache_test() {
|
|
|
|
let _g = util::http_server();
|
2022-04-01 11:15:37 -04:00
|
|
|
let deno_dir = TempDir::new();
|
2021-06-27 13:27:36 -04:00
|
|
|
let module_url =
|
2021-08-11 10:20:47 -04:00
|
|
|
url::Url::parse("http://localhost:4545/006_url_imports.ts").unwrap();
|
2021-06-27 13:27:36 -04:00
|
|
|
let output = Command::new(util::deno_exe_path())
|
|
|
|
.env("DENO_DIR", deno_dir.path())
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("cache")
|
2022-06-13 17:13:16 -04:00
|
|
|
.arg("--check=all")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("-L")
|
|
|
|
.arg("debug")
|
|
|
|
.arg(module_url.to_string())
|
|
|
|
.output()
|
|
|
|
.expect("Failed to spawn script");
|
|
|
|
assert!(output.status.success());
|
|
|
|
|
|
|
|
let out = std::str::from_utf8(&output.stderr).unwrap();
|
|
|
|
// Check if file and dependencies are written successfully
|
|
|
|
assert!(out.contains("host.writeFile(\"deno://subdir/print_hello.js\")"));
|
|
|
|
assert!(out.contains("host.writeFile(\"deno://subdir/mod2.js\")"));
|
|
|
|
assert!(out.contains("host.writeFile(\"deno://006_url_imports.js\")"));
|
|
|
|
|
|
|
|
let prg = util::deno_exe_path();
|
|
|
|
let output = Command::new(&prg)
|
|
|
|
.env("DENO_DIR", deno_dir.path())
|
|
|
|
.env("HTTP_PROXY", "http://nil")
|
|
|
|
.env("NO_COLOR", "1")
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("run")
|
|
|
|
.arg(module_url.to_string())
|
|
|
|
.output()
|
|
|
|
.expect("Failed to spawn script");
|
|
|
|
|
|
|
|
let str_output = std::str::from_utf8(&output.stdout).unwrap();
|
|
|
|
|
2021-08-11 10:20:47 -04:00
|
|
|
let module_output_path = util::testdata_path().join("006_url_imports.ts.out");
|
2021-06-27 13:27:36 -04:00
|
|
|
let mut module_output = String::new();
|
|
|
|
let mut module_output_file = fs::File::open(module_output_path).unwrap();
|
|
|
|
module_output_file
|
|
|
|
.read_to_string(&mut module_output)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_eq!(module_output, str_output);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cache_invalidation_test() {
|
2022-04-01 11:15:37 -04:00
|
|
|
let deno_dir = TempDir::new();
|
2021-06-27 13:27:36 -04:00
|
|
|
let fixture_path = deno_dir.path().join("fixture.ts");
|
|
|
|
{
|
|
|
|
let mut file = std::fs::File::create(fixture_path.clone())
|
|
|
|
.expect("could not create fixture");
|
|
|
|
file
|
|
|
|
.write_all(b"console.log(\"42\");")
|
|
|
|
.expect("could not write fixture");
|
|
|
|
}
|
|
|
|
let output = Command::new(util::deno_exe_path())
|
|
|
|
.env("DENO_DIR", deno_dir.path())
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("run")
|
|
|
|
.arg(fixture_path.to_str().unwrap())
|
|
|
|
.output()
|
|
|
|
.expect("Failed to spawn script");
|
|
|
|
assert!(output.status.success());
|
|
|
|
let actual = std::str::from_utf8(&output.stdout).unwrap();
|
|
|
|
assert_eq!(actual, "42\n");
|
|
|
|
{
|
|
|
|
let mut file = std::fs::File::create(fixture_path.clone())
|
|
|
|
.expect("could not create fixture");
|
|
|
|
file
|
|
|
|
.write_all(b"console.log(\"43\");")
|
|
|
|
.expect("could not write fixture");
|
|
|
|
}
|
|
|
|
let output = Command::new(util::deno_exe_path())
|
|
|
|
.env("DENO_DIR", deno_dir.path())
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("run")
|
|
|
|
.arg(fixture_path.to_str().unwrap())
|
|
|
|
.output()
|
|
|
|
.expect("Failed to spawn script");
|
|
|
|
assert!(output.status.success());
|
|
|
|
let actual = std::str::from_utf8(&output.stdout).unwrap();
|
|
|
|
assert_eq!(actual, "43\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cache_invalidation_test_no_check() {
|
2022-04-01 11:15:37 -04:00
|
|
|
let deno_dir = TempDir::new();
|
2021-06-27 13:27:36 -04:00
|
|
|
let fixture_path = deno_dir.path().join("fixture.ts");
|
|
|
|
{
|
|
|
|
let mut file = std::fs::File::create(fixture_path.clone())
|
|
|
|
.expect("could not create fixture");
|
|
|
|
file
|
|
|
|
.write_all(b"console.log(\"42\");")
|
|
|
|
.expect("could not write fixture");
|
|
|
|
}
|
|
|
|
let output = Command::new(util::deno_exe_path())
|
|
|
|
.env("DENO_DIR", deno_dir.path())
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("run")
|
|
|
|
.arg("--no-check")
|
|
|
|
.arg(fixture_path.to_str().unwrap())
|
|
|
|
.output()
|
|
|
|
.expect("Failed to spawn script");
|
|
|
|
assert!(output.status.success());
|
|
|
|
let actual = std::str::from_utf8(&output.stdout).unwrap();
|
|
|
|
assert_eq!(actual, "42\n");
|
|
|
|
{
|
|
|
|
let mut file = std::fs::File::create(fixture_path.clone())
|
|
|
|
.expect("could not create fixture");
|
|
|
|
file
|
|
|
|
.write_all(b"console.log(\"43\");")
|
|
|
|
.expect("could not write fixture");
|
|
|
|
}
|
|
|
|
let output = Command::new(util::deno_exe_path())
|
|
|
|
.env("DENO_DIR", deno_dir.path())
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("run")
|
|
|
|
.arg("--no-check")
|
|
|
|
.arg(fixture_path.to_str().unwrap())
|
|
|
|
.output()
|
|
|
|
.expect("Failed to spawn script");
|
|
|
|
assert!(output.status.success());
|
|
|
|
let actual = std::str::from_utf8(&output.stdout).unwrap();
|
|
|
|
assert_eq!(actual, "43\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ts_dependency_recompilation() {
|
2022-04-01 11:15:37 -04:00
|
|
|
let t = TempDir::new();
|
2021-06-27 13:27:36 -04:00
|
|
|
let ats = t.path().join("a.ts");
|
|
|
|
|
|
|
|
std::fs::write(
|
|
|
|
&ats,
|
|
|
|
"
|
|
|
|
import { foo } from \"./b.ts\";
|
|
|
|
|
|
|
|
function print(str: string): void {
|
|
|
|
console.log(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
print(foo);",
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let bts = t.path().join("b.ts");
|
|
|
|
std::fs::write(
|
|
|
|
&bts,
|
|
|
|
"
|
|
|
|
export const foo = \"foo\";",
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let output = util::deno_cmd()
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.env("NO_COLOR", "1")
|
|
|
|
.arg("run")
|
2022-04-10 19:12:51 -04:00
|
|
|
.arg("--check")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg(&ats)
|
|
|
|
.output()
|
|
|
|
.expect("failed to spawn script");
|
|
|
|
|
|
|
|
let stdout_output = std::str::from_utf8(&output.stdout).unwrap().trim();
|
|
|
|
let stderr_output = std::str::from_utf8(&output.stderr).unwrap().trim();
|
|
|
|
|
|
|
|
assert!(stdout_output.ends_with("foo"));
|
|
|
|
assert!(stderr_output.starts_with("Check"));
|
|
|
|
|
|
|
|
// Overwrite contents of b.ts and run again
|
|
|
|
std::fs::write(
|
|
|
|
&bts,
|
|
|
|
"
|
|
|
|
export const foo = 5;",
|
|
|
|
)
|
|
|
|
.expect("error writing file");
|
|
|
|
|
|
|
|
let output = util::deno_cmd()
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.env("NO_COLOR", "1")
|
|
|
|
.arg("run")
|
2022-04-10 19:12:51 -04:00
|
|
|
.arg("--check")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg(&ats)
|
|
|
|
.output()
|
|
|
|
.expect("failed to spawn script");
|
|
|
|
|
|
|
|
let stdout_output = std::str::from_utf8(&output.stdout).unwrap().trim();
|
|
|
|
let stderr_output = std::str::from_utf8(&output.stderr).unwrap().trim();
|
|
|
|
|
|
|
|
// error: TS2345 [ERROR]: Argument of type '5' is not assignable to parameter of type 'string'.
|
|
|
|
assert!(stderr_output.contains("TS2345"));
|
|
|
|
assert!(!output.status.success());
|
|
|
|
assert!(stdout_output.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ts_no_recheck_on_redirect() {
|
|
|
|
let deno_dir = util::new_deno_dir();
|
|
|
|
let e = util::deno_exe_path();
|
|
|
|
|
2021-08-11 10:20:47 -04:00
|
|
|
let redirect_ts = util::testdata_path().join("017_import_redirect.ts");
|
2021-06-27 13:27:36 -04:00
|
|
|
assert!(redirect_ts.is_file());
|
|
|
|
let mut cmd = Command::new(e.clone());
|
|
|
|
cmd.env("DENO_DIR", deno_dir.path());
|
|
|
|
let mut initial = cmd
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("run")
|
2022-04-10 19:12:51 -04:00
|
|
|
.arg("--check")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg(redirect_ts.clone())
|
|
|
|
.spawn()
|
|
|
|
.expect("failed to span script");
|
|
|
|
let status_initial =
|
|
|
|
initial.wait().expect("failed to wait for child process");
|
|
|
|
assert!(status_initial.success());
|
|
|
|
|
|
|
|
let mut cmd = Command::new(e);
|
|
|
|
cmd.env("DENO_DIR", deno_dir.path());
|
|
|
|
let output = cmd
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("run")
|
2022-04-10 19:12:51 -04:00
|
|
|
.arg("--check")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg(redirect_ts)
|
|
|
|
.output()
|
|
|
|
.expect("failed to spawn script");
|
|
|
|
|
|
|
|
assert!(std::str::from_utf8(&output.stderr).unwrap().is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ts_reload() {
|
2021-08-11 10:20:47 -04:00
|
|
|
let hello_ts = util::testdata_path().join("002_hello.ts");
|
2021-06-27 13:27:36 -04:00
|
|
|
assert!(hello_ts.is_file());
|
|
|
|
|
2022-04-01 11:15:37 -04:00
|
|
|
let deno_dir = TempDir::new();
|
|
|
|
let mut initial = util::deno_cmd_with_deno_dir(&deno_dir)
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("cache")
|
2022-06-13 17:13:16 -04:00
|
|
|
.arg("--check=all")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg(&hello_ts)
|
|
|
|
.spawn()
|
|
|
|
.expect("failed to spawn script");
|
|
|
|
let status_initial =
|
|
|
|
initial.wait().expect("failed to wait for child process");
|
|
|
|
assert!(status_initial.success());
|
|
|
|
|
2022-04-01 11:15:37 -04:00
|
|
|
let output = util::deno_cmd_with_deno_dir(&deno_dir)
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("cache")
|
2022-06-13 17:13:16 -04:00
|
|
|
.arg("--check=all")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("--reload")
|
|
|
|
.arg("-L")
|
|
|
|
.arg("debug")
|
|
|
|
.arg(&hello_ts)
|
|
|
|
.output()
|
|
|
|
.expect("failed to spawn script");
|
|
|
|
|
|
|
|
// check the output of the the bundle program.
|
|
|
|
let output_path = hello_ts.canonicalize().unwrap();
|
2021-12-16 05:45:41 -05:00
|
|
|
assert!(
|
|
|
|
dbg!(std::str::from_utf8(&output.stderr).unwrap().trim()).contains(
|
|
|
|
&format!(
|
|
|
|
"host.getSourceFile(\"{}\", Latest)",
|
|
|
|
url::Url::from_file_path(&output_path).unwrap().as_str()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2021-06-27 13:27:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn timeout_clear() {
|
|
|
|
// https://github.com/denoland/deno/issues/7599
|
|
|
|
|
|
|
|
use std::time::Duration;
|
|
|
|
use std::time::Instant;
|
|
|
|
|
|
|
|
let source_code = r#"
|
|
|
|
const handle = setTimeout(() => {
|
|
|
|
console.log("timeout finish");
|
|
|
|
}, 10000);
|
|
|
|
clearTimeout(handle);
|
|
|
|
console.log("finish");
|
|
|
|
"#;
|
|
|
|
|
|
|
|
let mut p = util::deno_cmd()
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("run")
|
|
|
|
.arg("-")
|
|
|
|
.stdin(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let stdin = p.stdin.as_mut().unwrap();
|
|
|
|
stdin.write_all(source_code.as_bytes()).unwrap();
|
|
|
|
let start = Instant::now();
|
|
|
|
let status = p.wait().unwrap();
|
|
|
|
let end = Instant::now();
|
|
|
|
assert!(status.success());
|
|
|
|
// check that program did not run for 10 seconds
|
|
|
|
// for timeout to clear
|
|
|
|
assert!(end - start < Duration::new(10, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn broken_stdout() {
|
|
|
|
let (reader, writer) = os_pipe::pipe().unwrap();
|
|
|
|
// drop the reader to create a broken pipe
|
|
|
|
drop(reader);
|
|
|
|
|
|
|
|
let output = util::deno_cmd()
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("eval")
|
|
|
|
.arg("console.log(3.14)")
|
|
|
|
.stdout(writer)
|
|
|
|
.stderr(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait_with_output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(!output.status.success());
|
|
|
|
let stderr = std::str::from_utf8(output.stderr.as_ref()).unwrap().trim();
|
|
|
|
assert!(stderr.contains("Uncaught BrokenPipe"));
|
|
|
|
assert!(!stderr.contains("panic"));
|
|
|
|
}
|
|
|
|
|
2021-12-29 13:34:13 -05:00
|
|
|
itest!(error_cause {
|
|
|
|
args: "run error_cause.ts",
|
|
|
|
output: "error_cause.ts.out",
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
itest!(error_cause_recursive {
|
|
|
|
args: "run error_cause_recursive.ts",
|
|
|
|
output: "error_cause_recursive.ts.out",
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
2021-08-11 11:38:07 -04:00
|
|
|
itest_flaky!(cafile_url_imports {
|
2021-08-11 05:52:52 -04:00
|
|
|
args: "run --quiet --reload --cert tls/RootCA.pem cafile_url_imports.ts",
|
|
|
|
output: "cafile_url_imports.ts.out",
|
|
|
|
http_server: true,
|
|
|
|
});
|
|
|
|
|
2021-08-11 11:38:07 -04:00
|
|
|
itest_flaky!(cafile_ts_fetch {
|
2021-08-11 05:52:52 -04:00
|
|
|
args:
|
|
|
|
"run --quiet --reload --allow-net --cert tls/RootCA.pem cafile_ts_fetch.ts",
|
|
|
|
output: "cafile_ts_fetch.ts.out",
|
|
|
|
http_server: true,
|
|
|
|
});
|
|
|
|
|
2021-08-11 11:38:07 -04:00
|
|
|
itest_flaky!(cafile_eval {
|
2021-08-11 10:20:47 -04:00
|
|
|
args: "eval --cert tls/RootCA.pem fetch('https://localhost:5545/cafile_ts_fetch.ts.out').then(r=>r.text()).then(t=>console.log(t.trimEnd()))",
|
2021-08-11 05:52:52 -04:00
|
|
|
output: "cafile_ts_fetch.ts.out",
|
|
|
|
http_server: true,
|
|
|
|
});
|
|
|
|
|
2021-08-11 11:38:07 -04:00
|
|
|
itest_flaky!(cafile_info {
|
2021-08-11 05:52:52 -04:00
|
|
|
args:
|
2021-08-11 10:20:47 -04:00
|
|
|
"info --quiet --cert tls/RootCA.pem https://localhost:5545/cafile_info.ts",
|
2021-08-11 05:52:52 -04:00
|
|
|
output: "cafile_info.ts.out",
|
|
|
|
http_server: true,
|
|
|
|
});
|
2021-06-27 13:27:36 -04:00
|
|
|
|
2021-08-11 11:38:07 -04:00
|
|
|
itest_flaky!(cafile_url_imports_unsafe_ssl {
|
2021-08-10 07:19:45 -04:00
|
|
|
args: "run --quiet --reload --unsafely-ignore-certificate-errors=localhost cafile_url_imports.ts",
|
2021-08-09 10:53:21 -04:00
|
|
|
output: "cafile_url_imports_unsafe_ssl.ts.out",
|
|
|
|
http_server: true,
|
|
|
|
});
|
|
|
|
|
2021-08-11 11:38:07 -04:00
|
|
|
itest_flaky!(cafile_ts_fetch_unsafe_ssl {
|
2021-08-09 10:53:21 -04:00
|
|
|
args:
|
2021-08-10 07:19:45 -04:00
|
|
|
"run --quiet --reload --allow-net --unsafely-ignore-certificate-errors cafile_ts_fetch.ts",
|
2021-08-09 10:53:21 -04:00
|
|
|
output: "cafile_ts_fetch_unsafe_ssl.ts.out",
|
|
|
|
http_server: true,
|
|
|
|
});
|
|
|
|
|
2021-08-10 10:22:21 -04:00
|
|
|
itest!(deno_land_unsafe_ssl {
|
|
|
|
args:
|
|
|
|
"run --quiet --reload --allow-net --unsafely-ignore-certificate-errors=deno.land deno_land_unsafe_ssl.ts",
|
|
|
|
output: "deno_land_unsafe_ssl.ts.out",
|
|
|
|
});
|
|
|
|
|
2022-05-18 07:32:12 -04:00
|
|
|
itest!(ip_address_unsafe_ssl {
|
|
|
|
args:
|
|
|
|
"run --quiet --reload --allow-net --unsafely-ignore-certificate-errors=1.1.1.1 ip_address_unsafe_ssl.ts",
|
|
|
|
output: "ip_address_unsafe_ssl.ts.out",
|
|
|
|
});
|
|
|
|
|
2021-08-10 10:22:21 -04:00
|
|
|
itest!(localhost_unsafe_ssl {
|
|
|
|
args:
|
|
|
|
"run --quiet --reload --allow-net --unsafely-ignore-certificate-errors=deno.land cafile_url_imports.ts",
|
|
|
|
output: "localhost_unsafe_ssl.ts.out",
|
|
|
|
http_server: true,
|
|
|
|
exit_code: 1,
|
|
|
|
});
|
|
|
|
|
2021-08-11 11:38:07 -04:00
|
|
|
#[flaky_test::flaky_test]
|
2021-06-27 13:27:36 -04:00
|
|
|
fn cafile_env_fetch() {
|
|
|
|
use deno_core::url::Url;
|
|
|
|
let _g = util::http_server();
|
2022-04-01 11:15:37 -04:00
|
|
|
let deno_dir = TempDir::new();
|
2021-06-27 13:27:36 -04:00
|
|
|
let module_url =
|
2021-08-11 10:20:47 -04:00
|
|
|
Url::parse("https://localhost:5545/cafile_url_imports.ts").unwrap();
|
|
|
|
let cafile = util::testdata_path().join("tls/RootCA.pem");
|
2021-06-27 13:27:36 -04:00
|
|
|
let output = Command::new(util::deno_exe_path())
|
|
|
|
.env("DENO_DIR", deno_dir.path())
|
|
|
|
.env("DENO_CERT", cafile)
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("cache")
|
|
|
|
.arg(module_url.to_string())
|
|
|
|
.output()
|
|
|
|
.expect("Failed to spawn script");
|
|
|
|
assert!(output.status.success());
|
|
|
|
}
|
|
|
|
|
2021-08-11 11:38:07 -04:00
|
|
|
#[flaky_test::flaky_test]
|
2021-06-27 13:27:36 -04:00
|
|
|
fn cafile_fetch() {
|
|
|
|
use deno_core::url::Url;
|
|
|
|
let _g = util::http_server();
|
2022-04-01 11:15:37 -04:00
|
|
|
let deno_dir = TempDir::new();
|
2021-06-27 13:27:36 -04:00
|
|
|
let module_url =
|
2021-08-11 10:20:47 -04:00
|
|
|
Url::parse("http://localhost:4545/cafile_url_imports.ts").unwrap();
|
|
|
|
let cafile = util::testdata_path().join("tls/RootCA.pem");
|
2021-06-27 13:27:36 -04:00
|
|
|
let output = Command::new(util::deno_exe_path())
|
|
|
|
.env("DENO_DIR", deno_dir.path())
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("cache")
|
|
|
|
.arg("--cert")
|
|
|
|
.arg(cafile)
|
|
|
|
.arg(module_url.to_string())
|
|
|
|
.output()
|
|
|
|
.expect("Failed to spawn script");
|
|
|
|
assert!(output.status.success());
|
|
|
|
let out = std::str::from_utf8(&output.stdout).unwrap();
|
|
|
|
assert_eq!(out, "");
|
|
|
|
}
|
|
|
|
|
2021-08-11 11:38:07 -04:00
|
|
|
#[flaky_test::flaky_test]
|
2021-06-27 13:27:36 -04:00
|
|
|
fn cafile_install_remote_module() {
|
|
|
|
let _g = util::http_server();
|
2022-04-01 11:15:37 -04:00
|
|
|
let temp_dir = TempDir::new();
|
2021-06-27 13:27:36 -04:00
|
|
|
let bin_dir = temp_dir.path().join("bin");
|
|
|
|
std::fs::create_dir(&bin_dir).unwrap();
|
2022-04-01 11:15:37 -04:00
|
|
|
let deno_dir = TempDir::new();
|
2021-08-11 10:20:47 -04:00
|
|
|
let cafile = util::testdata_path().join("tls/RootCA.pem");
|
2021-06-27 13:27:36 -04:00
|
|
|
|
|
|
|
let install_output = Command::new(util::deno_exe_path())
|
|
|
|
.env("DENO_DIR", deno_dir.path())
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("install")
|
|
|
|
.arg("--cert")
|
|
|
|
.arg(cafile)
|
|
|
|
.arg("--root")
|
|
|
|
.arg(temp_dir.path())
|
|
|
|
.arg("-n")
|
|
|
|
.arg("echo_test")
|
2021-08-11 10:20:47 -04:00
|
|
|
.arg("https://localhost:5545/echo.ts")
|
2021-06-27 13:27:36 -04:00
|
|
|
.output()
|
|
|
|
.expect("Failed to spawn script");
|
|
|
|
println!("{}", std::str::from_utf8(&install_output.stdout).unwrap());
|
|
|
|
eprintln!("{}", std::str::from_utf8(&install_output.stderr).unwrap());
|
|
|
|
assert!(install_output.status.success());
|
|
|
|
|
|
|
|
let mut echo_test_path = bin_dir.join("echo_test");
|
|
|
|
if cfg!(windows) {
|
|
|
|
echo_test_path = echo_test_path.with_extension("cmd");
|
|
|
|
}
|
|
|
|
assert!(echo_test_path.exists());
|
|
|
|
|
|
|
|
let output = Command::new(echo_test_path)
|
|
|
|
.current_dir(temp_dir.path())
|
|
|
|
.arg("foo")
|
|
|
|
.env("PATH", util::target_dir())
|
|
|
|
.output()
|
|
|
|
.expect("failed to spawn script");
|
|
|
|
let stdout = std::str::from_utf8(&output.stdout).unwrap().trim();
|
|
|
|
assert!(stdout.ends_with("foo"));
|
|
|
|
}
|
|
|
|
|
2021-08-11 11:38:07 -04:00
|
|
|
#[flaky_test::flaky_test]
|
2021-06-27 13:27:36 -04:00
|
|
|
fn cafile_bundle_remote_exports() {
|
|
|
|
let _g = util::http_server();
|
|
|
|
|
|
|
|
// First we have to generate a bundle of some remote module that has exports.
|
2021-08-11 10:20:47 -04:00
|
|
|
let mod1 = "https://localhost:5545/subdir/mod1.ts";
|
|
|
|
let cafile = util::testdata_path().join("tls/RootCA.pem");
|
2022-04-01 11:15:37 -04:00
|
|
|
let t = TempDir::new();
|
2021-06-27 13:27:36 -04:00
|
|
|
let bundle = t.path().join("mod1.bundle.js");
|
|
|
|
let mut deno = util::deno_cmd()
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("bundle")
|
|
|
|
.arg("--cert")
|
|
|
|
.arg(cafile)
|
|
|
|
.arg(mod1)
|
|
|
|
.arg(&bundle)
|
|
|
|
.spawn()
|
|
|
|
.expect("failed to spawn script");
|
|
|
|
let status = deno.wait().expect("failed to wait for the child process");
|
|
|
|
assert!(status.success());
|
|
|
|
assert!(bundle.is_file());
|
|
|
|
|
|
|
|
// Now we try to use that bundle from another module.
|
|
|
|
let test = t.path().join("test.js");
|
|
|
|
std::fs::write(
|
|
|
|
&test,
|
|
|
|
"
|
|
|
|
import { printHello3 } from \"./mod1.bundle.js\";
|
|
|
|
printHello3(); ",
|
|
|
|
)
|
|
|
|
.expect("error writing file");
|
|
|
|
|
|
|
|
let output = util::deno_cmd()
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("run")
|
2022-04-10 19:12:51 -04:00
|
|
|
.arg("--check")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg(&test)
|
|
|
|
.output()
|
|
|
|
.expect("failed to spawn script");
|
|
|
|
// check the output of the test.ts program.
|
|
|
|
assert!(std::str::from_utf8(&output.stdout)
|
|
|
|
.unwrap()
|
|
|
|
.trim()
|
|
|
|
.ends_with("Hello"));
|
|
|
|
assert_eq!(output.stderr, b"");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn websocket() {
|
|
|
|
let _g = util::http_server();
|
|
|
|
|
2021-08-11 10:20:47 -04:00
|
|
|
let script = util::testdata_path().join("websocket_test.ts");
|
|
|
|
let root_ca = util::testdata_path().join("tls/RootCA.pem");
|
2021-06-27 13:27:36 -04:00
|
|
|
let status = util::deno_cmd()
|
|
|
|
.arg("test")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg("--allow-net")
|
|
|
|
.arg("--cert")
|
|
|
|
.arg(root_ca)
|
|
|
|
.arg(script)
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(status.success());
|
|
|
|
}
|
|
|
|
|
2021-08-09 18:28:17 -04:00
|
|
|
#[test]
|
|
|
|
fn websocketstream() {
|
|
|
|
let _g = util::http_server();
|
|
|
|
|
2021-08-11 10:20:47 -04:00
|
|
|
let script = util::testdata_path().join("websocketstream_test.ts");
|
|
|
|
let root_ca = util::testdata_path().join("tls/RootCA.pem");
|
2021-08-09 18:28:17 -04:00
|
|
|
let status = util::deno_cmd()
|
|
|
|
.arg("test")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg("--allow-net")
|
|
|
|
.arg("--cert")
|
|
|
|
.arg(root_ca)
|
|
|
|
.arg(script)
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(status.success());
|
|
|
|
}
|
|
|
|
|
2021-08-13 14:52:13 -04:00
|
|
|
#[test]
|
|
|
|
fn websocket_server_multi_field_connection_header() {
|
|
|
|
let script = util::testdata_path()
|
|
|
|
.join("websocket_server_multi_field_connection_header_test.ts");
|
|
|
|
let root_ca = util::testdata_path().join("tls/RootCA.pem");
|
|
|
|
let mut child = util::deno_cmd()
|
|
|
|
.arg("run")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg("--allow-net")
|
|
|
|
.arg("--cert")
|
|
|
|
.arg(root_ca)
|
|
|
|
.arg(script)
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let stdout = child.stdout.as_mut().unwrap();
|
|
|
|
let mut buffer = [0; 5];
|
|
|
|
let read = stdout.read(&mut buffer).unwrap();
|
|
|
|
assert_eq!(read, 5);
|
|
|
|
let msg = std::str::from_utf8(&buffer).unwrap();
|
|
|
|
assert_eq!(msg, "READY");
|
|
|
|
|
|
|
|
let req = http::request::Builder::new()
|
|
|
|
.header(http::header::CONNECTION, "keep-alive, Upgrade")
|
|
|
|
.uri("ws://localhost:4319")
|
|
|
|
.body(())
|
|
|
|
.unwrap();
|
2022-05-23 07:21:11 -04:00
|
|
|
let (mut socket, _) =
|
2021-08-13 14:52:13 -04:00
|
|
|
deno_runtime::deno_websocket::tokio_tungstenite::tungstenite::connect(req)
|
2022-05-23 07:21:11 -04:00
|
|
|
.unwrap();
|
|
|
|
let message = socket.read_message().unwrap();
|
|
|
|
assert_eq!(message, deno_runtime::deno_websocket::tokio_tungstenite::tungstenite::Message::Close(None));
|
|
|
|
socket.close(None).unwrap();
|
2021-08-13 14:52:13 -04:00
|
|
|
assert!(child.wait().unwrap().success());
|
|
|
|
}
|
|
|
|
|
2022-04-15 08:24:41 -04:00
|
|
|
// TODO(bartlomieju): this should use `deno run`, not `deno test`; but the
|
|
|
|
// test hangs then. https://github.com/denoland/deno/issues/14283
|
2022-01-06 11:41:16 -05:00
|
|
|
#[test]
|
2022-04-15 08:24:41 -04:00
|
|
|
#[ignore]
|
2022-01-06 11:41:16 -05:00
|
|
|
fn websocket_server_idletimeout() {
|
|
|
|
let script = util::testdata_path().join("websocket_server_idletimeout.ts");
|
|
|
|
let root_ca = util::testdata_path().join("tls/RootCA.pem");
|
|
|
|
let mut child = util::deno_cmd()
|
|
|
|
.arg("test")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg("--allow-net")
|
|
|
|
.arg("--cert")
|
|
|
|
.arg(root_ca)
|
|
|
|
.arg(script)
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let stdout = child.stdout.as_mut().unwrap();
|
|
|
|
let mut buffer = [0; 5];
|
|
|
|
let read = stdout.read(&mut buffer).unwrap();
|
|
|
|
assert_eq!(read, 5);
|
|
|
|
let msg = std::str::from_utf8(&buffer).unwrap();
|
|
|
|
assert_eq!(msg, "READY");
|
|
|
|
|
|
|
|
let req = http::request::Builder::new()
|
2022-02-16 10:51:32 -05:00
|
|
|
.uri("ws://localhost:4509")
|
2022-01-06 11:41:16 -05:00
|
|
|
.body(())
|
|
|
|
.unwrap();
|
|
|
|
let (_ws, _request) =
|
|
|
|
deno_runtime::deno_websocket::tokio_tungstenite::tungstenite::connect(req)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(child.wait().unwrap().success());
|
|
|
|
}
|
|
|
|
|
2021-06-27 13:27:36 -04:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
#[test]
|
|
|
|
fn set_raw_should_not_panic_on_no_tty() {
|
|
|
|
let output = util::deno_cmd()
|
|
|
|
.arg("eval")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg("Deno.setRaw(Deno.stdin.rid, true)")
|
|
|
|
// stdin set to piped so it certainly does not refer to TTY
|
|
|
|
.stdin(std::process::Stdio::piped())
|
|
|
|
// stderr is piped so we can capture output.
|
|
|
|
.stderr(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait_with_output()
|
|
|
|
.unwrap();
|
|
|
|
assert!(!output.status.success());
|
|
|
|
let stderr = std::str::from_utf8(&output.stderr).unwrap().trim();
|
|
|
|
assert!(stderr.contains("BadResource"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
|
|
async fn test_resolve_dns() {
|
|
|
|
use std::net::SocketAddr;
|
|
|
|
use std::str::FromStr;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::time::Duration;
|
|
|
|
use tokio::net::TcpListener;
|
|
|
|
use tokio::net::UdpSocket;
|
|
|
|
use tokio::sync::oneshot;
|
|
|
|
use trust_dns_server::authority::Catalog;
|
|
|
|
use trust_dns_server::authority::ZoneType;
|
|
|
|
use trust_dns_server::proto::rr::Name;
|
|
|
|
use trust_dns_server::store::in_memory::InMemoryAuthority;
|
|
|
|
use trust_dns_server::ServerFuture;
|
|
|
|
|
|
|
|
const DNS_PORT: u16 = 4553;
|
|
|
|
|
|
|
|
// Setup DNS server for testing
|
|
|
|
async fn run_dns_server(tx: oneshot::Sender<()>) {
|
2022-05-14 08:08:35 -04:00
|
|
|
let zone_file =
|
|
|
|
fs::read_to_string(util::testdata_path().join("resolve_dns.zone.in"))
|
|
|
|
.unwrap();
|
|
|
|
let lexer = Lexer::new(&zone_file);
|
|
|
|
let records = Parser::new().parse(
|
|
|
|
lexer,
|
|
|
|
Some(Name::from_str("example.com").unwrap()),
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
if records.is_err() {
|
|
|
|
panic!("failed to parse: {:?}", records.err())
|
|
|
|
}
|
|
|
|
let (origin, records) = records.unwrap();
|
|
|
|
let authority = Box::new(Arc::new(
|
|
|
|
InMemoryAuthority::new(origin, records, ZoneType::Primary, false)
|
2021-06-27 13:27:36 -04:00
|
|
|
.unwrap(),
|
2022-05-14 08:08:35 -04:00
|
|
|
));
|
|
|
|
let mut catalog: Catalog = Catalog::new();
|
|
|
|
catalog.upsert(Name::root().into(), authority);
|
2021-06-27 13:27:36 -04:00
|
|
|
|
|
|
|
let mut server_fut = ServerFuture::new(catalog);
|
|
|
|
let socket_addr = SocketAddr::from(([127, 0, 0, 1], DNS_PORT));
|
|
|
|
let tcp_listener = TcpListener::bind(socket_addr).await.unwrap();
|
|
|
|
let udp_socket = UdpSocket::bind(socket_addr).await.unwrap();
|
|
|
|
server_fut.register_socket(udp_socket);
|
|
|
|
server_fut.register_listener(tcp_listener, Duration::from_secs(2));
|
|
|
|
|
|
|
|
// Notifies that the DNS server is ready
|
|
|
|
tx.send(()).unwrap();
|
|
|
|
|
|
|
|
server_fut.block_until_done().await.unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
let (ready_tx, ready_rx) = oneshot::channel();
|
|
|
|
let dns_server_fut = run_dns_server(ready_tx);
|
|
|
|
let handle = tokio::spawn(dns_server_fut);
|
|
|
|
|
|
|
|
// Waits for the DNS server to be ready
|
|
|
|
ready_rx.await.unwrap();
|
|
|
|
|
|
|
|
// Pass: `--allow-net`
|
|
|
|
{
|
|
|
|
let output = util::deno_cmd()
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.env("NO_COLOR", "1")
|
|
|
|
.arg("run")
|
2022-04-10 19:12:51 -04:00
|
|
|
.arg("--check")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("--allow-net")
|
|
|
|
.arg("resolve_dns.ts")
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.stderr(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait_with_output()
|
|
|
|
.unwrap();
|
|
|
|
let err = String::from_utf8_lossy(&output.stderr);
|
|
|
|
let out = String::from_utf8_lossy(&output.stdout);
|
2022-05-14 08:08:35 -04:00
|
|
|
println!("{}", err);
|
2021-06-27 13:27:36 -04:00
|
|
|
assert!(output.status.success());
|
|
|
|
assert!(err.starts_with("Check file"));
|
|
|
|
|
|
|
|
let expected =
|
2021-08-11 10:20:47 -04:00
|
|
|
std::fs::read_to_string(util::testdata_path().join("resolve_dns.ts.out"))
|
2021-06-27 13:27:36 -04:00
|
|
|
.unwrap();
|
|
|
|
assert_eq!(expected, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass: `--allow-net=127.0.0.1:4553`
|
|
|
|
{
|
|
|
|
let output = util::deno_cmd()
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.env("NO_COLOR", "1")
|
|
|
|
.arg("run")
|
2022-04-10 19:12:51 -04:00
|
|
|
.arg("--check")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("--allow-net=127.0.0.1:4553")
|
|
|
|
.arg("resolve_dns.ts")
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.stderr(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait_with_output()
|
|
|
|
.unwrap();
|
|
|
|
let err = String::from_utf8_lossy(&output.stderr);
|
|
|
|
let out = String::from_utf8_lossy(&output.stdout);
|
|
|
|
assert!(output.status.success());
|
|
|
|
assert!(err.starts_with("Check file"));
|
|
|
|
|
|
|
|
let expected =
|
2021-08-11 10:20:47 -04:00
|
|
|
std::fs::read_to_string(util::testdata_path().join("resolve_dns.ts.out"))
|
2021-06-27 13:27:36 -04:00
|
|
|
.unwrap();
|
|
|
|
assert_eq!(expected, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Permission error: `--allow-net=deno.land`
|
|
|
|
{
|
|
|
|
let output = util::deno_cmd()
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.env("NO_COLOR", "1")
|
|
|
|
.arg("run")
|
2022-04-10 19:12:51 -04:00
|
|
|
.arg("--check")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("--allow-net=deno.land")
|
|
|
|
.arg("resolve_dns.ts")
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.stderr(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait_with_output()
|
|
|
|
.unwrap();
|
|
|
|
let err = String::from_utf8_lossy(&output.stderr);
|
|
|
|
let out = String::from_utf8_lossy(&output.stdout);
|
|
|
|
assert!(!output.status.success());
|
|
|
|
assert!(err.starts_with("Check file"));
|
|
|
|
assert!(err.contains(r#"error: Uncaught (in promise) PermissionDenied: Requires net access to "127.0.0.1:4553""#));
|
|
|
|
assert!(out.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Permission error: no permission specified
|
|
|
|
{
|
|
|
|
let output = util::deno_cmd()
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.env("NO_COLOR", "1")
|
|
|
|
.arg("run")
|
2022-04-10 19:12:51 -04:00
|
|
|
.arg("--check")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("resolve_dns.ts")
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.stderr(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait_with_output()
|
|
|
|
.unwrap();
|
|
|
|
let err = String::from_utf8_lossy(&output.stderr);
|
|
|
|
let out = String::from_utf8_lossy(&output.stdout);
|
|
|
|
assert!(!output.status.success());
|
|
|
|
assert!(err.starts_with("Check file"));
|
|
|
|
assert!(err.contains(r#"error: Uncaught (in promise) PermissionDenied: Requires net access to "127.0.0.1:4553""#));
|
|
|
|
assert!(out.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
handle.abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn typecheck_declarations_ns() {
|
feat(test): Add more overloads for "Deno.test" (#12749)
This commit adds 4 more overloads to "Deno.test()" API.
```
// Deno.test(function testName() { });
export function test(fn: (t: TestContext) => void | Promise<void>): void;
// Deno.test("test name", { only: true }, function() { });
export function test(
name: string,
options: Omit<TestDefinition, "name">,
fn: (t: TestContext) => void | Promise<void>,
): void;
// Deno.test({ name: "test name" }, function() { });
export function test(
options: Omit<TestDefinition, "fn">,
fn: (t: TestContext) => void | Promise<void>,
): void;
// Deno.test({ only: true }, function testName() { });
export function test(
options: Omit<TestDefinition, "fn" | "name">,
fn: (t: TestContext) => void | Promise<void>,
): void;
```
2021-11-23 08:57:51 -05:00
|
|
|
let output = util::deno_cmd()
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("test")
|
|
|
|
.arg("--doc")
|
|
|
|
.arg(util::root_path().join("cli/dts/lib.deno.ns.d.ts"))
|
feat(test): Add more overloads for "Deno.test" (#12749)
This commit adds 4 more overloads to "Deno.test()" API.
```
// Deno.test(function testName() { });
export function test(fn: (t: TestContext) => void | Promise<void>): void;
// Deno.test("test name", { only: true }, function() { });
export function test(
name: string,
options: Omit<TestDefinition, "name">,
fn: (t: TestContext) => void | Promise<void>,
): void;
// Deno.test({ name: "test name" }, function() { });
export function test(
options: Omit<TestDefinition, "fn">,
fn: (t: TestContext) => void | Promise<void>,
): void;
// Deno.test({ only: true }, function testName() { });
export function test(
options: Omit<TestDefinition, "fn" | "name">,
fn: (t: TestContext) => void | Promise<void>,
): void;
```
2021-11-23 08:57:51 -05:00
|
|
|
.output()
|
2021-06-27 13:27:36 -04:00
|
|
|
.unwrap();
|
feat(test): Add more overloads for "Deno.test" (#12749)
This commit adds 4 more overloads to "Deno.test()" API.
```
// Deno.test(function testName() { });
export function test(fn: (t: TestContext) => void | Promise<void>): void;
// Deno.test("test name", { only: true }, function() { });
export function test(
name: string,
options: Omit<TestDefinition, "name">,
fn: (t: TestContext) => void | Promise<void>,
): void;
// Deno.test({ name: "test name" }, function() { });
export function test(
options: Omit<TestDefinition, "fn">,
fn: (t: TestContext) => void | Promise<void>,
): void;
// Deno.test({ only: true }, function testName() { });
export function test(
options: Omit<TestDefinition, "fn" | "name">,
fn: (t: TestContext) => void | Promise<void>,
): void;
```
2021-11-23 08:57:51 -05:00
|
|
|
println!("stdout: {}", String::from_utf8(output.stdout).unwrap());
|
|
|
|
println!("stderr: {}", String::from_utf8(output.stderr).unwrap());
|
|
|
|
assert!(output.status.success());
|
2021-06-27 13:27:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn typecheck_declarations_unstable() {
|
feat(test): Add more overloads for "Deno.test" (#12749)
This commit adds 4 more overloads to "Deno.test()" API.
```
// Deno.test(function testName() { });
export function test(fn: (t: TestContext) => void | Promise<void>): void;
// Deno.test("test name", { only: true }, function() { });
export function test(
name: string,
options: Omit<TestDefinition, "name">,
fn: (t: TestContext) => void | Promise<void>,
): void;
// Deno.test({ name: "test name" }, function() { });
export function test(
options: Omit<TestDefinition, "fn">,
fn: (t: TestContext) => void | Promise<void>,
): void;
// Deno.test({ only: true }, function testName() { });
export function test(
options: Omit<TestDefinition, "fn" | "name">,
fn: (t: TestContext) => void | Promise<void>,
): void;
```
2021-11-23 08:57:51 -05:00
|
|
|
let output = util::deno_cmd()
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("test")
|
|
|
|
.arg("--doc")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg(util::root_path().join("cli/dts/lib.deno.unstable.d.ts"))
|
feat(test): Add more overloads for "Deno.test" (#12749)
This commit adds 4 more overloads to "Deno.test()" API.
```
// Deno.test(function testName() { });
export function test(fn: (t: TestContext) => void | Promise<void>): void;
// Deno.test("test name", { only: true }, function() { });
export function test(
name: string,
options: Omit<TestDefinition, "name">,
fn: (t: TestContext) => void | Promise<void>,
): void;
// Deno.test({ name: "test name" }, function() { });
export function test(
options: Omit<TestDefinition, "fn">,
fn: (t: TestContext) => void | Promise<void>,
): void;
// Deno.test({ only: true }, function testName() { });
export function test(
options: Omit<TestDefinition, "fn" | "name">,
fn: (t: TestContext) => void | Promise<void>,
): void;
```
2021-11-23 08:57:51 -05:00
|
|
|
.output()
|
2021-06-27 13:27:36 -04:00
|
|
|
.unwrap();
|
feat(test): Add more overloads for "Deno.test" (#12749)
This commit adds 4 more overloads to "Deno.test()" API.
```
// Deno.test(function testName() { });
export function test(fn: (t: TestContext) => void | Promise<void>): void;
// Deno.test("test name", { only: true }, function() { });
export function test(
name: string,
options: Omit<TestDefinition, "name">,
fn: (t: TestContext) => void | Promise<void>,
): void;
// Deno.test({ name: "test name" }, function() { });
export function test(
options: Omit<TestDefinition, "fn">,
fn: (t: TestContext) => void | Promise<void>,
): void;
// Deno.test({ only: true }, function testName() { });
export function test(
options: Omit<TestDefinition, "fn" | "name">,
fn: (t: TestContext) => void | Promise<void>,
): void;
```
2021-11-23 08:57:51 -05:00
|
|
|
println!("stdout: {}", String::from_utf8(output.stdout).unwrap());
|
|
|
|
println!("stderr: {}", String::from_utf8(output.stderr).unwrap());
|
|
|
|
assert!(output.status.success());
|
2021-06-27 13:27:36 -04:00
|
|
|
}
|
|
|
|
|
2022-01-14 13:05:16 -05:00
|
|
|
#[test]
|
|
|
|
fn typecheck_core() {
|
2022-04-01 11:15:37 -04:00
|
|
|
let deno_dir = TempDir::new();
|
2022-01-14 13:05:16 -05:00
|
|
|
let test_file = deno_dir.path().join("test_deno_core_types.ts");
|
|
|
|
std::fs::write(
|
|
|
|
&test_file,
|
|
|
|
format!(
|
|
|
|
"import \"{}\";",
|
|
|
|
deno_core::resolve_path(
|
|
|
|
util::root_path()
|
|
|
|
.join("core/lib.deno_core.d.ts")
|
|
|
|
.to_str()
|
|
|
|
.unwrap()
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.unwrap();
|
2022-04-01 11:15:37 -04:00
|
|
|
let output = util::deno_cmd_with_deno_dir(&deno_dir)
|
2022-01-14 13:05:16 -05:00
|
|
|
.arg("run")
|
|
|
|
.arg(test_file.to_str().unwrap())
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
println!("stdout: {}", String::from_utf8(output.stdout).unwrap());
|
|
|
|
println!("stderr: {}", String::from_utf8(output.stderr).unwrap());
|
|
|
|
assert!(output.status.success());
|
|
|
|
}
|
|
|
|
|
2021-06-27 13:27:36 -04:00
|
|
|
#[test]
|
|
|
|
fn js_unit_tests_lint() {
|
|
|
|
let status = util::deno_cmd()
|
|
|
|
.arg("lint")
|
|
|
|
.arg("--unstable")
|
2021-08-11 10:20:47 -04:00
|
|
|
.arg(util::tests_path().join("unit"))
|
2021-06-27 13:27:36 -04:00
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait()
|
|
|
|
.unwrap();
|
|
|
|
assert!(status.success());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn js_unit_tests() {
|
|
|
|
let _g = util::http_server();
|
|
|
|
|
|
|
|
// Note that the unit tests are not safe for concurrency and must be run with a concurrency limit
|
|
|
|
// of one because there are some chdir tests in there.
|
|
|
|
// TODO(caspervonb) split these tests into two groups: parallel and serial.
|
|
|
|
let mut deno = util::deno_cmd()
|
|
|
|
.current_dir(util::root_path())
|
|
|
|
.arg("test")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg("--location=http://js-unit-tests/foo/bar")
|
2022-02-12 22:13:21 -05:00
|
|
|
.arg("--no-prompt")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("-A")
|
2021-08-11 10:20:47 -04:00
|
|
|
.arg(util::tests_path().join("unit"))
|
2021-06-27 13:27:36 -04:00
|
|
|
.spawn()
|
|
|
|
.expect("failed to spawn script");
|
|
|
|
|
|
|
|
let status = deno.wait().expect("failed to wait for the child process");
|
|
|
|
assert_eq!(Some(0), status.code());
|
|
|
|
assert!(status.success());
|
|
|
|
}
|
|
|
|
|
2021-09-08 00:18:11 -04:00
|
|
|
#[test]
|
|
|
|
fn basic_auth_tokens() {
|
|
|
|
let _g = util::http_server();
|
|
|
|
|
|
|
|
let output = util::deno_cmd()
|
|
|
|
.current_dir(util::root_path())
|
|
|
|
.arg("run")
|
|
|
|
.arg("http://127.0.0.1:4554/001_hello.js")
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.stderr(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait_with_output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(!output.status.success());
|
|
|
|
|
|
|
|
let stdout_str = std::str::from_utf8(&output.stdout).unwrap().trim();
|
|
|
|
assert!(stdout_str.is_empty());
|
|
|
|
|
|
|
|
let stderr_str = std::str::from_utf8(&output.stderr).unwrap().trim();
|
|
|
|
eprintln!("{}", stderr_str);
|
|
|
|
|
2021-12-22 08:25:06 -05:00
|
|
|
assert!(stderr_str
|
|
|
|
.contains("Module not found \"http://127.0.0.1:4554/001_hello.js\"."));
|
2021-09-08 00:18:11 -04:00
|
|
|
|
|
|
|
let output = util::deno_cmd()
|
|
|
|
.current_dir(util::root_path())
|
|
|
|
.arg("run")
|
|
|
|
.arg("http://127.0.0.1:4554/001_hello.js")
|
|
|
|
.env("DENO_AUTH_TOKENS", "testuser123:testpassabc@127.0.0.1:4554")
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.stderr(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait_with_output()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let stderr_str = std::str::from_utf8(&output.stderr).unwrap().trim();
|
|
|
|
eprintln!("{}", stderr_str);
|
|
|
|
|
|
|
|
assert!(output.status.success());
|
|
|
|
|
|
|
|
let stdout_str = std::str::from_utf8(&output.stdout).unwrap().trim();
|
|
|
|
assert_eq!(util::strip_ansi_codes(stdout_str), "Hello World");
|
|
|
|
}
|
|
|
|
|
2021-06-27 13:27:36 -04:00
|
|
|
#[tokio::test]
|
|
|
|
async fn listen_tls_alpn() {
|
|
|
|
// TLS streams require the presence of an ambient local task set to gracefully
|
|
|
|
// close dropped connections in the background.
|
|
|
|
LocalSet::new()
|
|
|
|
.run_until(async {
|
|
|
|
let mut child = util::deno_cmd()
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("run")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg("--quiet")
|
|
|
|
.arg("--allow-net")
|
|
|
|
.arg("--allow-read")
|
2021-08-11 10:20:47 -04:00
|
|
|
.arg("./listen_tls_alpn.ts")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("4504")
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let stdout = child.stdout.as_mut().unwrap();
|
2021-12-06 18:48:11 -05:00
|
|
|
let mut msg = [0; 5];
|
|
|
|
let read = stdout.read(&mut msg).unwrap();
|
2021-06-27 13:27:36 -04:00
|
|
|
assert_eq!(read, 5);
|
2021-12-06 18:48:11 -05:00
|
|
|
assert_eq!(&msg, b"READY");
|
2021-06-27 13:27:36 -04:00
|
|
|
|
2021-12-06 18:48:11 -05:00
|
|
|
let mut reader = &mut BufReader::new(Cursor::new(include_bytes!(
|
2021-08-11 10:20:47 -04:00
|
|
|
"../testdata/tls/RootCA.crt"
|
|
|
|
)));
|
2021-12-06 18:48:11 -05:00
|
|
|
let certs = rustls_pemfile::certs(&mut reader).unwrap();
|
|
|
|
let mut root_store = rustls::RootCertStore::empty();
|
|
|
|
root_store.add_parsable_certificates(&certs);
|
|
|
|
let mut cfg = rustls::ClientConfig::builder()
|
|
|
|
.with_safe_defaults()
|
|
|
|
.with_root_certificates(root_store)
|
|
|
|
.with_no_client_auth();
|
|
|
|
cfg.alpn_protocols.push(b"foobar".to_vec());
|
2021-06-27 13:27:36 -04:00
|
|
|
let cfg = Arc::new(cfg);
|
|
|
|
|
2021-12-06 18:48:11 -05:00
|
|
|
let hostname = rustls::ServerName::try_from("localhost").unwrap();
|
2021-06-27 13:27:36 -04:00
|
|
|
|
|
|
|
let tcp_stream = tokio::net::TcpStream::connect("localhost:4504")
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
let mut tls_stream =
|
2021-12-06 18:48:11 -05:00
|
|
|
TlsStream::new_client_side(tcp_stream, cfg, hostname);
|
|
|
|
|
2021-06-27 13:27:36 -04:00
|
|
|
tls_stream.handshake().await.unwrap();
|
|
|
|
|
2021-12-06 18:48:11 -05:00
|
|
|
let (_, rustls_connection) = tls_stream.get_ref();
|
|
|
|
let alpn = rustls_connection.alpn_protocol().unwrap();
|
|
|
|
assert_eq!(alpn, b"foobar");
|
2021-06-27 13:27:36 -04:00
|
|
|
|
2021-12-06 18:48:11 -05:00
|
|
|
let status = child.wait().unwrap();
|
|
|
|
assert!(status.success());
|
2021-06-27 13:27:36 -04:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn listen_tls_alpn_fail() {
|
|
|
|
// TLS streams require the presence of an ambient local task set to gracefully
|
|
|
|
// close dropped connections in the background.
|
|
|
|
LocalSet::new()
|
|
|
|
.run_until(async {
|
|
|
|
let mut child = util::deno_cmd()
|
2021-08-11 10:20:47 -04:00
|
|
|
.current_dir(util::testdata_path())
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("run")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg("--quiet")
|
|
|
|
.arg("--allow-net")
|
|
|
|
.arg("--allow-read")
|
2021-12-06 18:48:11 -05:00
|
|
|
.arg("./listen_tls_alpn_fail.ts")
|
2021-06-27 13:27:36 -04:00
|
|
|
.arg("4505")
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let stdout = child.stdout.as_mut().unwrap();
|
2021-12-06 18:48:11 -05:00
|
|
|
let mut msg = [0; 5];
|
|
|
|
let read = stdout.read(&mut msg).unwrap();
|
2021-06-27 13:27:36 -04:00
|
|
|
assert_eq!(read, 5);
|
2021-12-06 18:48:11 -05:00
|
|
|
assert_eq!(&msg, b"READY");
|
2021-06-27 13:27:36 -04:00
|
|
|
|
2021-12-06 18:48:11 -05:00
|
|
|
let mut reader = &mut BufReader::new(Cursor::new(include_bytes!(
|
2021-08-11 10:20:47 -04:00
|
|
|
"../testdata/tls/RootCA.crt"
|
|
|
|
)));
|
2021-12-06 18:48:11 -05:00
|
|
|
let certs = rustls_pemfile::certs(&mut reader).unwrap();
|
|
|
|
let mut root_store = rustls::RootCertStore::empty();
|
|
|
|
root_store.add_parsable_certificates(&certs);
|
|
|
|
let mut cfg = rustls::ClientConfig::builder()
|
|
|
|
.with_safe_defaults()
|
|
|
|
.with_root_certificates(root_store)
|
|
|
|
.with_no_client_auth();
|
|
|
|
cfg.alpn_protocols.push(b"boofar".to_vec());
|
2021-06-27 13:27:36 -04:00
|
|
|
let cfg = Arc::new(cfg);
|
|
|
|
|
2021-12-06 18:48:11 -05:00
|
|
|
let hostname = rustls::ServerName::try_from("localhost").unwrap();
|
2021-06-27 13:27:36 -04:00
|
|
|
|
|
|
|
let tcp_stream = tokio::net::TcpStream::connect("localhost:4505")
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
let mut tls_stream =
|
2021-12-06 18:48:11 -05:00
|
|
|
TlsStream::new_client_side(tcp_stream, cfg, hostname);
|
|
|
|
|
|
|
|
tls_stream.handshake().await.unwrap_err();
|
2021-06-27 13:27:36 -04:00
|
|
|
|
2021-12-06 18:48:11 -05:00
|
|
|
let (_, rustls_connection) = tls_stream.get_ref();
|
|
|
|
assert!(rustls_connection.alpn_protocol().is_none());
|
2021-06-27 13:27:36 -04:00
|
|
|
|
2021-12-06 18:48:11 -05:00
|
|
|
let status = child.wait().unwrap();
|
|
|
|
assert!(status.success());
|
2021-06-27 13:27:36 -04:00
|
|
|
})
|
|
|
|
.await;
|
|
|
|
}
|
2021-09-26 14:26:16 -04:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn http2_request_url() {
|
|
|
|
// TLS streams require the presence of an ambient local task set to gracefully
|
|
|
|
// close dropped connections in the background.
|
|
|
|
LocalSet::new()
|
|
|
|
.run_until(async {
|
|
|
|
let mut child = util::deno_cmd()
|
|
|
|
.current_dir(util::testdata_path())
|
|
|
|
.arg("run")
|
|
|
|
.arg("--unstable")
|
|
|
|
.arg("--quiet")
|
|
|
|
.arg("--allow-net")
|
|
|
|
.arg("--allow-read")
|
|
|
|
.arg("./http2_request_url.ts")
|
|
|
|
.arg("4506")
|
|
|
|
.stdout(std::process::Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let stdout = child.stdout.as_mut().unwrap();
|
|
|
|
let mut buffer = [0; 5];
|
|
|
|
let read = stdout.read(&mut buffer).unwrap();
|
|
|
|
assert_eq!(read, 5);
|
|
|
|
let msg = std::str::from_utf8(&buffer).unwrap();
|
|
|
|
assert_eq!(msg, "READY");
|
|
|
|
|
|
|
|
let cert = reqwest::Certificate::from_pem(include_bytes!(
|
|
|
|
"../testdata/tls/RootCA.crt"
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let client = reqwest::Client::builder()
|
|
|
|
.add_root_certificate(cert)
|
|
|
|
.http2_prior_knowledge()
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let res = client.get("http://127.0.0.1:4506").send().await.unwrap();
|
|
|
|
assert_eq!(200, res.status());
|
|
|
|
|
|
|
|
let body = res.text().await.unwrap();
|
|
|
|
assert_eq!(body, "http://127.0.0.1:4506/");
|
|
|
|
|
|
|
|
child.kill().unwrap();
|
|
|
|
child.wait().unwrap();
|
|
|
|
})
|
|
|
|
.await;
|
|
|
|
}
|