fix(proxy): 青果检测改真探并按供应商分码,三面收口凭据外漏与「无法判定」

用户报「青果也要加检测」,往下挖出四层假象,一次收口:

- 后端:probeProxy 的青果短路(过去无条件回「提取成功(青果隧道端点,连接鉴权在客户端)」,
  依据的注释已过期——存下来的链接里就带 key/pwd)删掉,改成真打一次提取,按供应商返回码
  分档出独立 check_code:channel_busy / invalid_key / forbidden / rate_limited /
  insufficient_balance / tunnel_unverified。文案出口一律抹 key/pwd。
- 后端:巡检遇 channel_busy 不落库也不推通知。通道被占不是「密钥坏了」而是「此刻问不出
  结论」,而巡检自己那一发真提取就要占掉唯一一条通道——落库等于把用户早上看到的
  「代理异常」写成我们自己造成的。
- 后端:余量口径按供应商分档。青果账号此前会落进「否则查平台套餐」那条,界面显示的是
  别人家的 jikip 余量(串档);青果不提供可鉴权的余量/余额查询(余额接口是控制台
  appid/appkey 签名档),这一档宁可返回「查不了」也不借极客的数。
- 后端:SecretMasking.maskProxy 的脏值回落不再套 mask()——它保后 4 字符,而青果的 pwd=
  恰好挂在末尾,等于把口令尾 4 位交给界面与日志;改成只交「像 host 的那一段」。
- 用户端:去掉「青果账密直连,无需检测」的 disabled 例外,未保存账密现拼链接送检;
  「无法判定」回落改成后端文案原样显示+可重试语义;代理卡不再套 LLM 渠道字典
  (「龙抬头」错标的真根因就在这行)。
- 后管:货源标签拆成两张互不相通的字典,代理列只读 masked 且不回落到原文,删掉
  user-select:all 的全选复制旁路,「修改代理」改成重填 Authkey/Authpwd 的弹窗。

判据:SecretMaskingTest(5)、UserProxyBalanceServiceTest(6)、UserApiSecretServiceTest
(+1 巡检不落库)、UserApiSecretCheckServiceTest(+138 行分码)、ProxyLinkKeyTest、
用户端 node 5 支+mount 10 支、后管 node 9 支+mount 8 支。后端整量 5187/0 失败,
full 闸门四面绿。
This commit is contained in:
2026-11-02 15:18:41 +08:00
parent 7f5437d012
commit 7e64c12dd6
24 changed files with 2062 additions and 204 deletions
@@ -0,0 +1,209 @@
/**
* 密钥管理列表页的脱敏与货源标签判据(2026-11-02 后端 `SecretMasking.maskProxy` 收口的界面侧)。
*
* 跑真组件+真 pinia store,API 用假数据顶掉:夹具里那条 `full` **故意带着假账密**
* (形状等同收口前的旧回包),用来证明界面这一侧不会把原文渲染出来——后端不下发是必要条件,
* 但界面留着 `row.proxy.full || row.proxy.masked` 那种回落时,旧包/灰度包照样会漏。
*
* 假值一律 fakekey/fakepwd(本仓有尺子按长度+高熵认凭据,长十六进制串哪怕编的也会点红)。
*
* 跑法:`npx vitest run tests/mount/user-secret-proxy-mask.mount.test.ts`
*/
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount } from '@vue/test-utils'
import { createPinia, setActivePinia, type Pinia } from 'pinia'
import UserSecretsPage from '@/pages/account/UserSecretsPage.vue'
import { useAdminSessionStore } from '@/stores/admin-session'
import { useCompanyTabStore } from '@/stores/company-tab'
const secretsApi = vi.hoisted(() => ({
fetchUserSecretList: vi.fn(),
checkUserSecret: vi.fn(),
deleteUserSecret: vi.fn(),
saveUserSecretModule: vi.fn(),
clearUserSecretModule: vi.fn(),
}))
vi.mock('@/api/user-secrets', () => secretsApi)
const FAKE_KEY = 'fakekey'
const FAKE_PWD = 'fakepwd'
/** 收口前的旧回包形状:整条青果提取链接原文,查询段里带着 key/pwd。 */
const LEGACY_PROXY_LINK = `https://overseas.proxy.qg.net/get?key=${FAKE_KEY}&pwd=${FAKE_PWD}`
/** 收口后后端实际下发的脱敏值。 */
const MASKED_PROXY = 'https://overseas.proxy.qg.net'
function moduleCell(moduleKey: string, over: Record<string, unknown> = {}) {
return {
moduleKey,
moduleLabel: moduleKey,
channel: null,
masked: 'abcd****wxyz',
full: '',
exists: true,
locked: false,
checkStatus: 'passed',
checkCode: '',
checkMessage: '',
checkLatencyMs: 12,
checkedAt: '2026-11-02T10:00:00',
updatedAt: '2026-11-02T10:00:00',
...over,
}
}
function row(over: Record<string, unknown> = {}) {
return {
userId: 7,
username: 'alice',
groups: [],
leaderUsername: '',
similarAsin: moduleCell('similar-asin'),
appearancePatent: moduleCell('appearance-patent'),
proxy: moduleCell('proxy', { masked: MASKED_PROXY }),
status: 'passed',
statusMessage: '',
createdAt: '2026-11-01T09:00:00',
updatedAt: '2026-11-02T10:00:00',
...over,
}
}
function pageOf(items: unknown[]) {
return { items, total: items.length, page: 1, pageSize: 15, groupOptions: [] }
}
/** 按表头文字取该行对应 <td> 的文本(不靠列序数:加列就会全体错位)。 */
function cellText(wrapper: ReturnType<typeof mount>, header: string): string {
const headers = wrapper.findAll('thead th').map((th) => th.text().trim())
const index = headers.findIndex((label) => label.includes(header))
expect(index, `表头里找不到「${header}」`).toBeGreaterThanOrEqual(0)
return wrapper.findAll('tbody tr')[0].findAll('td')[index].text()
}
describe('密钥管理页:代理列脱敏+货源标签分域', () => {
let pinia: Pinia
beforeEach(() => {
vi.clearAllMocks()
pinia = createPinia()
setActivePinia(pinia)
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
useCompanyTabStore().setActiveId(1)
})
async function mountWith(proxyChannel: string | null, fullValue: string = LEGACY_PROXY_LINK) {
secretsApi.fetchUserSecretList.mockResolvedValue(pageOf([
row({
similarAsin: moduleCell('similar-asin', { channel: 'longtaitou' }),
appearancePatent: moduleCell('appearance-patent', { channel: 't8star' }),
proxy: moduleCell('proxy', { channel: proxyChannel, masked: MASKED_PROXY, full: fullValue }),
}),
]))
const wrapper = mount(UserSecretsPage, { global: { plugins: [pinia] } })
await flushPromises()
return wrapper
}
it('代理列不渲染 key/pwd:整棵树(含 title 属性)都没有这两个值', async () => {
const wrapper = await mountWith('qingguo')
const markup = wrapper.html()
expect(markup).not.toContain(FAKE_KEY)
expect(markup).not.toContain(FAKE_PWD)
expect(markup).not.toContain('key=')
expect(markup).not.toContain('pwd=')
// 脱敏值照常显示,页面不是把整列抹白了事
expect(cellText(wrapper, '代理设置')).toContain(MASKED_PROXY)
})
it('代理列即便拿到旧形状的回包也只显示 masked,不回落原文', async () => {
const wrapper = await mountWith('qingguo', LEGACY_PROXY_LINK)
expect(cellText(wrapper, '代理设置')).toContain(MASKED_PROXY)
expect(cellText(wrapper, '代理设置')).not.toContain('get?')
})
it('masked 为空时留占位符:不许把 full 当兜底渲染出来', async () => {
// 后端对识别不了的形状(如无 host 的脏值)会给出空 masked;
// 界面这一侧若写成 `masked || full`,脱敏就等于没做——这一支就是钉住那条回落。
secretsApi.fetchUserSecretList.mockResolvedValue(pageOf([
row({
proxy: moduleCell('proxy', { channel: 'qingguo', masked: '', full: LEGACY_PROXY_LINK }),
}),
]))
const wrapper = mount(UserSecretsPage, { global: { plugins: [pinia] } })
await flushPromises()
expect(cellText(wrapper, '代理设置')).toContain('—')
expect(cellText(wrapper, '代理设置')).not.toContain(FAKE_KEY)
expect(wrapper.html()).not.toContain(FAKE_KEY)
expect(wrapper.html()).not.toContain(FAKE_PWD)
})
it('代理行贴的是供应商,不是 LLM 渠道名;密钥行仍显示渠道名', async () => {
const wrapper = await mountWith('qingguo')
const proxyCell = cellText(wrapper, '代理设置')
expect(proxyCell).toContain('青果')
expect(proxyCell).not.toContain('龙抬头')
expect(proxyCell).not.toContain('贞贞')
expect(cellText(wrapper, '货源查询密钥')).toContain('龙抬头')
expect(cellText(wrapper, '外观专利密钥')).toContain('贞贞')
})
it('代理行的 channel 被写成 LLM 渠道值时也不许贴出渠道名(合表就是这么错的)', async () => {
const wrapper = await mountWith('longtaitou')
const proxyCell = cellText(wrapper, '代理设置')
expect(proxyCell).not.toContain('龙抬头')
// 认不出的货源留占位,而不是硬认下一个具体名字
expect(proxyCell).toContain('—')
// 同一行上的密钥列不受影响
expect(cellText(wrapper, '货源查询密钥')).toContain('龙抬头')
})
it('页面上没有把原文带出界面的旁路:无复制/导出整条代理链接的入口', async () => {
const wrapper = await mountWith('qingguo')
const labels = wrapper.findAll('button').map((button) => button.text().trim())
expect(labels.some((label) => /复制|导出/.test(label)), `出现复制/导出入口:${labels.join('/')}`).toBe(false)
})
it('「改代理」打开的是重填表单:三个输入位都空,不给原文预填', async () => {
const wrapper = await mountWith('qingguo')
const openButton = wrapper.findAll('button').find((button) => button.text().trim() === '代填代理')
expect(openButton, '行内应有「代填代理」入口').toBeDefined()
await openButton!.trigger('click')
await flushPromises()
const inputs = wrapper.findAll('.modal input[type="text"], .modal input[type="password"]')
expect(inputs.length, '弹窗里应有账密/链接输入位').toBeGreaterThan(0)
for (const input of inputs) {
expect((input.element as HTMLInputElement).value, '不得预填任何已有值').toBe('')
}
expect(wrapper.html()).not.toContain(FAKE_KEY)
expect(wrapper.html()).not.toContain(FAKE_PWD)
})
it('保存把现拼的链接与这一单的供应商一起发出去,界面不留原文', async () => {
secretsApi.saveUserSecretModule.mockResolvedValue(moduleCell('proxy', { channel: 'qingguo' }))
const wrapper = await mountWith('qingguo')
const openButton = wrapper.findAll('button').find((button) => button.text().trim() === '代填代理')
await openButton!.trigger('click')
await flushPromises()
const fields = wrapper.findAll('.modal input[type="text"], .modal input[type="password"]')
await fields[0].setValue(FAKE_KEY)
await fields[1].setValue(FAKE_PWD)
const saveButton = wrapper.findAll('.modal button').find((button) => button.text().trim() === '保存')
expect(saveButton, '弹窗里应有「保存」').toBeDefined()
await saveButton!.trigger('click')
await flushPromises()
expect(secretsApi.saveUserSecretModule).toHaveBeenCalledTimes(1)
const [userId, moduleKey, value, channel] = secretsApi.saveUserSecretModule.mock.calls[0]
expect(userId).toBe(7)
expect(moduleKey).toBe('proxy')
expect(value).toBe(`https://overseas.proxy.qg.net/get?key=${FAKE_KEY}&pwd=${FAKE_PWD}`)
expect(channel).toBe('qingguo')
// 写请求发完,界面上仍然看不到那两个值
expect(wrapper.html()).not.toContain(FAKE_KEY)
expect(wrapper.html()).not.toContain(FAKE_PWD)
})
})
@@ -0,0 +1,102 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import {
DEFAULT_PROXY_PROVIDER,
UNKNOWN_SOURCE_LABEL,
buildProxyEntryPayload,
emptyProxyEntryDraft,
llmSourceLabel,
proxyDisplayText,
proxySourceLabel,
validateProxyEntry,
} from '../src/pages/account/user-secret-model.ts'
import { QINGGUO_EXTRACT_URL, composeQingguoLink } from '../src/shared/utils/qingguo-link.ts'
// 密钥管理页(后管)两条收口的判据(2026-11-02):
// ① 货源标签按模块分字典——代理列只认供应商,LLM 渠道名不许出现在代理行上;
// ② 代理列只显示后端脱敏值(masked),界面既不回落原文、也没有可预填的整条链接。
// 夹具里的 key/pwd 全是假值(fakekey/fakepwd),本仓有尺子按长度+高熵认凭据。
test('代理列只认供应商:LLM 渠道值在代理列认不出', () => {
assert.equal(proxySourceLabel('qingguo'), '青果')
assert.equal(proxySourceLabel('JIKIP'), '极客', '后端值大小写不一时应归一')
assert.equal(proxySourceLabel(' qingguo '), '青果')
// 这一条就是截图上「代理行贴了龙抬头」的形状:合表按值匹配会认下来,分表必须认不出
assert.equal(proxySourceLabel('longtaitou'), UNKNOWN_SOURCE_LABEL)
assert.equal(proxySourceLabel('t8star'), UNKNOWN_SOURCE_LABEL)
assert.equal(proxySourceLabel(''), UNKNOWN_SOURCE_LABEL)
assert.equal(proxySourceLabel(null), UNKNOWN_SOURCE_LABEL)
assert.equal(proxySourceLabel(undefined), UNKNOWN_SOURCE_LABEL)
})
test('LLM 列只认渠道:代理供应商名不许贴到密钥列上', () => {
assert.equal(llmSourceLabel('longtaitou'), '龙抬头')
assert.equal(llmSourceLabel('t8star'), '贞贞')
assert.equal(llmSourceLabel('qingguo'), UNKNOWN_SOURCE_LABEL)
assert.equal(llmSourceLabel('jikip'), UNKNOWN_SOURCE_LABEL)
assert.equal(llmSourceLabel('nonsense'), UNKNOWN_SOURCE_LABEL)
// 两张表除占位符外不得有任何共同输出:合表就是从这个性质破掉的
const proxyLabels = ['qingguo', 'jikip'].map(proxySourceLabel)
assert.deepEqual(proxyLabels.filter((label) => label !== UNKNOWN_SOURCE_LABEL), ['青果', '极客'])
})
test('代理列文本只取 masked,绝不回落到原文字段', () => {
const link = composeQingguoLink('fakekey', 'fakepwd')
const masked = 'https://overseas.proxy.qg.net' // 后端 SecretMasking.maskProxy 的输出形状
assert.equal(proxyDisplayText({ masked, full: '' }), masked)
// 万一某个旧回包还带着 full:界面也不许把它渲染出来(回落原文=脱敏白做)
assert.equal(proxyDisplayText({ masked, full: link }), masked)
const shown = proxyDisplayText({ masked, full: link })
assert.ok(!shown.includes('fakekey'), `显示文本里漏出了 key:${shown}`)
assert.ok(!shown.includes('fakepwd'), `显示文本里漏出了 pwd:${shown}`)
assert.ok(!shown.includes('get?'), `显示文本里漏出了提取链接的查询段:${shown}`)
})
test('masked 为空时显示占位符,不猜原文', () => {
assert.equal(proxyDisplayText({ masked: '', full: composeQingguoLink('fakekey', 'fakepwd') }), UNKNOWN_SOURCE_LABEL)
assert.equal(proxyDisplayText({ masked: null }), UNKNOWN_SOURCE_LABEL)
assert.equal(proxyDisplayText(undefined), UNKNOWN_SOURCE_LABEL)
})
test('青果链接拼装口径:overseas 域+key+pwd,特殊字符按 URL 组件编码', () => {
assert.equal(composeQingguoLink('fakekey', 'fakepwd'), `${QINGGUO_EXTRACT_URL}?key=fakekey&pwd=fakepwd`)
assert.equal(composeQingguoLink(' fakekey ', ' fakepwd '), `${QINGGUO_EXTRACT_URL}?key=fakekey&pwd=fakepwd`)
// pwd 里的 @ 与 : 不编码会把 host 切歪(AGENTS 铁律 25 实录)
const encoded = composeQingguoLink('fakekey', 'p@ss:1')
assert.ok(encoded.includes('pwd=p%40ss%3A1'), encoded)
})
test('改代理每次从空表开始:没有原文可预填', () => {
const draft = emptyProxyEntryDraft('qingguo')
assert.equal(draft.provider, 'qingguo')
assert.deepEqual([draft.authkey, draft.authpwd, draft.link], ['', '', ''])
// 供应商值认不出时不猜成凭据,只回落到后端默认供应商(极客)
assert.equal(emptyProxyEntryDraft('longtaitou').provider, DEFAULT_PROXY_PROVIDER)
assert.equal(emptyProxyEntryDraft(null).provider, DEFAULT_PROXY_PROVIDER)
})
test('青果要两把都填:缺哪把就点名哪把', () => {
assert.equal(validateProxyEntry({ provider: 'qingguo', authkey: '', authpwd: 'fakepwd', link: '' }), '请填写青果 Authkey')
assert.match(validateProxyEntry({ provider: 'qingguo', authkey: 'fakekey', authpwd: ' ', link: '' }), /Authpwd/)
assert.equal(validateProxyEntry({ provider: 'qingguo', authkey: 'fakekey', authpwd: 'fakepwd', link: '' }), '')
assert.equal(buildProxyEntryPayload({ provider: 'qingguo', authkey: 'fakekey', authpwd: 'fakepwd', link: '' })?.value,
composeQingguoLink('fakekey', 'fakepwd'))
assert.equal(buildProxyEntryPayload({ provider: 'qingguo', authkey: 'fakekey', authpwd: '', link: '' }), null,
'不合法时不得产出载荷(拿空串顶上去等于把配置清空)')
})
test('极客填自家提取链接:形状与后端 validateProxyValue 同口径、不扩大判死', () => {
const draft = { provider: 'jikip' as const, authkey: '', authpwd: '', link: 'https://api.example.test/ip-get?appkey=fakekey' }
assert.equal(validateProxyEntry(draft), '')
assert.deepEqual(buildProxyEntryPayload(draft), { value: 'https://api.example.test/ip-get?appkey=fakekey', channel: 'jikip' })
assert.match(validateProxyEntry({ ...draft, link: '' }), /极客提取链接/)
assert.match(validateProxyEntry({ ...draft, link: 'ftp://api.example.test/ip-get' }), /格式不正确/)
assert.match(validateProxyEntry({ ...draft, link: 'not a url' }), /格式不正确/)
// 静态代理地址(http://host:port)同样是后端认的形态,前端不许判死
assert.equal(validateProxyEntry({ ...draft, link: 'http://1.2.3.4:8080' }), '')
})
test('载荷带上这一单的供应商:channel 缺失会被后端按域名识别,识别不出就静默换供应商', () => {
assert.equal(buildProxyEntryPayload({ provider: 'qingguo', authkey: 'fakekey', authpwd: 'fakepwd', link: '' })?.channel, 'qingguo')
assert.equal(buildProxyEntryPayload({ provider: 'jikip', authkey: '', authpwd: '', link: 'https://api.example.test/ip-get' })?.channel, 'jikip')
})