fix(mcp): fix test_allows_safe_env_vars test failure
All checks were successful
Test / rust-fmt-check (pull_request) Successful in 1m27s
Test / frontend-tests (pull_request) Successful in 1m31s
Test / frontend-typecheck (pull_request) Successful in 1m34s
Test / rust-clippy (pull_request) Successful in 3m8s
Test / rust-tests (pull_request) Successful in 4m33s
PR Review Automation / review (pull_request) Successful in 4m47s
All checks were successful
Test / rust-fmt-check (pull_request) Successful in 1m27s
Test / frontend-tests (pull_request) Successful in 1m31s
Test / frontend-typecheck (pull_request) Successful in 1m34s
Test / rust-clippy (pull_request) Successful in 3m8s
Test / rust-tests (pull_request) Successful in 4m33s
PR Review Automation / review (pull_request) Successful in 4m47s
The test was trying to spawn a process which requires a Tokio runtime. Changed the test to only verify validation logic by checking that safe environment variables don't trigger 'Dangerous environment variable' errors. Uses /usr/bin/nonexistent as command so spawn will fail (command not found) but validation will pass for safe env vars like DEBUG, API_KEY, PATH, etc. All 243 tests now passing.
This commit is contained in:
parent
0469f121b1
commit
7c2452e3f7
@ -102,22 +102,33 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_allows_safe_env_vars() {
|
fn test_allows_safe_env_vars() {
|
||||||
|
// Test that safe env vars pass validation (validation happens before spawn)
|
||||||
|
let safe_vars = vec![
|
||||||
|
("DEBUG", "1"),
|
||||||
|
("API_KEY", "secret123"),
|
||||||
|
("PATH", "/usr/bin"),
|
||||||
|
("HOME", "/home/user"),
|
||||||
|
("GITHUB_PERSONAL_ACCESS_TOKEN", "ghp_token"),
|
||||||
|
("LOG_LEVEL", "info"),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (key, value) in safe_vars {
|
||||||
let mut env = HashMap::new();
|
let mut env = HashMap::new();
|
||||||
env.insert("DEBUG".to_string(), "1".to_string());
|
env.insert(key.to_string(), value.to_string());
|
||||||
env.insert("API_KEY".to_string(), "secret123".to_string());
|
|
||||||
env.insert("PATH".to_string(), "/usr/bin".to_string());
|
|
||||||
|
|
||||||
// Note: This will fail to spawn since /usr/bin/test may not exist,
|
// This will fail to spawn since /usr/bin/nonexistent doesn't exist,
|
||||||
// but we're testing that it doesn't reject the env vars
|
// but if validation passed, error won't mention "Dangerous environment variable"
|
||||||
let result = build_stdio_transport("/usr/bin/test", &[], env);
|
let result = build_stdio_transport("/usr/bin/nonexistent", &[], env);
|
||||||
|
|
||||||
// Should fail with spawn error, not env var validation error
|
// Validation passes (doesn't reject env var), spawn fails (command doesn't exist)
|
||||||
if let Err(err) = result {
|
if let Err(err) = result {
|
||||||
assert!(
|
assert!(
|
||||||
!err.contains("Dangerous environment variable"),
|
!err.contains("Dangerous environment variable"),
|
||||||
"Should not reject safe env vars, got: {}",
|
"Should not reject safe env var '{}', got: {}",
|
||||||
|
key,
|
||||||
err
|
err
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user