Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test: cover protected literals in interpreter tools

Steven Enamakel54888cb2e099
diff --git a/crates/openhuman-core/src/tools/impl/system/node_exec_tests.rs b/crates/openhuman-core/src/tools/impl/system/node_exec_tests.rs
index a10667de87..9b1f7f45c8 100644
--- a/crates/openhuman-core/src/tools/impl/system/node_exec_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/system/node_exec_tests.rs
@@ -1,5 +1,27 @@
use super::*;
use serde_json::json;
+
+#[tokio::test]
+async fn node_exec_blocks_protected_literal_before_runtime_resolution() {
+ let tool = NodeExecTool::new(
+ std::sync::Arc::new(crate::security::SecurityPolicy {
+ enabled: false,
+ ..crate::security::SecurityPolicy::default()
+ }),
+ std::sync::Arc::new(crate::agent::host_runtime::NativeRuntime::new()),
+ std::sync::Arc::new(NodeBootstrap::new(std::sync::Arc::new(
+ crate::config::Config::default(),
+ ))),
+ crate::config::RuntimePoolConfig::default(),
+ std::path::PathBuf::from("."),
+ );
+ let result = tool
+ .execute(json!({"inline_code": "require('fs').readFileSync('~/.ssh/id_rsa')"}))
+ .await
+ .unwrap();
+ assert!(result.is_error);
+ assert!(result.text().contains("protected path"));
+}
fn absolute_sample() -> &'static str {
if cfg!(windows) {
"C:\\Windows\\System32\\drivers\\etc\\hosts"
diff --git a/crates/openhuman-core/src/tools/impl/system/npm_exec_tests.rs b/crates/openhuman-core/src/tools/impl/system/npm_exec_tests.rs
index 64c24dff35..4472c00db8 100644
--- a/crates/openhuman-core/src/tools/impl/system/npm_exec_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/system/npm_exec_tests.rs
@@ -1,5 +1,25 @@
use super::*;
use serde_json::json;
+
+#[tokio::test]
+async fn npm_exec_blocks_protected_literal_before_runtime_resolution() {
+ let tool = NpmExecTool::new(
+ std::sync::Arc::new(crate::security::SecurityPolicy {
+ enabled: false,
+ ..crate::security::SecurityPolicy::default()
+ }),
+ std::sync::Arc::new(crate::agent::host_runtime::NativeRuntime::new()),
+ std::sync::Arc::new(NodeBootstrap::new(std::sync::Arc::new(
+ crate::config::Config::default(),
+ ))),
+ );
+ let result = tool
+ .execute(json!({"subcommand": "run", "args": ["~/.npmrc"]}))
+ .await
+ .unwrap();
+ assert!(result.is_error);
+ assert!(result.text().contains("protected path"));
+}
fn absolute_sample() -> &'static str {
if cfg!(windows) {
"C:\\Windows\\System32"
diff --git a/crates/openhuman-core/src/tools/impl/system/python_exec_tests.rs b/crates/openhuman-core/src/tools/impl/system/python_exec_tests.rs
index 94bdbe59a2..a781157296 100644
--- a/crates/openhuman-core/src/tools/impl/system/python_exec_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/system/python_exec_tests.rs
@@ -1,5 +1,27 @@
use super::*;
+#[tokio::test]
+async fn python_exec_blocks_protected_literal_before_runtime_resolution() {
+ let tool = PythonExecTool::new(
+ std::sync::Arc::new(crate::security::SecurityPolicy {
+ enabled: false,
+ ..crate::security::SecurityPolicy::default()
+ }),
+ std::sync::Arc::new(crate::agent::host_runtime::NativeRuntime::new()),
+ std::sync::Arc::new(PythonBootstrap::new(std::sync::Arc::new(
+ crate::config::Config::default(),
+ ))),
+ crate::config::RuntimePoolConfig::default(),
+ std::path::PathBuf::from("."),
+ );
+ let result = tool
+ .execute(json!({"inline_code": "open('~/.aws/credentials').read()"}))
+ .await
+ .unwrap();
+ assert!(result.is_error);
+ assert!(result.text().contains("protected path"));
+}
+
#[test]
fn python_timeout_policy_unbounded_by_default() {
assert_eq!(python_timeout_policy(&json!({})), ToolTimeout::Unbounded);