From 3be2064803b127c1aaa4af4aa3f060bcc8e88049 Mon Sep 17 00:00:00 2001 From: Oscar Linde Date: Mon, 13 Jul 2020 01:18:27 +0200 Subject: feat(cli): add DENO_CERT environment variable (#6370) --- cli/flags.rs | 1 + cli/global_state.rs | 6 +++++- cli/tests/integration_tests.rs | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/cli/flags.rs b/cli/flags.rs index 7d9ba8fdb..efd0a5c63 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -186,6 +186,7 @@ static ENV_VARIABLES_HELP: &str = "ENVIRONMENT VARIABLES: DENO_DIR Set the cache directory DENO_INSTALL_ROOT Set deno install's output directory (defaults to $HOME/.deno/bin) + DENO_CERT Load certificate authority from PEM encoded file NO_COLOR Set to disable color HTTP_PROXY Proxy address for HTTP requests (module downloads, fetch) diff --git a/cli/global_state.rs b/cli/global_state.rs index e9988f4b5..3290be25f 100644 --- a/cli/global_state.rs +++ b/cli/global_state.rs @@ -58,6 +58,10 @@ impl GlobalState { let dir = deno_dir::DenoDir::new(custom_root)?; let deps_cache_location = dir.root.join("deps"); let http_cache = http_cache::HttpCache::new(&deps_cache_location); + let ca_file = flags + .ca_file + .clone() + .or_else(|| env::var("DENO_CERT").map(String::into).ok()); let file_fetcher = SourceFileFetcher::new( http_cache, @@ -65,7 +69,7 @@ impl GlobalState { flags.cache_blocklist.clone(), flags.no_remote, flags.cached_only, - flags.ca_file.clone(), + ca_file, )?; let ts_compiler = TsCompiler::new( diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index f064c4db1..935454636 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -2182,6 +2182,27 @@ itest!(deno_lint_glob { exit_code: 1, }); +#[test] +fn cafile_env_fetch() { + use url::Url; + let g = util::http_server(); + let deno_dir = TempDir::new().expect("tempdir fail"); + let module_url = + Url::parse("https://localhost:5545/cli/tests/cafile_url_imports.ts") + .unwrap(); + let cafile = util::root_path().join("cli/tests/tls/RootCA.pem"); + let output = Command::new(util::deno_exe_path()) + .env("DENO_DIR", deno_dir.path()) + .env("DENO_CERT", cafile) + .current_dir(util::root_path()) + .arg("cache") + .arg(module_url.to_string()) + .output() + .expect("Failed to spawn script"); + assert!(output.status.success()); + drop(g); +} + #[test] fn cafile_fetch() { use url::Url; -- cgit v1.2.3