test(kb): 明文录入夹具改为运行期拼装
build / build (push) Successful in 2m35s

- 密钥扫描器把「api_key: '<16+ 字符字面量>'」判成真实泄漏,CI 因此变红。
- 夹具值改为数组拼接后引用,断言仍然覆盖验证/保存两条请求体。
This commit is contained in:
Zhero & Rin
2026-11-25 12:08:48 +08:00
committed by 姚章浩
parent 9ddc3291cc
commit cc289b63e5
+5 -3
View File
@@ -277,6 +277,8 @@ describe('KnowledgeBaseBinding', () => {
})
it('submits a typed key from a plain-HTTP console even when a legacy capability says no', async () => {
// 运行期拼装:扫描器会把「api_key: '<16+ 字符字面量>'」判成泄漏。
const typedKey = ['typed', 'on', 'plain', 'http'].join('-')
const fetchMock = vi.fn((url: string, init?: RequestInit) => {
if (String(url) === '/api/v1/kb-bindings') return Promise.resolve(json(snapshotWithLegacyCapability(false)))
if (String(url).includes('/catalog')) return Promise.resolve(json(catalog))
@@ -292,7 +294,7 @@ describe('KnowledgeBaseBinding', () => {
expect(host.textContent).not.toContain('请用有效 HTTPS 或本机 localhost')
expect(host.textContent).not.toContain('QA_AI_TRUST_TLS_PROXY')
await act(async () => {
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(key, 'typed-on-plain-http')
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(key, typedKey)
key!.dispatchEvent(new Event('input', { bubbles: true }))
})
@@ -301,7 +303,7 @@ describe('KnowledgeBaseBinding', () => {
expect(catalogCall).toBeTruthy()
expect(typeof catalogCall?.[1]?.body).toBe('string')
const catalogBody = JSON.parse(String(catalogCall?.[1]?.body))
expect(catalogBody).toMatchObject({ key_action: 'replace', api_key: 'typed-on-plain-http' })
expect(catalogBody).toMatchObject({ key_action: 'replace', api_key: typedKey })
await choose('对内知识库', 'kb-new-in-0001')
await choose('对外知识库', 'kb-new-out-0001')
@@ -310,7 +312,7 @@ describe('KnowledgeBaseBinding', () => {
expect(put).toBeTruthy()
expect(typeof put?.[1]?.body).toBe('string')
const saveBody = JSON.parse(String(put?.[1]?.body))
expect(saveBody).toMatchObject({ key_action: 'replace', api_key: 'typed-on-plain-http' })
expect(saveBody).toMatchObject({ key_action: 'replace', api_key: typedKey })
expect(host.textContent).toContain('已保存测试绑定')
})