mirror of
https://github.com/openai/codex.git
synced 2026-10-25 15:56:38 +00:00
## What changed - Accept root `http://` and `https://` URLs in `--code-mode-host` and use the shared gRPC session provider for those endpoints. - Keep `ws://` and `wss://` URLs on the existing WebSocket transport. - Reject paths, queries, fragments, and credentials where unsupported, without exposing gRPC URL credentials in command-line validation errors. ## Testing - Cover argument parsing and transport selection for both remote protocols. - Exercise a gRPC host shared across app-server threads and verify credential rejection does not disclose usernames or passwords. GitOrigin-RevId: b6516a85cf76db5c4cea620f89ef866d8af30cf0
97 lines
2.7 KiB
Rust
97 lines
2.7 KiB
Rust
use super::AppServerCodeModeHostArgs;
|
|
use super::CodeModeHostTransport;
|
|
use super::parse_host_url;
|
|
use pretty_assertions::assert_eq;
|
|
use url::Url;
|
|
|
|
#[test]
|
|
fn websocket_host_accepts_local_and_secure_endpoints() {
|
|
for endpoint in [
|
|
"ws://127.0.0.1:8765",
|
|
"wss://example.test/code-mode",
|
|
"ws://alice:secret@example.test/code-mode",
|
|
"wss://alice:secret@example.test/code-mode",
|
|
] {
|
|
assert_eq!(
|
|
parse_host_url(endpoint),
|
|
Ok(Url::parse(endpoint).expect("test endpoint should parse"))
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn grpc_host_accepts_local_and_secure_endpoints() {
|
|
for endpoint in ["http://127.0.0.1:8765", "https://example.test"] {
|
|
assert_eq!(
|
|
parse_host_url(endpoint),
|
|
Ok(Url::parse(endpoint).expect("test endpoint should parse"))
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn grpc_host_rejects_credentials_without_disclosing_them() {
|
|
for endpoint in [
|
|
"http://alice:secret@example.test",
|
|
"https://alice:secret@example.test",
|
|
"https://alice@example.test",
|
|
"https://:secret@example.test",
|
|
] {
|
|
let error = parse_host_url(endpoint).expect_err("gRPC credentials should be rejected");
|
|
|
|
assert!(error.contains("must not contain credentials"));
|
|
assert!(!error.contains("alice"));
|
|
assert!(!error.contains("secret"));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn code_mode_host_rejects_invalid_endpoints() {
|
|
for endpoint in [
|
|
"ftp://127.0.0.1:8765",
|
|
"ws://",
|
|
"not a host endpoint",
|
|
"wss://example.test/code-mode#fragment",
|
|
"https://example.test/code-mode#fragment",
|
|
"https://example.test/code-mode",
|
|
"http://example.test/?token=secret",
|
|
] {
|
|
assert!(
|
|
parse_host_url(endpoint).is_err(),
|
|
"invalid code-mode host endpoint should be rejected: {endpoint}"
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn omitted_websocket_host_selects_local_transport() {
|
|
assert_eq!(
|
|
CodeModeHostTransport::from(AppServerCodeModeHostArgs::default()),
|
|
CodeModeHostTransport::Local
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn explicit_websocket_host_selects_remote_transport() {
|
|
let url = Url::parse("wss://example.test/code-mode").expect("test endpoint should parse");
|
|
|
|
assert_eq!(
|
|
CodeModeHostTransport::from(AppServerCodeModeHostArgs {
|
|
code_mode_host: Some(url.clone()),
|
|
}),
|
|
CodeModeHostTransport::WebSocket(url)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn explicit_grpc_host_selects_remote_transport() {
|
|
let url = Url::parse("https://example.test").expect("test endpoint should parse");
|
|
|
|
assert_eq!(
|
|
CodeModeHostTransport::from(AppServerCodeModeHostArgs {
|
|
code_mode_host: Some(url.clone()),
|
|
}),
|
|
CodeModeHostTransport::Grpc(url)
|
|
);
|
|
}
|