fix: 修复分享链接路由与登录回跳
- 统一生成包含部署基路径和 Hash 路由的知识库、工作流分享地址 - 未登录访问分享页时保留目标地址,并在登录成功后自动回跳 - 限定分享密钥作用域并补充失效、加载失败及回归测试
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { resolveLoginRedirectPath } from '#/utils/login-redirect';
|
||||
|
||||
describe('login redirect', () => {
|
||||
it('restores an encoded knowledge share route', () => {
|
||||
expect(
|
||||
resolveLoginRedirectPath(
|
||||
encodeURIComponent('/share/knowledge?shareKey=knowledge-key'),
|
||||
),
|
||||
).toBe('/share/knowledge?shareKey=knowledge-key');
|
||||
});
|
||||
|
||||
it('accepts an unencoded workflow share route', () => {
|
||||
expect(
|
||||
resolveLoginRedirectPath('/ai/workflow/design?shareKey=workflow-key'),
|
||||
).toBe('/ai/workflow/design?shareKey=workflow-key');
|
||||
});
|
||||
|
||||
it('uses the first valid query value', () => {
|
||||
expect(
|
||||
resolveLoginRedirectPath([
|
||||
undefined,
|
||||
encodeURIComponent('/share/knowledge?shareKey=knowledge-key'),
|
||||
]),
|
||||
).toBe('/share/knowledge?shareKey=knowledge-key');
|
||||
});
|
||||
|
||||
it('rejects external and malformed redirects', () => {
|
||||
expect(resolveLoginRedirectPath('https://example.test')).toBeNull();
|
||||
expect(resolveLoginRedirectPath('//example.test/path')).toBeNull();
|
||||
expect(resolveLoginRedirectPath('%E0%A4%A')).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user