summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/cafile_info.ts24
-rw-r--r--cli/tests/cafile_info.ts.out14
-rw-r--r--cli/tests/cafile_ts_fetch.ts3
-rw-r--r--cli/tests/cafile_ts_fetch.ts.out1
-rw-r--r--cli/tests/cafile_url_imports.ts3
-rw-r--r--cli/tests/cafile_url_imports.ts.out2
-rw-r--r--cli/tests/integration_tests.rs168
-rw-r--r--cli/tests/tls/README.md2
8 files changed, 216 insertions, 1 deletions
diff --git a/cli/tests/cafile_info.ts b/cli/tests/cafile_info.ts
new file mode 100644
index 000000000..e11d106e6
--- /dev/null
+++ b/cli/tests/cafile_info.ts
@@ -0,0 +1,24 @@
+// When run against the test HTTP server, it will serve different media types
+// based on the URL containing `.t#.` strings, which exercises the different
+// mapping of media types end to end.
+
+import { loaded as loadedTs1 } from "https://localhost:5545/cli/tests/subdir/mt_text_typescript.t1.ts";
+import { loaded as loadedTs2 } from "https://localhost:5545/cli/tests/subdir/mt_video_vdn.t2.ts";
+import { loaded as loadedTs3 } from "https://localhost:5545/cli/tests/subdir/mt_video_mp2t.t3.ts";
+import { loaded as loadedTs4 } from "https://localhost:5545/cli/tests/subdir/mt_application_x_typescript.t4.ts";
+import { loaded as loadedJs1 } from "https://localhost:5545/cli/tests/subdir/mt_text_javascript.j1.js";
+import { loaded as loadedJs2 } from "https://localhost:5545/cli/tests/subdir/mt_application_ecmascript.j2.js";
+import { loaded as loadedJs3 } from "https://localhost:5545/cli/tests/subdir/mt_text_ecmascript.j3.js";
+import { loaded as loadedJs4 } from "https://localhost:5545/cli/tests/subdir/mt_application_x_javascript.j4.js";
+
+console.log(
+ "success",
+ loadedTs1,
+ loadedTs2,
+ loadedTs3,
+ loadedTs4,
+ loadedJs1,
+ loadedJs2,
+ loadedJs3,
+ loadedJs4
+);
diff --git a/cli/tests/cafile_info.ts.out b/cli/tests/cafile_info.ts.out
new file mode 100644
index 000000000..443b92eea
--- /dev/null
+++ b/cli/tests/cafile_info.ts.out
@@ -0,0 +1,14 @@
+local: [WILDCARD]cafile_info.ts
+type: TypeScript
+compiled: [WILDCARD].js
+map: [WILDCARD].js.map
+deps:
+https://localhost:5545/cli/tests/cafile_info.ts
+ ├── https://localhost:5545/cli/tests/subdir/mt_text_typescript.t1.ts
+ ├── https://localhost:5545/cli/tests/subdir/mt_video_vdn.t2.ts
+ ├── https://localhost:5545/cli/tests/subdir/mt_video_mp2t.t3.ts
+ ├── https://localhost:5545/cli/tests/subdir/mt_application_x_typescript.t4.ts
+ ├── https://localhost:5545/cli/tests/subdir/mt_text_javascript.j1.js
+ ├── https://localhost:5545/cli/tests/subdir/mt_application_ecmascript.j2.js
+ ├── https://localhost:5545/cli/tests/subdir/mt_text_ecmascript.j3.js
+ └── https://localhost:5545/cli/tests/subdir/mt_application_x_javascript.j4.js
diff --git a/cli/tests/cafile_ts_fetch.ts b/cli/tests/cafile_ts_fetch.ts
new file mode 100644
index 000000000..be158bf70
--- /dev/null
+++ b/cli/tests/cafile_ts_fetch.ts
@@ -0,0 +1,3 @@
+fetch("https://localhost:5545/cli/tests/cafile_ts_fetch.ts.out")
+ .then(r => r.text())
+ .then(t => console.log(t.trimEnd()));
diff --git a/cli/tests/cafile_ts_fetch.ts.out b/cli/tests/cafile_ts_fetch.ts.out
new file mode 100644
index 000000000..e965047ad
--- /dev/null
+++ b/cli/tests/cafile_ts_fetch.ts.out
@@ -0,0 +1 @@
+Hello
diff --git a/cli/tests/cafile_url_imports.ts b/cli/tests/cafile_url_imports.ts
new file mode 100644
index 000000000..f781f32f5
--- /dev/null
+++ b/cli/tests/cafile_url_imports.ts
@@ -0,0 +1,3 @@
+import { printHello } from "https://localhost:5545/cli/tests/subdir/mod2.ts";
+printHello();
+console.log("success");
diff --git a/cli/tests/cafile_url_imports.ts.out b/cli/tests/cafile_url_imports.ts.out
new file mode 100644
index 000000000..989ce33e9
--- /dev/null
+++ b/cli/tests/cafile_url_imports.ts.out
@@ -0,0 +1,2 @@
+Hello
+success
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index fb35163f0..38c870200 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -929,6 +929,174 @@ itest!(import_wasm_via_network {
http_server: true,
});
+itest!(cafile_url_imports {
+ args: "run --reload --cert tls/RootCA.pem cafile_url_imports.ts",
+ output: "cafile_url_imports.ts.out",
+ http_server: true,
+});
+
+itest!(cafile_ts_fetch {
+ args: "run --reload --allow-net --cert tls/RootCA.pem cafile_ts_fetch.ts",
+ output: "cafile_ts_fetch.ts.out",
+ http_server: true,
+});
+
+itest!(cafile_eval {
+ args: "eval --cert tls/RootCA.pem fetch('https://localhost:5545/cli/tests/cafile_ts_fetch.ts.out').then(r=>r.text()).then(t=>console.log(t.trimEnd()))",
+ output: "cafile_ts_fetch.ts.out",
+ http_server: true,
+});
+
+itest!(cafile_info {
+ args:
+ "info --cert tls/RootCA.pem https://localhost:5545/cli/tests/cafile_info.ts",
+ output: "cafile_info.ts.out",
+ http_server: true,
+});
+
+#[test]
+fn cafile_fetch() {
+ pub use deno::test_util::*;
+ use std::process::Command;
+ use tempfile::TempDir;
+
+ let g = util::http_server();
+
+ let deno_dir = TempDir::new().expect("tempdir fail");
+ let t = util::root_path().join("cli/tests/cafile_url_imports.ts");
+ let cafile = util::root_path().join("cli/tests/tls/RootCA.pem");
+ let output = Command::new(deno_exe_path())
+ .env("DENO_DIR", deno_dir.path())
+ .current_dir(util::root_path())
+ .arg("fetch")
+ .arg("--cert")
+ .arg(cafile)
+ .arg(t)
+ .output()
+ .expect("Failed to spawn script");
+
+ let code = output.status.code();
+ let out = std::str::from_utf8(&output.stdout).unwrap();
+
+ assert_eq!(Some(0), code);
+ assert_eq!(out, "");
+
+ let expected_path = deno_dir
+ .path()
+ .join("deps/https/localhost_PORT5545/cli/tests/subdir/mod2.ts");
+ assert_eq!(expected_path.exists(), true);
+
+ drop(g);
+}
+
+#[test]
+fn cafile_install_remote_module() {
+ pub use deno::test_util::*;
+ use std::env;
+ use std::path::PathBuf;
+ use std::process::Command;
+ use tempfile::TempDir;
+
+ let g = util::http_server();
+ let temp_dir = TempDir::new().expect("tempdir fail");
+ let deno_dir = TempDir::new().expect("tempdir fail");
+ let cafile = util::root_path().join("cli/tests/tls/RootCA.pem");
+
+ let install_output = Command::new(deno_exe_path())
+ .env("DENO_DIR", deno_dir.path())
+ .current_dir(util::root_path())
+ .arg("install")
+ .arg("--cert")
+ .arg(cafile)
+ .arg("--dir")
+ .arg(temp_dir.path())
+ .arg("echo_test")
+ .arg("https://localhost:5545/cli/tests/echo.ts")
+ .output()
+ .expect("Failed to spawn script");
+
+ let code = install_output.status.code();
+ assert_eq!(Some(0), code);
+
+ let mut file_path = temp_dir.path().join("echo_test");
+ if cfg!(windows) {
+ file_path = file_path.with_extension(".cmd");
+ }
+ assert!(file_path.exists());
+
+ let path_var_name = if cfg!(windows) { "Path" } else { "PATH" };
+ let paths_var = env::var_os(path_var_name).expect("PATH not set");
+ let mut paths: Vec<PathBuf> = env::split_paths(&paths_var).collect();
+ paths.push(temp_dir.path().to_owned());
+ paths.push(util::target_dir());
+ let path_var_value = env::join_paths(paths).expect("Can't create PATH");
+
+ let output = Command::new(file_path)
+ .current_dir(temp_dir.path())
+ .arg("foo")
+ .env(path_var_name, path_var_value)
+ .output()
+ .expect("failed to spawn script");
+ assert!(std::str::from_utf8(&output.stdout)
+ .unwrap()
+ .trim()
+ .ends_with("foo"));
+
+ drop(deno_dir);
+ drop(temp_dir);
+ drop(g)
+}
+
+#[test]
+fn cafile_bundle_remote_exports() {
+ use tempfile::TempDir;
+
+ let g = util::http_server();
+
+ // First we have to generate a bundle of some remote module that has exports.
+ let mod1 = "https://localhost:5545/cli/tests/subdir/mod1.ts";
+ let cafile = util::root_path().join("cli/tests/tls/RootCA.pem");
+ let t = TempDir::new().expect("tempdir fail");
+ let bundle = t.path().join("mod1.bundle.js");
+ let mut deno = util::deno_cmd()
+ .current_dir(util::root_path())
+ .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()
+ .current_dir(util::root_path())
+ .arg("run")
+ .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"");
+
+ drop(g)
+}
+
mod util {
use deno::colors::strip_ansi_codes;
pub use deno::test_util::*;
diff --git a/cli/tests/tls/README.md b/cli/tests/tls/README.md
index 14399ae82..34de47dea 100644
--- a/cli/tests/tls/README.md
+++ b/cli/tests/tls/README.md
@@ -5,7 +5,7 @@ https://gist.github.com/cecilemuller/9492b848eb8fe46d462abeb26656c4f8
## Certificate authority (CA)
-Generate RootCA.pem, RootCA.key & RootCA.crt:
+Generate RootCA.pem, RootCA.key, RootCA.crt:
```shell
openssl req -x509 -nodes -new -sha256 -days 36135 -newkey rsa:2048 -keyout RootCA.key -out RootCA.pem -subj "/C=US/CN=Example-Root-CA"