82 lines
2.8 KiB
TypeScript
82 lines
2.8 KiB
TypeScript
|
|
import { test, expect } from '@playwright/test';
|
|||
|
|
|
|||
|
|
const moicenUnionid = process.env.MOICEN_E2E_UNIONID?.trim();
|
|||
|
|
const expectedRealName = process.env.MOICEN_E2E_EXPECTED_REAL_NAME?.trim();
|
|||
|
|
|
|||
|
|
test.describe('已登录用户与串号防护', () => {
|
|||
|
|
test.skip(!moicenUnionid, '需要 MOICEN_E2E_UNIONID(Secret 或 .env.e2e)');
|
|||
|
|
|
|||
|
|
test('login2_with_unionid 后不应停留在未登录占位,应出现身份或工作台', async ({
|
|||
|
|
page,
|
|||
|
|
}) => {
|
|||
|
|
const q = new URLSearchParams({
|
|||
|
|
unionid: moicenUnionid!,
|
|||
|
|
status: '2',
|
|||
|
|
});
|
|||
|
|
await page.goto(`/?${q.toString()}`, {
|
|||
|
|
waitUntil: 'domcontentloaded',
|
|||
|
|
timeout: 60_000,
|
|||
|
|
});
|
|||
|
|
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
|
|||
|
|
await expect(
|
|||
|
|
page.getByText('请返回微信小程序完成登录')
|
|||
|
|
).not.toBeVisible({ timeout: 90_000 });
|
|||
|
|
await expect(
|
|||
|
|
page.getByText(/请选择您的登录身份|欢迎回来|进入工作台/)
|
|||
|
|
).toBeVisible({ timeout: 90_000 });
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
test('已登录后 URL 中异主 unionid 应被剥离(不串号)', async ({ page }) => {
|
|||
|
|
const q = new URLSearchParams({
|
|||
|
|
unionid: moicenUnionid!,
|
|||
|
|
status: '2',
|
|||
|
|
});
|
|||
|
|
await page.goto(`/?${q.toString()}`, {
|
|||
|
|
waitUntil: 'domcontentloaded',
|
|||
|
|
timeout: 60_000,
|
|||
|
|
});
|
|||
|
|
await expect(
|
|||
|
|
page.getByText(/请选择您的登录身份|欢迎回来|进入工作台/)
|
|||
|
|
).toBeVisible({ timeout: 90_000 });
|
|||
|
|
|
|||
|
|
const poisonUnionid = 'e2eStrangerUnionidNotCurrentUser001';
|
|||
|
|
const pathBefore = new URL(page.url()).pathname || '/';
|
|||
|
|
await page.goto(
|
|||
|
|
`${pathBefore}?unionid=${encodeURIComponent(poisonUnionid)}&status=2`,
|
|||
|
|
{ waitUntil: 'domcontentloaded', timeout: 60_000 }
|
|||
|
|
);
|
|||
|
|
await page.waitForURL(
|
|||
|
|
(u) => !u.toString().includes(poisonUnionid),
|
|||
|
|
{ timeout: 45_000 }
|
|||
|
|
);
|
|||
|
|
expect(page.url()).not.toContain(poisonUnionid);
|
|||
|
|
await expect(
|
|||
|
|
page.getByText('请返回微信小程序完成登录')
|
|||
|
|
).not.toBeVisible();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
test('可选:工作台「欢迎回来」展示配置的真实姓名(自己的数据)', async ({
|
|||
|
|
page,
|
|||
|
|
}) => {
|
|||
|
|
test.skip(
|
|||
|
|
!expectedRealName,
|
|||
|
|
'未设置 MOICEN_E2E_EXPECTED_REAL_NAME 时跳过(与库中 real_name 一致,如 阿难)'
|
|||
|
|
);
|
|||
|
|
const q = new URLSearchParams({
|
|||
|
|
unionid: moicenUnionid!,
|
|||
|
|
status: '2',
|
|||
|
|
});
|
|||
|
|
await page.goto(`/?${q.toString()}`, {
|
|||
|
|
waitUntil: 'domcontentloaded',
|
|||
|
|
timeout: 60_000,
|
|||
|
|
});
|
|||
|
|
if (await page.getByText('请选择您的登录身份').isVisible().catch(() => false)) {
|
|||
|
|
await page.locator('.van-grid-item').first().click();
|
|||
|
|
}
|
|||
|
|
await expect(page.getByText('欢迎回来')).toBeVisible({ timeout: 120_000 });
|
|||
|
|
await expect(page.getByText(expectedRealName!)).toBeVisible({
|
|||
|
|
timeout: 30_000,
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
});
|