mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-08-17 11:37:06 +08:00
feat: 完善首次连接账号身份展示
首次连接前读取当前账号昵称和头像 从账号目录安全推导其他账号 wxid 避免账号串号
This commit is contained in:
@@ -69,6 +69,53 @@ function renderPage(
|
||||
}
|
||||
|
||||
describe('DatabaseConnectionPage', () => {
|
||||
it('renders a discovered nickname and avatar before connection', () => {
|
||||
const { container } = renderPage({
|
||||
mode: 'automatic',
|
||||
accounts: [
|
||||
{
|
||||
id: 'account-a',
|
||||
accountRoot: 'C:\\fixture\\account-a',
|
||||
directoryName: 'account-a',
|
||||
nickname: '首次识别账号',
|
||||
wxid: 'fixture_account',
|
||||
avatar: 'https://wx.qlogo.cn/fixture/avatar',
|
||||
hasSavedDbKey: false,
|
||||
loginStatus: 'unknown',
|
||||
selectedByInput: true
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
expect(screen.getByText('首次识别账号')).toBeVisible()
|
||||
expect(screen.getByText('fixture_account')).toBeVisible()
|
||||
expect(container.querySelector('.database-account-avatar img')).toHaveAttribute(
|
||||
'src',
|
||||
'https://wx.qlogo.cn/fixture/avatar'
|
||||
)
|
||||
})
|
||||
|
||||
it('shows a directory-derived wxid without pretending profile data is available', () => {
|
||||
renderPage({
|
||||
mode: 'automatic',
|
||||
accounts: [
|
||||
{
|
||||
id: 'account-b',
|
||||
accountRoot: 'C:\\fixture\\wxid_fixture_b_ab12',
|
||||
directoryName: 'wxid_fixture_b_ab12',
|
||||
wxid: 'wxid_fixture',
|
||||
hasSavedDbKey: false,
|
||||
loginStatus: 'other',
|
||||
selectedByInput: false
|
||||
}
|
||||
],
|
||||
selectedAccountId: ''
|
||||
})
|
||||
|
||||
expect(screen.getByText('微信账号 wxid_fixture')).toBeVisible()
|
||||
expect(screen.getByText('昵称和头像需连接此账号后读取')).toBeVisible()
|
||||
})
|
||||
|
||||
it('keeps connect disabled until a valid 64-character key is supplied', () => {
|
||||
const { rerender, props } = renderPage()
|
||||
expect(screen.getByRole('button', { name: '连接数据库' })).toBeDisabled()
|
||||
|
||||
@@ -12,6 +12,13 @@ vi.mock('electron', () => ({
|
||||
}))
|
||||
|
||||
import { discoverAccounts } from '../../src/main/services/account-discovery'
|
||||
import {
|
||||
accountDirectoryBelongsToIdentity,
|
||||
deriveAccountWxid
|
||||
} from '../../src/main/services/local-account-identity'
|
||||
|
||||
const ENCRYPTED_PROFILE_FIXTURE =
|
||||
'AQAAAO94jcgf4UG6tCOnxpkapWihufN03upWNEXBfttmtsNHGfPwTv6d4rHJ5BQ9fTQWVc8QuHn1cCk1TmQ4eYW4iHKHEGgyGn/3mcpxlJIxlkt/y7IFifofGw8UShRYcOa8j59W2EML986dq+OWo/cN19iq3PHiMhbDLugGiWYdeDMAIPI/'
|
||||
|
||||
describe('account discovery', () => {
|
||||
let root: string
|
||||
@@ -66,4 +73,48 @@ describe('account discovery', () => {
|
||||
expect(result.preselectedAccountId).toBe(result.accounts[0].id)
|
||||
expect(result.accounts[0].selectedByInput).toBe(true)
|
||||
})
|
||||
|
||||
it('adds the local profile only to its exact account directory before unlock', async () => {
|
||||
const accountRoot = path.join(root, 'fixture_account_ab12')
|
||||
await fs.ensureDir(path.join(accountRoot, 'db_storage'))
|
||||
const profileFile = path.join(root, 'all_users', 'config', 'global_config')
|
||||
await fs.ensureDir(path.dirname(profileFile))
|
||||
await fs.writeFile(profileFile, Buffer.from(ENCRYPTED_PROFILE_FIXTURE, 'base64'))
|
||||
|
||||
const result = await discoverAccounts(root, keyStore as never)
|
||||
|
||||
expect(
|
||||
result.accounts.find((account) => account.directoryName === 'fixture_account_ab12')
|
||||
).toMatchObject({
|
||||
wxid: 'fixture_account',
|
||||
nickname: '测试账号',
|
||||
avatar: 'https://wx.qlogo.cn/fixture/avatar'
|
||||
})
|
||||
expect(result.accounts.find((account) => account.directoryName === 'account-a')).toMatchObject({
|
||||
wxid: undefined,
|
||||
nickname: undefined,
|
||||
avatar: undefined
|
||||
})
|
||||
|
||||
const directResult = await discoverAccounts(accountRoot, keyStore as never)
|
||||
expect(directResult.accounts[0]).toMatchObject({
|
||||
wxid: 'fixture_account',
|
||||
nickname: '测试账号'
|
||||
})
|
||||
})
|
||||
|
||||
it('uses strict account-directory suffix matching', () => {
|
||||
expect(accountDirectoryBelongsToIdentity('fixture_account', 'fixture_account')).toBe(true)
|
||||
expect(accountDirectoryBelongsToIdentity('fixture_account_ab12', 'fixture_account')).toBe(true)
|
||||
expect(accountDirectoryBelongsToIdentity('fixture_account_z9q2', 'fixture_account')).toBe(true)
|
||||
expect(accountDirectoryBelongsToIdentity('fixture_account_other', 'fixture_account')).toBe(
|
||||
false
|
||||
)
|
||||
expect(accountDirectoryBelongsToIdentity('fixture_account2_ab12', 'fixture_account')).toBe(
|
||||
false
|
||||
)
|
||||
expect(deriveAccountWxid('wxid_iuq1a00d79c212_00fa')).toBe('wxid_iuq1a00d79c212')
|
||||
expect(deriveAccountWxid('a969409112_d784')).toBe('a969409112')
|
||||
expect(deriveAccountWxid('account-a')).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user