-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deal with SSL_CERT_{FILE,DIR} set by Cargo
Cargo sets these env. vars. internally, at least here, on Linux: $ cargo init --bin env-conflict $ cd env-conflict $ cat >src/main.rs <<EOF fn main() { let _ = dbg!(std::env::var("SSL_CERT_FILE")); let _ = dbg!(std::env::var("SSL_CERT_DIR")); } EOF $ cargo -q run [src/main.rs:2:13] std::env::var("SSL_CERT_FILE") = Ok( "/usr/lib/ssl/cert.pem", ) [src/main.rs:3:13] std::env::var("SSL_CERT_DIR") = Ok( "/usr/lib/ssl/certs", )
- Loading branch information
Showing
3 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use std::env; | ||
|
||
/// Cargo, at least sometimes, sets SSL_CERT_FILE and SSL_CERT_DIR internally, | ||
/// it uses OpenSSL. So, always unset both at the beginning of a test even if | ||
/// the test doesn't use either. | ||
/// | ||
/// # Safety | ||
/// | ||
/// This is only safe if used together with `#[serial]` because calling | ||
/// `[env::remove_var()]` is unsafe if another thread is running. | ||
/// | ||
/// Note that `env::remove_var()` is scheduled to become unsafe in Rust | ||
/// Edition 2024. | ||
pub(crate) unsafe fn clear_env() { | ||
env::remove_var("SSL_CERT_FILE"); | ||
env::remove_var("SSL_CERT_DIR"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters