背景: - 落实 11-前端路由与目录规范:URL、导航、面包屑、页面目录一一对应; - 「平台」更名「管理中心」,模块 key 由 platform 改为 system; - 原导航模块 key 与 URL 首段不一致(script vs /scripts、asset vs /assets), 占位页按 URL 解析不到模块,出现「页面不存在」。 改动: - nav-config:模块 key 改为 URL 首段(scripts / assets / system),平台更名 管理中心,管理中心全部路径收敛到 /system/*;用户页为 /system/users; - routes / router:ROUTES 按模块分组;新增 /system/users、/system/users/new、 /system/users/:id;旧 /users* 与 /platform* 加前端重定向;/system 落到用户列表; - 页面目录迁移:pages/users → pages/system/users,pages/home → pages/dashboard, 懒加载与所有引用同步; - 面包屑、AppLayout、登录回跳、通用占位页(按路径 + 权限解析,无权限进 403) 与单测 / e2e 路径同步; - 顺带修复 /scripts/library、/assets/library 等占位页因模块 key 不一致导致的 404。 影响面: - 仅前端路由与目录;后端 /api/v1/users 等接口与权限点不变; - 旧书签 /users*、/platform* 由前端重定向兼容一个版本。 回滚方式: - 回滚本提交即恢复 /users 与 /platform/* 路由、原页面目录与导航命名。 验证证据: - pnpm --filter @lingxi/web lint / typecheck / test 通过(15 files / 55 tests); - pnpm build 通过; - 浏览器:登录后落在 /system/users,导航显示「管理中心」;/users → /system/users, /platform/roles → /system/roles;有权限的 /scripts/library、/assets/library 显示占位页,无权限显示 403; - A1 e2e 6/6 通过(真实 API + 浏览器)。
This commit is contained in:
1 parent
a1e28daec5
commit
f97f97b0cd
40 files changed
+159
-106
No files matched your search
@@ -3,25 +3,29 @@ import { describe, expect, it } from 'vitest';
|
||||
import { loginPath, ROUTES, sanitizeRedirect, userDetailPath } from './routes';
|
||||
|
||||
describe('路由常量与登录回跳', () => {
|
||||
it('用户路由按附录 C 使用 /users', () => {
|
||||
expect(ROUTES.users).toBe('/users');
|
||||
expect(ROUTES.userNew).toBe('/users/new');
|
||||
expect(userDetailPath('01HZZZZZZZZZZZZZZZZZZZZZZZ')).toBe('/users/01HZZZZZZZZZZZZZZZZZZZZZZZ');
|
||||
it('用户路由遵循 /system/users 模块化约定', () => {
|
||||
expect(ROUTES.system.users).toBe('/system/users');
|
||||
expect(ROUTES.system.userNew).toBe('/system/users/new');
|
||||
expect(userDetailPath('01HZZZZZZZZZZZZZZZZZZZZZZZ')).toBe(
|
||||
'/system/users/01HZZZZZZZZZZZZZZZZZZZZZZZ',
|
||||
);
|
||||
});
|
||||
|
||||
it('sanitizeRedirect 只接受站内路径', () => {
|
||||
expect(sanitizeRedirect('/users/new')).toBe('/users/new');
|
||||
expect(sanitizeRedirect(' /users?status=active ')).toBe('/users?status=active');
|
||||
expect(sanitizeRedirect('/system/users/new')).toBe('/system/users/new');
|
||||
expect(sanitizeRedirect(' /system/users?status=active ')).toBe('/system/users?status=active');
|
||||
expect(sanitizeRedirect('https://evil.example.com')).toBeNull();
|
||||
expect(sanitizeRedirect('//evil.example.com')).toBeNull();
|
||||
expect(sanitizeRedirect('javascript:alert(1)')).toBeNull();
|
||||
expect(sanitizeRedirect('/login?redirect=/users')).toBeNull();
|
||||
expect(sanitizeRedirect('/login?redirect=/system/users')).toBeNull();
|
||||
expect(sanitizeRedirect(null)).toBeNull();
|
||||
});
|
||||
|
||||
it('loginPath 编码 redirect 参数', () => {
|
||||
expect(loginPath()).toBe('/login');
|
||||
expect(loginPath('/users?status=active')).toBe('/login?redirect=%2Fusers%3Fstatus%3Dactive');
|
||||
expect(loginPath('/system/users?status=active')).toBe(
|
||||
'/login?redirect=%2Fsystem%2Fusers%3Fstatus%3Dactive',
|
||||
);
|
||||
expect(loginPath('https://evil.example.com')).toBe('/login');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user