import { expect, test } from '@playwright/test'; for (const protocol of ['Redis', 'RabbitMQ']) test(`${protocol} 网关支持只读,并通过真实 POST 保存账号`, async ({ page }) => { let gatewayID = ''; await page.goto('/'); const session = await page.request.get('/api/v1/session'); const headers = { 'X-CSRF-Token': (await session.json()).csrfToken }; try { await page.getByRole('navigation').getByRole('button', { name: '网关服务', exact: true }).click(); await page.getByRole('button', { name: '新建网关', exact: true }).click(); const editor = page.getByRole('region', { name: '新建网关', exact: true }); await editor.getByRole('combobox', { name: '协议类型', exact: true }).click(); await page.getByRole('option', { name: protocol, exact: true }).click(); await editor.getByLabel('网关名称', { exact: true }).fill('Redis access mode regression'); if (protocol === 'RabbitMQ') await editor.getByLabel('管理监听端口(0 关闭)', { exact: true }).fill('15672'); await editor.getByRole('tab', { name: '账号', exact: true }).click(); if (protocol === 'Redis') await editor.getByRole('button', { name: '添加账号', exact: true }).click(); await editor.getByLabel('用户名', { exact: true }).fill('redis-client'); await editor.getByLabel('密码', { exact: true }).fill('isolated-redis-client-password'); const mode = editor.getByRole('combobox', { name: '账号访问模式', exact: true }); await mode.click(); await expect(page.getByRole('option', { name: '只读', exact: true })).toHaveCount(1); await expect(page.getByRole('option', { name: '全放行', exact: true })).toHaveCount(0); await page.getByRole('option', { name: '只读', exact: true }).click(); const saved = page.waitForResponse(response => response.url().endsWith('/api/v1/proxies') && response.request().method() === 'POST'); await editor.getByRole('button', { name: '保存配置', exact: true }).click(); const response = await saved; expect(response.status()).toBe(201); const stored = await response.json(); gatewayID = stored.config.id; if (protocol === 'RabbitMQ') expect(stored.config.managementListenPort).toBe(15672); expect(response.request().postDataJSON().gatewayAccounts[0].accessMode).toBe('readonly'); expect(stored.config.gatewayAccounts[0].accessMode).toBe('readonly'); await expect(editor).not.toBeVisible(); } finally { if (gatewayID) expect((await page.request.delete(`/api/v1/proxies/${gatewayID}`, { headers })).ok()).toBeTruthy(); } });