修复(半自动履约): 拆分虎牙账号与角色身份并恢复CK注入
This commit is contained in:
@@ -321,12 +321,33 @@ test(
|
||||
huyaUid: `it-huya-${suffix}`,
|
||||
bindGameAccount: '集成测试虎牙账号',
|
||||
bindGameRole: '集成测试角色',
|
||||
bindGameRoleId: '1192083858',
|
||||
bindGameRoleToken: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
||||
bindGameChannel: '安卓(android) · QQ',
|
||||
roleIdentitySource: 'huya_outer_current',
|
||||
verificationBasis: 'role_name_zone',
|
||||
},
|
||||
{ eventId: snapshotEventId, eventType: 'semi_auto.task_state' },
|
||||
)
|
||||
assert.equal(snapshot.applied, true)
|
||||
const reusedUidEventId = randomUUID()
|
||||
await expectErrorCode(
|
||||
() =>
|
||||
applySemiAutoTaskStateSnapshot(
|
||||
{
|
||||
eventId: reusedUidEventId,
|
||||
taskId,
|
||||
orderNo,
|
||||
loginStatus: 'authenticated',
|
||||
bindingStatus: 'role_ready',
|
||||
huyaUid: '1199664118656',
|
||||
platformGameRoleUid: '1199664118656',
|
||||
bindGameRole: '集成测试角色',
|
||||
bindGameChannel: '安卓(android) · QQ',
|
||||
},
|
||||
{ eventId: reusedUidEventId, eventType: 'semi_auto.task_state' },
|
||||
),
|
||||
'semi_auto_snapshot_platform_role_uid_reused',
|
||||
)
|
||||
const duplicateSnapshot = await applySemiAutoTaskStateSnapshot(
|
||||
{
|
||||
eventId: snapshotEventId,
|
||||
@@ -342,8 +363,12 @@ test(
|
||||
login_status: string
|
||||
binding_status: string
|
||||
execution_status: string
|
||||
bind_game_role_token: string
|
||||
role_identity_source: string
|
||||
verification_basis: string
|
||||
}>(
|
||||
`SELECT login_status, binding_status, execution_status
|
||||
`SELECT login_status, binding_status, execution_status,
|
||||
bind_game_role_token, role_identity_source, verification_basis
|
||||
FROM semi_auto_tasks WHERE id = $1`,
|
||||
[taskId],
|
||||
)
|
||||
@@ -351,6 +376,9 @@ test(
|
||||
login_status: 'authenticated',
|
||||
binding_status: 'confirmed',
|
||||
execution_status: 'waiting_operator',
|
||||
bind_game_role_token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
||||
role_identity_source: 'huya_outer_current',
|
||||
verification_basis: 'role_name_zone',
|
||||
})
|
||||
} finally {
|
||||
if (orderId > 0) {
|
||||
@@ -748,6 +776,143 @@ test(
|
||||
},
|
||||
)
|
||||
|
||||
test(
|
||||
'虎牙数据库 CK 可在进程会话丢失后恢复并生成浏览器注入票据',
|
||||
{ skip: !TEST_DATABASE_URL ? '未设置 SEMI_AUTO_TASK_TEST_DATABASE_URL' : false },
|
||||
async () => {
|
||||
process.env.DATABASE_URL = TEST_DATABASE_URL
|
||||
process.env.ENABLE_DEV_MOCK = '1'
|
||||
const { closeDb, query, withTransaction } = await import('../../db/client.js')
|
||||
const { createSemiAutoMock } = await import('../dev-mock/dev-mock-service.js')
|
||||
const { upsertSemiAutoCredentialWithClient } = await import('./semi-auto-credential-service.js')
|
||||
const { createAdminBrowserSession, consumeSemiAutoInjectionTicket } =
|
||||
await import('./semi-auto-task-service.js')
|
||||
const { huyaNativeConnector } = await import('./huya-native/huya-native-connector.js')
|
||||
const suffix = `${Date.now()}_${Math.floor(Math.random() * 1_000_000)}`
|
||||
const orderNo = `IT-HUYA-RESTORE-${suffix}`
|
||||
const platformUid = '1686664168'
|
||||
let orderId = 0
|
||||
let configId = 0
|
||||
let credentialId = 0
|
||||
let adminId = 0
|
||||
let restoredSessionId = ''
|
||||
try {
|
||||
const admin = await query<{ id: number }>(
|
||||
`INSERT INTO admin_users (username, password_hash, role, status, created_at, updated_at)
|
||||
VALUES ($1, 'x', 'support', 'active', NOW(), NOW()) RETURNING id`,
|
||||
[`it_huya_restore_admin_${suffix}`],
|
||||
)
|
||||
adminId = Number(admin.rows[0]?.id || 0)
|
||||
const result = await createSemiAutoMock({
|
||||
orderNo,
|
||||
skuName: `虎牙CK恢复-${suffix}`,
|
||||
quantity: 1,
|
||||
pageTitle: '虎牙CK恢复集成测试',
|
||||
connectorMode: 'embedded',
|
||||
})
|
||||
orderId = result.orderId
|
||||
configId = result.configId
|
||||
credentialId = await withTransaction((client) =>
|
||||
upsertSemiAutoCredentialWithClient(client, {
|
||||
platform: 'huya',
|
||||
source: 'sms',
|
||||
payload: {
|
||||
platformUid,
|
||||
nickname: '虎牙恢复测试',
|
||||
cookies: [
|
||||
{
|
||||
name: 'yyuid',
|
||||
value: platformUid,
|
||||
domain: '.huya.com',
|
||||
path: '/',
|
||||
secure: true,
|
||||
httpOnly: false,
|
||||
expiresAt: null,
|
||||
},
|
||||
{
|
||||
name: 'udb_uid',
|
||||
value: platformUid,
|
||||
domain: '.huya.com',
|
||||
path: '/',
|
||||
secure: true,
|
||||
httpOnly: false,
|
||||
expiresAt: null,
|
||||
},
|
||||
{
|
||||
name: 'udb_cred',
|
||||
value: `restored-${suffix}`,
|
||||
domain: '.huya.com',
|
||||
path: '/',
|
||||
secure: true,
|
||||
httpOnly: false,
|
||||
expiresAt: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
)
|
||||
await query(
|
||||
`UPDATE semi_auto_tasks
|
||||
SET credential_id = $2,
|
||||
connector_session_id = $3,
|
||||
huya_uid = $4,
|
||||
login_status = 'authenticated',
|
||||
binding_status = 'not_started',
|
||||
execution_status = 'waiting_operator',
|
||||
updated_at = NOW()
|
||||
WHERE id = $1`,
|
||||
[result.taskId, credentialId, `missing-session-${suffix}`, platformUid],
|
||||
)
|
||||
|
||||
const ticket = await createAdminBrowserSession(result.taskId, 'https://www.huya.com/', {
|
||||
userId: adminId,
|
||||
role: 'support',
|
||||
displayName: '集成测试客服',
|
||||
} as never)
|
||||
const restored = await query<{
|
||||
connector_session_id: string
|
||||
credential_session_restored: number
|
||||
}>(
|
||||
`SELECT task.connector_session_id,
|
||||
COUNT(event.id) FILTER (
|
||||
WHERE event.event_type = 'credential_session_restored'
|
||||
)::int AS credential_session_restored
|
||||
FROM semi_auto_tasks task
|
||||
LEFT JOIN semi_auto_task_events event ON event.task_id = task.id
|
||||
WHERE task.id = $1
|
||||
GROUP BY task.connector_session_id`,
|
||||
[result.taskId],
|
||||
)
|
||||
restoredSessionId = String(restored.rows[0]?.connector_session_id || '')
|
||||
assert.ok(restoredSessionId)
|
||||
assert.notEqual(restoredSessionId, `missing-session-${suffix}`)
|
||||
assert.equal(Number(restored.rows[0]?.credential_session_restored), 1)
|
||||
|
||||
const payload = await consumeSemiAutoInjectionTicket(ticket.ticket)
|
||||
assert.equal(
|
||||
payload.cookies.find((cookie) => cookie.name === 'udb_cred')?.value,
|
||||
`restored-${suffix}`,
|
||||
)
|
||||
} finally {
|
||||
if (restoredSessionId) {
|
||||
await huyaNativeConnector.revokeSession(restoredSessionId).catch(() => undefined)
|
||||
}
|
||||
if (orderId > 0) await query('DELETE FROM orders WHERE id = $1', [orderId])
|
||||
if (credentialId > 0) {
|
||||
await query('DELETE FROM semi_auto_credentials WHERE id = $1', [credentialId])
|
||||
}
|
||||
if (adminId > 0) {
|
||||
await query('DELETE FROM admin_users WHERE id = $1', [adminId])
|
||||
}
|
||||
if (configId > 0) {
|
||||
await query('DELETE FROM manual_fulfillment_configs WHERE id = $1', [configId])
|
||||
}
|
||||
delete process.env.ENABLE_DEV_MOCK
|
||||
await closeDb()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
test(
|
||||
'微博平台角色绑定事实收敛为等待客服处理',
|
||||
{ skip: !TEST_DATABASE_URL ? '未设置 SEMI_AUTO_TASK_TEST_DATABASE_URL' : false },
|
||||
|
||||
Reference in New Issue
Block a user