mirror of
https://github.com/openai/codex.git
synced 2026-11-20 15:07:25 +00:00
Support gRPC code-mode hosts in app server (#38288)
## 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
This commit is contained in:
1 parent
e766f75989
commit
5104cb649e
9 files changed
+216
-26
No files matched your search
@@ -1,30 +1,63 @@
|
||||
use super::AppServerCodeModeHostArgs;
|
||||
use super::CodeModeHostTransport;
|
||||
use super::parse_websocket_url;
|
||||
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"] {
|
||||
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_websocket_url(endpoint),
|
||||
parse_host_url(endpoint),
|
||||
Ok(Url::parse(endpoint).expect("test endpoint should parse"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn websocket_host_rejects_invalid_endpoints() {
|
||||
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://127.0.0.1:8765",
|
||||
"https://example.test/code-mode",
|
||||
"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 websocket",
|
||||
"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_websocket_url(endpoint).is_err(),
|
||||
parse_host_url(endpoint).is_err(),
|
||||
"invalid code-mode host endpoint should be rejected: {endpoint}"
|
||||
);
|
||||
}
|
||||
@@ -49,3 +82,15 @@ fn explicit_websocket_host_selects_remote_transport() {
|
||||
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)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user