Skip to content

Commit 0cbb3ee

Browse files
committed
Verify authenticated HTTPS collect across the three JDK lines
1 parent b40ed5a commit 0cbb3ee

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Configuration is object-based via `OpenCliProperties`:
185185
| `cleanupGraceMillis` | `5000` | Positive, separate local cleanup grace in milliseconds. Timeout values must fit the monotonic nanosecond budget. |
186186
| `startupProbeTimeoutMillis` | `30000` | Availability-probe timeout |
187187
| `environment` | `{}` | Extra environment variables (e.g. `OPENCLI_CDP_ENDPOINT`) |
188-
| `remoteAgentBaseUrl` | — | Remote agent base URL |
188+
| `remoteAgentBaseUrl` | — | Remote Agent HTTP(S) base URL. Keep any deployment path prefix and omit user info, queries and fragments. |
189189
| `remoteCollectMode` | `cdp` | `bridge` or `cdp` (must match the agent side) |
190190
| `remoteOutputFormat` | `json` | Output format requested from the agent |
191191
| `remoteCdpEndpoint` | — | Optional CDP endpoint overriding the agent default |

‎README.zh-CN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ cli.gemini().deepResearch("topic",
184184
| `cleanupGraceMillis` | `5000` | 独立的本地清理等待上限,单位毫秒,必须为正数。时间配置必须可换算成单调时钟的纳秒预算。 |
185185
| `startupProbeTimeoutMillis` | `30000` | 可用性探测超时 |
186186
| `environment` | `{}` | 额外环境变量(如 `OPENCLI_CDP_ENDPOINT`) |
187-
| `remoteAgentBaseUrl` | — | 远程 Agent 根地址 |
187+
| `remoteAgentBaseUrl` | — | 远程 Agent 的 HTTP(S) 基址,可以保留部署路径前缀。省略用户信息、查询参数和片段。 |
188188
| `remoteCollectMode` | `cdp` | `bridge` 或 `cdp`(须与 Agent 侧一致) |
189189
| `remoteOutputFormat` | `json` | 向 Agent 请求的输出格式 |
190190
| `remoteCdpEndpoint` | — | 可选,覆盖 Agent 默认 CDP 端点 |

‎openspec/changes/harden-opencli-remote-collect/tasks.md‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
- [ ] 2.1 引入显式 legacy capability guard 和保真转换子集,避免无条件解析任意 argv。
1616
- [x] 2.2 区分 HTTP、协议与命令失败,保留兼容退出码及其来源。见 OC-REMOTE-003/004 验证。
17-
- [ ] 2.3 使 body/timeout 有界并实现可测试的显式 header 配置,保持 TLS。
17+
- [x] 2.3 使 body/timeout 有界并实现可测试的显式 header 配置,保持 TLS。见 OC-REMOTE-005/006 验证。
1818

1919
## 3. 三线与安全
2020

2121
- [x] 3.1 验证凭据、URL query、正文和异常 cause 的默认诊断边界。见 OC-REMOTE-006 验证。
22-
- [ ] 3.2 在三分支分别跑本地 HTTP fixture;记录旧 API 的行为收紧与迁移例子。
22+
- [x] 3.2 在三分支分别跑本地 HTTP fixture;记录旧 API 的行为收紧与迁移例子。见三线验证。
2323
- [ ] 3.3 未取得服务端契约的扩展仍标记 unsupported,不借此宣称远程全量兼容。
2424

2525
## 证据交付模板(实施时填写)
@@ -69,3 +69,17 @@ JDK 17 基线中,chunked 响应每 125 ms 持续发送数据,900 ms 的原
6969
基线先增加配置和夹具,尚未接入传输。HTTPS 认证成功、明文认证拒绝及三类 URL 凭据输入共 5 项验收失败。接入后,回环 HTTPS 服务使用独立测试证书和显式信任。未信任的证书在请求转交应用处理器前被拒绝。信任证书后,桩仅在明确收到正确的指定请求头时返回成功。去除配置后按 401 处理,不自动生成认证数据。错误凭据的 401 回显未出现在默认日志、异常栈或原文捕获关闭时的失败快照中。
7070

7171
显式认证采用 SDK 已有 Apache HttpClient 的 HTTPS 校验。明文认证、URL 用户信息、查询参数和片段均在发送前拒绝。测试复用了 WebSocket 的回环证书生成方式。真实 Agent 可接受的请求头和生产认证流程仍待部署契约验证。
72+
73+
### 三线验证
74+
75+
以分别包含显式 HTTPS 认证的 `c03aac0`、`b40ed5a`、`1ee75dc` 为基线,补测带部署路径前缀的 HTTPS Agent。原基址 `https://<agent>/agent///` 在桩上实际到达 `/agent/collect`,认证值由指定请求头传递,URL 和请求体中均没有认证值。普通 HTTP 的认证请求、包含用户信息或查询或片段的基址继续在发起 HTTP 前拒绝。配置样例见中英文 README,认证值从调用方环境读取。
76+
77+
三条线分别使用其 Wrapper 执行 `./mvnw -B -ntp clean verify`,退出码均为 0。每条线的 `OpenCliRemoteAgentHttpClientTest` 均运行 54 项,零失败、错误和跳过。下表是构建实测。日志、Surefire XML 和 JaCoCo XML 由对应构建产生。
78+
79+
| JDK | 路径前缀验证提交 | 全量测试数 | 行覆盖率 |
80+
| --- | --- | ---: | ---: |
81+
| 8 | `f0286587c9caa98aa50fa4d4ab0045d23776b453` | 2178 | 92.44% |
82+
| 17 | 本提交的路径前缀测试,基于 `b40ed5a91ed357478fe0f05b4936e4ac3508ec31` | 2179 | 92.53% |
83+
| 21 | `85de78f4e847ac1c1ff73d855573954a5898e9ee` | 2178 | 92.52% |
84+
85+
这组测试覆盖可控 HTTP 和 HTTPS 服务端。真实 opencli-admin 部署的认证协议及扩展契约仍待验收。

‎src/test/java/io/github/easy4j/opencli/remote/OpenCliRemoteAgentHttpClientTest.java‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ void authenticationHeaderIsSentOnlyOverVerifiedTls(@TempDir Path temporary) thro
373373
AtomicReference<String> receivedUri = new AtomicReference<>();
374374
OpenCliTlsFixture tls = OpenCliTlsFixture.create(temporary);
375375
SSLContext previous = SSLContext.getDefault();
376-
try (JsonCollectStub stub = JsonCollectStub.start(tls.getServer(), exchange -> {
376+
try (JsonCollectStub stub = JsonCollectStub.start(tls.getServer(), "/agent/collect", exchange -> {
377377
receivedCredential.set(exchange.getRequestHeaders().getFirst(header));
378378
receivedUri.set(exchange.getRequestURI().toASCIIString());
379379
// The synthetic fixture supports only this explicit header.
@@ -389,7 +389,7 @@ void authenticationHeaderIsSentOnlyOverVerifiedTls(@TempDir Path temporary) thro
389389
}
390390
})) {
391391
OpenCliProperties props = baseProps(stub.port());
392-
props.setRemoteAgentBaseUrl("https://127.0.0.1:" + stub.port());
392+
props.setRemoteAgentBaseUrl("https://127.0.0.1:" + stub.port() + "/agent///");
393393
props.setRemoteAuthentication(new OpenCliRemoteAuthentication(header, credential));
394394
Assertions.assertFalse(props.toString().contains(credential));
395395
Assertions.assertNull(props.copyForLocalCliExecution().getRemoteAuthentication());
@@ -405,7 +405,7 @@ void authenticationHeaderIsSentOnlyOverVerifiedTls(@TempDir Path temporary) thro
405405
try (OpenCliRemoteAgentHttpClient client = new OpenCliRemoteAgentHttpClient(props)) {
406406
Assertions.assertTrue(client.collect(request).isSuccess());
407407
Assertions.assertEquals(credential, receivedCredential.get());
408-
Assertions.assertEquals("/collect", receivedUri.get());
408+
Assertions.assertEquals("/agent/collect", receivedUri.get());
409409
Assertions.assertFalse(stub.requestBody.contains(credential));
410410
props.setRemoteAuthentication(new OpenCliRemoteAuthentication(header, "rejected-" + credential));
411411
ByteArrayOutputStream diagnostics = new ByteArrayOutputStream();
@@ -719,6 +719,10 @@ static JsonCollectStub start(HttpHandler response) throws IOException {
719719
}
720720

721721
static JsonCollectStub start(SSLContext tls, HttpHandler response) throws IOException {
722+
return start(tls, "/collect", response);
723+
}
724+
725+
static JsonCollectStub start(SSLContext tls, String path, HttpHandler response) throws IOException {
722726
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 0);
723727
HttpServer server;
724728
if (Objects.isNull(tls)) {
@@ -730,7 +734,7 @@ static JsonCollectStub start(SSLContext tls, HttpHandler response) throws IOExce
730734
}
731735
JsonCollectStub stub = new JsonCollectStub(server, server.getAddress().getPort());
732736
server.createContext(
733-
"/collect",
737+
path,
734738
new HttpHandler() {
735739
@Override
736740
public void handle(HttpExchange exchange) throws IOException {

0 commit comments

Comments
 (0)