From d05ebfb5b0365924783a0b65eaadb174cd70b802 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 15 Sep 2026 11:12:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(apix):=20passthrough=20=E6=96=B0=E5=BB=BA?= =?UTF-8?q?=E5=8F=AF=E7=A9=BA=20Key=20=E2=80=94=E2=80=94=20upsert=20?= =?UTF-8?q?=E6=8C=89=20mode=20=E6=94=BE=E5=AE=BD=E6=A0=A1=E9=AA=8C=20(1.0.?= =?UTF-8?q?21)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.0.20 现场踩坑:upsert 统一要求「基址与密钥」,但 passthrough 设计是 Key 可空(内部服务免鉴权,handler 已经放空 Key 转发),管理台提交 passthrough + 空 Key 直接 400。 修:vendor 必须 base + key 都填;passthrough 仅 base 必填,key 可空。 补 2 条测试断言防回归(vendor 缺 Key → 400;passthrough 空 Key → 200)。 回归 227/0 全绿。 --- rust/crates/plugin-apix/src/apix.rs | 13 +++++++++++-- tests/llm/e2e.sh | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/rust/crates/plugin-apix/src/apix.rs b/rust/crates/plugin-apix/src/apix.rs index 10fa623..2e3fbb3 100644 --- a/rust/crates/plugin-apix/src/apix.rs +++ b/rust/crates/plugin-apix/src/apix.rs @@ -664,8 +664,17 @@ pub fn upsert( let key_val = new_key .or_else(|| existing.as_ref().map(|e| e.key.clone())) .unwrap_or_default(); - if existing.is_none() && (base.is_empty() || key_val.is_empty()) { - return Err("新建代理必须提供供应商基址与密钥".to_owned()); + // 新建必填校验:vendor 必须 base + key 都填;passthrough 仅 base 必填, + // key 可空(内部服务免鉴权,下发时 nginx 空串语义 = 不发该头)。 + // 这是 1.0.20 现场踩到的坑:原校验统一要求「基址与密钥」,导致管理台 + // 提交 passthrough + 空 Key 直接 400,handler 实际是放行的。 + if existing.is_none() { + if base.is_empty() { + return Err("新建代理必须提供供应商基址".to_owned()); + } + if key_val.is_empty() && mode == config::APIX_MODE_VENDOR { + return Err("vendor 模式必须提供供应商 Key(passthrough 可留空)".to_owned()); + } } let supplier = match supplier_raw { Some(s) => util::trim(s).chars().take(config::APIX_NAME_MAX_LEN).collect(), diff --git a/tests/llm/e2e.sh b/tests/llm/e2e.sh index 4c580fb..ba0c8ac 100755 --- a/tests/llm/e2e.sh +++ b/tests/llm/e2e.sh @@ -381,6 +381,12 @@ ck "非法 slug → 400" 400 "$(code -b "$JAR" -X POST $API/api/admin/apix/save -H 'Content-Type: application/json' -d "$(jbody slug 'Bad Slug!' asset_id x)")" ck "缺 asset_id → 400" 400 "$(code -b "$JAR" -X POST $API/api/admin/apix/save \ -H 'Content-Type: application/json' -d "$(jbody slug med asset_id '')")" +ck "★vendor 新建缺 Key → 400(vendor 必须 Key)" 400 \ + "$(code -b "$JAR" -X POST $API/api/admin/apix/save \ + -H 'Content-Type: application/json' -d "$(jbody slug vendorbare asset_id x base http://127.0.0.1:18999)")" +ck "★passthrough 新建可空 Key → 200(1.0.20 现场 bug 防回归)" 200 \ + "$(code -b "$JAR" -X POST $API/api/admin/apix/save \ + -H 'Content-Type: application/json' -d "$(jbody slug pt_nokey mode passthrough base http://127.0.0.1:18999)")" ck "新建代理 med → 200" 200 "$(code -b "$JAR" -X POST $API/api/admin/apix/save \ -H 'Content-Type: application/json' -d "$(jbody slug med asset_id asset_26476ef1-4687-45 name 疾病百科 params kw base http://127.0.0.1:18999 key ak_test_supplier_key supplier vendor-a)")" ck " ★新代理立即可用(写穿 shm)" 200 "$(code -H "X-API-Key: $ALICE_KEY" "$GW/apix/med?kw=感冒")"