mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
b2a4e3be27
## Why We're moving exec-server to use PathUri for its internal path representations. ## What Move `ExecutorFileSystem` APIs to use `PathUri` instead of `AbsolutePathBuf`. Future changes will convert higher-level parts of exec-server.
44 lines
1.3 KiB
Rust
44 lines
1.3 KiB
Rust
use codex_protocol::models::PermissionProfile;
|
|
use codex_protocol::permissions::FileSystemSandboxPolicy;
|
|
use codex_protocol::permissions::NetworkSandboxPolicy;
|
|
use codex_utils_path_uri::PathUri;
|
|
use pretty_assertions::assert_eq;
|
|
use tokio::io;
|
|
|
|
use super::*;
|
|
|
|
#[tokio::test]
|
|
async fn sandboxed_file_system_rejects_non_native_uri_as_invalid_input() {
|
|
let runtime_paths = ExecServerRuntimePaths::new(
|
|
std::env::current_exe().expect("current exe"),
|
|
/*codex_linux_sandbox_exe*/ None,
|
|
)
|
|
.expect("runtime paths");
|
|
let file_system = SandboxedFileSystem::new(runtime_paths);
|
|
let sandbox = FileSystemSandboxContext::from_permission_profile(
|
|
PermissionProfile::from_runtime_permissions(
|
|
&FileSystemSandboxPolicy::restricted(Vec::new()),
|
|
NetworkSandboxPolicy::Restricted,
|
|
),
|
|
);
|
|
|
|
let error = file_system
|
|
.read_file(&non_native_uri(), Some(&sandbox))
|
|
.await
|
|
.expect_err("non-native URI should be rejected");
|
|
|
|
assert_eq!(error.kind(), io::ErrorKind::InvalidInput);
|
|
}
|
|
|
|
fn non_native_uri() -> PathUri {
|
|
#[cfg(unix)]
|
|
let uri = "file://server/share/file.txt";
|
|
#[cfg(windows)]
|
|
let uri = "file:///usr/local/file.txt";
|
|
|
|
match PathUri::parse(uri) {
|
|
Ok(uri) => uri,
|
|
Err(err) => panic!("valid non-native URI should parse: {err}"),
|
|
}
|
|
}
|