Skip to content

Commit 7d683bb

Browse files
ammarioclaude
andcommitted
Fix CI test failures for CA certificate discovery
Multiple issues fixed for CI environment: 1. CA certificate discovery now checks multiple locations to handle user context changes (runner vs root in CI). This fixes TLS tests failing with "OpenSSL error:06880006:asn1 encoding routines" 2. Simplified concurrent namespace test to avoid shell quoting issues when environment variables are exported through multiple shell layers The main issue was that in GitHub Actions, the CA cert is created under /home/runner/.config but httpjail runs as root and looks in /root/.config. Now we check both locations plus SUDO_USER's home. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ac7d065 commit 7d683bb

2 files changed

Lines changed: 50 additions & 6 deletions

File tree

src/tls.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rcgen::{Certificate, CertificateParams, DistinguishedName, DnType, KeyPair,
55
use rustls::pki_types::{CertificateDer, PrivateKeyDer};
66
use std::fs;
77
use std::num::NonZeroUsize;
8+
use std::path::PathBuf;
89
use std::sync::{Arc, RwLock};
910
use tracing::{debug, info};
1011

@@ -236,10 +237,45 @@ impl CertificateManager {
236237

237238
/// Generate environment variables for common tools to use the CA certificate
238239
pub fn get_ca_env_vars() -> Result<Vec<(String, String)>> {
239-
let ca_path = Self::get_ca_cert_path()?;
240+
// Try multiple possible locations for the CA certificate
241+
// This handles cases where the effective user changes (e.g., sudo in CI)
242+
let mut ca_path = Self::get_ca_cert_path()?;
240243

241244
if !ca_path.exists() {
242-
anyhow::bail!("CA certificate not found at {:?}", ca_path);
245+
// If not found in current user's config, check common locations
246+
let possible_paths = [
247+
// Check SUDO_USER's config directory
248+
std::env::var("SUDO_USER").ok().and_then(|sudo_user| {
249+
dirs::home_dir().map(|home| {
250+
home.parent()
251+
.unwrap_or(&home)
252+
.join(sudo_user)
253+
.join(".config/httpjail/ca-cert.pem")
254+
})
255+
}),
256+
// Check /home/runner for CI
257+
Some(PathBuf::from("/home/runner/.config/httpjail/ca-cert.pem")),
258+
// Check root's config
259+
Some(PathBuf::from("/root/.config/httpjail/ca-cert.pem")),
260+
];
261+
262+
for path_option in &possible_paths {
263+
if let Some(path) = path_option {
264+
if path.exists() {
265+
ca_path = Utf8PathBuf::try_from(path.clone())
266+
.context("CA cert path is not valid UTF-8")?;
267+
debug!("Found CA certificate at alternate location: {}", ca_path);
268+
break;
269+
}
270+
}
271+
}
272+
273+
if !ca_path.exists() {
274+
anyhow::bail!(
275+
"CA certificate not found. Searched: {:?} and common locations",
276+
ca_path
277+
);
278+
}
243279
}
244280

245281
let ca_path_str = ca_path.to_string();

tests/linux_integration.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ mod tests {
105105
.arg("--")
106106
.arg("sh")
107107
.arg("-c")
108-
.arg("echo 'Instance 1'; sleep 2; echo 'Instance 1 done'")
108+
.arg("echo Instance1 && sleep 2 && echo Instance1Done")
109109
.spawn()
110110
.expect("Failed to start first httpjail");
111111

@@ -118,7 +118,7 @@ mod tests {
118118
.arg("allow: .*")
119119
.arg("--")
120120
.arg("echo")
121-
.arg("Instance 2")
121+
.arg("Instance2")
122122
.output()
123123
.expect("Failed to execute second httpjail");
124124

@@ -141,7 +141,15 @@ mod tests {
141141
// Verify both ran
142142
let stdout1 = String::from_utf8_lossy(&output1.stdout);
143143
let stdout2 = String::from_utf8_lossy(&output2.stdout);
144-
assert!(stdout1.contains("Instance 1"), "First instance didn't run");
145-
assert!(stdout2.contains("Instance 2"), "Second instance didn't run");
144+
assert!(
145+
stdout1.contains("Instance1"),
146+
"First instance didn't run: {}",
147+
stdout1
148+
);
149+
assert!(
150+
stdout2.contains("Instance2"),
151+
"Second instance didn't run: {}",
152+
stdout2
153+
);
146154
}
147155
}

0 commit comments

Comments
 (0)