mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-01 03:08:43 +08:00
✨ feat(connection): 支持生产连接多项保护策略
- 新增数据编辑、结构编辑、脚本执行和数据导入四类连接级保护配置 - 升级生产连接保护弹窗为多选卡片,并修复选项对齐与勾选态显示 - 按保护类型收口 QueryEditor、DataGrid、表设计、导入与同步目标入口 - 后端统一拦截 SQL 或 Mongo 写操作、结果编辑、结构变更和导入写入 - AI 本地工具与 RPC 执行链路透传连接保护配置并复用后端守卫 - 补充多语言文案、定向测试与需求追踪记录
This commit is contained in:
57
frontend/src/utils/connectionReadOnly.test.ts
Normal file
57
frontend/src/utils/connectionReadOnly.test.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
findConnectionMutatingStatements,
|
||||
isConnectionDataEditRestricted,
|
||||
isConnectionDataImportRestricted,
|
||||
isConnectionScriptExecutionRestricted,
|
||||
isConnectionStructureEditRestricted,
|
||||
resolveConnectionProtectionConfig,
|
||||
} from './connectionReadOnly';
|
||||
|
||||
describe('connectionReadOnly', () => {
|
||||
it('maps legacy readOnly connections to the full production protection set', () => {
|
||||
expect(resolveConnectionProtectionConfig({
|
||||
type: 'postgres',
|
||||
readOnly: true,
|
||||
})).toEqual({
|
||||
restrictDataEdit: true,
|
||||
restrictStructureEdit: true,
|
||||
restrictScriptExecution: true,
|
||||
restrictDataImport: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps partial protection flags isolated from each other', () => {
|
||||
const config = {
|
||||
type: 'postgres',
|
||||
protection: {
|
||||
restrictDataEdit: true,
|
||||
restrictDataImport: true,
|
||||
},
|
||||
};
|
||||
|
||||
expect(isConnectionDataEditRestricted(config)).toBe(true);
|
||||
expect(isConnectionDataImportRestricted(config)).toBe(true);
|
||||
expect(isConnectionStructureEditRestricted(config)).toBe(false);
|
||||
expect(isConnectionScriptExecutionRestricted(config)).toBe(false);
|
||||
});
|
||||
|
||||
it('only blocks mutating SQL when script execution protection is enabled', () => {
|
||||
expect(findConnectionMutatingStatements({
|
||||
type: 'postgres',
|
||||
protection: {
|
||||
restrictScriptExecution: true,
|
||||
},
|
||||
}, "SELECT * FROM users; UPDATE users SET name = 'next';")).toEqual([
|
||||
"UPDATE users SET name = 'next'",
|
||||
]);
|
||||
|
||||
expect(findConnectionMutatingStatements({
|
||||
type: 'postgres',
|
||||
protection: {
|
||||
restrictDataEdit: true,
|
||||
},
|
||||
}, "UPDATE users SET name = 'next';")).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user