Files
crawler-plugin/frontend-vue/tests/青果账密拼提取链接.test.ts
T
huangzd1997 7e64c12dd6 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 闸门四面绿。
2026-11-02 15:18:41 +08:00

81 lines
4.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { composeQingguoLink, QINGGUO_EXTRACT_URL } from '../src/shared/utils/qingguo-link.ts'
import { moduleSourceLabel, proxyCheckValue } from '../src/shared/utils/api-secret-channel.ts'
/**
* 青果没有「提取链接」可填,用户只给 key(Authkey)/ pwd(Authpwd),链接必须由前端拼
* (2026-10-31 用户拍板;官方口径 `https://overseas.proxy.qg.net/get?key=…&pwd=…`)。
* 拼不出来或拼错,用户就会在「填了账密」之后仍被商标检测的前置检查判成「未配置代理」。
*/
test('青果按密码鉴权拼出 key+pwd 的提取链接', () => {
assert.equal(composeQingguoLink('40F79A90', 'S3cret'),
`${QINGGUO_EXTRACT_URL}?key=40F79A90&pwd=S3cret`)
})
test('只有 key 时也拼得出来(不猜白名单档,缺 pwd 就只带 key)', () => {
assert.equal(composeQingguoLink(' 40F79A90 ', ''), `${QINGGUO_EXTRACT_URL}?key=40F79A90`)
})
test('没填 key 就不拼链接(空串=没配置,不许拼一条必然失败的链接)', () => {
assert.equal(composeQingguoLink('', 'pwd'), '')
assert.equal(composeQingguoLink(' ', 'pwd'), '')
})
test('key/pwd 里的特殊字符要编码,不能把查询串拼坏', () => {
const link = composeQingguoLink('a&b=c', 'p@ss:1')
assert.ok(link.endsWith('?key=a%26b%3Dc&pwd=p%40ss%3A1'), link)
})
/**
* 「点检测」送出去的链接必须走同一条拼装出处(2026-11-02 放开青果检测)。
* 检测按钮过去被 `proxyProvider === 'qingguo'` 直接 disabled,用户只能"保存了再猜";
* 现在未保存也要能检,就必须送现拼的链接——若这里另写一遍 URL,就会出现
* 「检的是一条、存的是另一条」(AGENTS.md 铁律 27 的同源边界)。
*/
test('检测未保存的青果账密时送现拼链接(与保存路径同一出处)', () => {
const sent = proxyCheckValue({
provider: 'qingguo', url: '', dirty: true, account: 'fakekey', password: 'fakepwd',
})
assert.equal(sent, composeQingguoLink('fakekey', 'fakepwd'), '送检值必须逐字节等于拼装出处的输出')
assert.ok(sent?.includes('fakekey'), '账密没进来就等于白检一次')
})
test('没改动时不送链接:让服务端用它库里存的那条(后端已不下发链接原文)', () => {
assert.equal(
proxyCheckValue({ provider: 'qingguo', url: '', dirty: false, account: 'fakekey', password: 'fakepwd' }),
undefined,
'已保存态送 undefined,前端手里没有库里的值可送')
assert.equal(
proxyCheckValue({ provider: 'jikip', url: 'http://1.2.3.4:8080', dirty: false, account: '', password: '' }),
undefined,
)
})
test('极客的检测送地址框里的原文(青果才需要拼)', () => {
assert.equal(
proxyCheckValue({ provider: 'jikip', url: ' http://1.2.3.4:8080 ', dirty: true, account: '', password: '' }),
'http://1.2.3.4:8080',
)
})
test('草稿拼不出链接时返回空串:调用方必须拦住,不能拿空串冒充"检测输入值"', () => {
assert.equal(
proxyCheckValue({ provider: 'qingguo', url: '', dirty: true, account: '', password: 'fakepwd' }),
'',
'空串与 undefined 语义不同:前者是"没配出来",后者才是"用库里的"')
})
/**
* 卡片标签:代理卡的货源是供应商(青果/极客),不能进 LLM 渠道字典——
* `normalizeLlmChannel('qingguo')` 会静默落到 LLM 默认值,界面就成了「代理卡标着渠道名」
* (2026-11-02 后端核实的那个错标)。
*/
test('代理卡按供应商标货源,LLM 卡仍按渠道字典', () => {
assert.equal(moduleSourceLabel('proxy', 'qingguo'), '青果')
assert.equal(moduleSourceLabel('proxy', 'jikip'), '极客')
assert.equal(moduleSourceLabel('appearance-patent', 'longtaitou'), '龙抬头')
assert.equal(moduleSourceLabel('similar-asin', 't8star'), '贞贞')
assert.notEqual(moduleSourceLabel('proxy', 'qingguo'), '龙抬头', '供应商 key 不许被当成 LLM 渠道回显')
})