from __future__ import annotations import re from playwright.sync_api import Page, expect from tests.e2e.helpers import expect_flash, expect_path, expect_sidebar_link, login, logout def test_auth_boundaries_for_login_logout_redirect_and_forbidden_access( page: Page, base_url: str, admin_credentials: dict[str, str], entry_credentials: dict[str, str], ) -> None: page.goto(f"{base_url}/auth/login") page.get_by_label("用户名").fill(admin_credentials["username"]) page.get_by_label("密码").fill("WrongPass123!") page.get_by_role("button", name="登录").click() expect(page).to_have_url(f"{base_url}/auth/login") expect_flash(page, "用户名或密码错误。") page.goto(f"{base_url}/admin/accounts") expect(page).to_have_url(re.compile(r".*/auth/login\?next=/admin/accounts$")) expect_flash(page, "请先登录。") login( page, base_url, username=entry_credentials["username"], password=entry_credentials["password"], expected_path="/quick-entry/", ) expect(page.get_by_role("heading", name="快速录入")).to_be_visible() expect_sidebar_link(page, "快速录入") expect(page.get_by_role("link", name="管理首页")).to_have_count(0) expect(page.get_by_label("包含女方")).not_to_be_checked() page.goto(f"{base_url}/") expect_path(page, base_url, "/quick-entry/") expect_flash(page, "您没有权限访问该页面。") logout(page, base_url) def test_quick_editor_is_limited_to_quick_entry( page: Page, base_url: str, quick_editor_credentials: dict[str, str], ) -> None: login( page, base_url, username=quick_editor_credentials["username"], password=quick_editor_credentials["password"], expected_path="/quick-entry/", ) expect(page.get_by_role("heading", name="快速录入")).to_be_visible() expect_sidebar_link(page, "快速录入") expect(page.get_by_role("link", name="管理首页")).to_have_count(0) page.goto(f"{base_url}/") expect_path(page, base_url, "/quick-entry/") expect_flash(page, "您没有权限访问该页面。")