From 69ec45eac76c63ea973c68479ea4f0bbf58b29e9 Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Tue, 17 Jan 2023 16:18:24 -0800 Subject: refactor(cli): Integrate standalone mode cert handling into `Flags` (#17419) The way the standalone mode handles the `--cert` flag is different to all other modes. This is because `--cert` takes a path to the certificate file, which is directly added to the root cert store; except for compile mode, where its byte contents are stored in the standalone metadata, and they are added to the root cert store after the `ProcState` is created. This change instead changes `Flags::ca_file` (an `Option`) into `Flags::ca_data`, which can represent a `String` file path or a `Vec` with the certificate contents. That way, standalone mode can create a `ProcState` whose root cert store alreay contains the certificate. This change also adds a tests for certificates in standalone mode, since there weren't any before. This refactor will help with implementing web workers in standalone mode in the future. --- cli/tests/integration/cert_tests.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'cli/tests/integration/cert_tests.rs') diff --git a/cli/tests/integration/cert_tests.rs b/cli/tests/integration/cert_tests.rs index 0a403c39a..9e0e810b0 100644 --- a/cli/tests/integration/cert_tests.rs +++ b/cli/tests/integration/cert_tests.rs @@ -112,6 +112,40 @@ fn cafile_fetch() { assert_eq!(out, ""); } +#[test] +fn cafile_compile() { + let _g = util::http_server(); + let dir = TempDir::new(); + let exe = if cfg!(windows) { + dir.path().join("cert.exe") + } else { + dir.path().join("cert") + }; + let output = util::deno_cmd() + .current_dir(util::testdata_path()) + .arg("compile") + .arg("--cert") + .arg("./tls/RootCA.pem") + .arg("--allow-net") + .arg("--output") + .arg(&exe) + .arg("./cert/cafile_ts_fetch.ts") + .stdout(std::process::Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(output.status.success()); + let output = Command::new(exe) + .stdout(std::process::Stdio::piped()) + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(output.status.success()); + assert_eq!(output.stdout, b"[WILDCARD]\nHello\n") +} + #[flaky_test::flaky_test] fn cafile_install_remote_module() { let _g = util::http_server(); -- cgit v1.2.3