2026-05-01 20:39:09 +08:00
|
|
|
import { beforeAll, describe, expect, it, vi } from 'vitest'
|
2026-04-23 15:26:24 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
vi.mock('./account-binder', () => ({
|
2026-04-23 15:26:24 +08:00
|
|
|
probePublishAccountSession: vi.fn(),
|
|
|
|
|
silentRefreshPublishAccountSession: vi.fn(),
|
2026-05-01 20:39:09 +08:00
|
|
|
}))
|
2026-04-23 15:26:24 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
let getPlatformAdapter: typeof import('./platform-auth-adapters').getPlatformAdapter
|
2026-04-23 15:26:24 +08:00
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2026-05-01 20:39:09 +08:00
|
|
|
;({ getPlatformAdapter } = await import('./platform-auth-adapters'))
|
|
|
|
|
})
|
2026-04-23 15:26:24 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
describe('platform auth adapters', () => {
|
|
|
|
|
it('classifies Wenxin environment abnormal messages as risk control', () => {
|
|
|
|
|
const adapter = getPlatformAdapter('wenxin')
|
2026-04-23 15:26:24 +08:00
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
2026-05-01 20:39:09 +08:00
|
|
|
message: '当前访问环境存在异常,请更换浏览器再尝试提问',
|
2026-04-23 15:26:24 +08:00
|
|
|
}),
|
2026-05-01 20:39:09 +08:00
|
|
|
).toBe('risk_control')
|
|
|
|
|
})
|
2026-04-26 21:57:04 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
it('classifies Qiehao missing cookie as auth failure', () => {
|
|
|
|
|
const adapter = getPlatformAdapter('qiehao')
|
2026-04-26 21:57:04 +08:00
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
2026-05-01 20:39:09 +08:00
|
|
|
code: 'qiehao_cookie_missing',
|
2026-04-26 21:57:04 +08:00
|
|
|
},
|
|
|
|
|
}),
|
2026-05-01 20:39:09 +08:00
|
|
|
).toBe('auth_failure')
|
|
|
|
|
})
|
2026-04-26 21:57:04 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
it('classifies Bilibili missing csrf as auth failure', () => {
|
|
|
|
|
const adapter = getPlatformAdapter('bilibili')
|
2026-04-26 21:57:04 +08:00
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
2026-05-01 20:39:09 +08:00
|
|
|
code: 'bilibili_csrf_missing',
|
2026-04-26 21:57:04 +08:00
|
|
|
},
|
|
|
|
|
}),
|
2026-05-01 20:39:09 +08:00
|
|
|
).toBe('auth_failure')
|
|
|
|
|
})
|
2026-04-27 00:57:37 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
it('classifies Juejin missing login as auth failure', () => {
|
|
|
|
|
const adapter = getPlatformAdapter('juejin')
|
2026-04-27 00:57:37 +08:00
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
2026-05-01 20:39:09 +08:00
|
|
|
code: 'juejin_not_logged_in',
|
2026-04-27 00:57:37 +08:00
|
|
|
},
|
|
|
|
|
}),
|
2026-05-01 20:39:09 +08:00
|
|
|
).toBe('auth_failure')
|
|
|
|
|
})
|
2026-04-27 00:57:37 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
it('classifies Sohuhao missing login as auth failure', () => {
|
|
|
|
|
const adapter = getPlatformAdapter('sohuhao')
|
2026-04-27 00:57:37 +08:00
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
2026-05-01 20:39:09 +08:00
|
|
|
code: 'sohuhao_not_logged_in',
|
2026-04-27 00:57:37 +08:00
|
|
|
},
|
|
|
|
|
}),
|
2026-05-01 20:39:09 +08:00
|
|
|
).toBe('auth_failure')
|
|
|
|
|
})
|
2026-04-27 00:57:37 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
it('does not classify Wangyihao publish token misses as auth failure', () => {
|
|
|
|
|
const adapter = getPlatformAdapter('wangyihao')
|
2026-04-27 00:57:37 +08:00
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
2026-05-01 20:39:09 +08:00
|
|
|
code: 'wangyihao_token_missing',
|
2026-04-27 00:57:37 +08:00
|
|
|
},
|
|
|
|
|
}),
|
2026-05-01 20:39:09 +08:00
|
|
|
).toBe('ok')
|
|
|
|
|
})
|
2026-04-27 00:57:37 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
it('classifies Weixin GZH verification as challenge', () => {
|
|
|
|
|
const adapter = getPlatformAdapter('weixin_gzh')
|
2026-04-27 00:57:37 +08:00
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
2026-05-01 20:39:09 +08:00
|
|
|
code: 'weixin_gzh_challenge_required',
|
2026-04-27 00:57:37 +08:00
|
|
|
},
|
|
|
|
|
}),
|
2026-05-01 20:39:09 +08:00
|
|
|
).toBe('challenge')
|
|
|
|
|
})
|
2026-04-27 00:57:37 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
it('classifies Weixin GZH login timeout as auth failure', () => {
|
|
|
|
|
const adapter = getPlatformAdapter('weixin_gzh')
|
2026-04-29 17:11:19 +08:00
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
2026-05-01 20:39:09 +08:00
|
|
|
message: '登录超时,请重新登录',
|
2026-04-29 17:11:19 +08:00
|
|
|
}),
|
2026-05-01 20:39:09 +08:00
|
|
|
).toBe('auth_failure')
|
|
|
|
|
})
|
2026-04-29 17:11:19 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
it('classifies ZOL missing login as auth failure', () => {
|
|
|
|
|
const adapter = getPlatformAdapter('zol')
|
2026-04-27 00:57:37 +08:00
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
2026-05-01 20:39:09 +08:00
|
|
|
code: 'zol_not_logged_in',
|
2026-04-27 00:57:37 +08:00
|
|
|
},
|
|
|
|
|
}),
|
2026-05-01 20:39:09 +08:00
|
|
|
).toBe('auth_failure')
|
|
|
|
|
})
|
2026-04-27 00:57:37 +08:00
|
|
|
|
2026-05-01 20:39:09 +08:00
|
|
|
it('classifies Dongchedi platform verification as challenge', () => {
|
|
|
|
|
const adapter = getPlatformAdapter('dongchedi')
|
2026-04-27 00:57:37 +08:00
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
adapter.classifyFailure({
|
|
|
|
|
error: {
|
2026-05-01 20:39:09 +08:00
|
|
|
code: 'dongchedi_challenge_required',
|
2026-04-27 00:57:37 +08:00
|
|
|
},
|
|
|
|
|
}),
|
2026-05-01 20:39:09 +08:00
|
|
|
).toBe('challenge')
|
|
|
|
|
})
|
|
|
|
|
})
|