mirror of
https://github.com/insistence/RuoYi-Vue3-FastAPI.git
synced 2026-09-26 14:23:49 +00:00
* feat: 初始化插件系统 * refactor: 收口插件系统运行时重构 * perf: 优化插件系统类型提示 * fix&perf: 修复和优化插件系统 * fix: 修复gitignore规则误忽略插件文件的问题 * fix: 修复运行时插件根路径算错的问题 * fix: 加强插件发现和路由注册的防护措施 * revert: 回滚定时任务白名单 * fix: 移除未使用的应用路由注册探测 * revert: 恢复部分代码 * perf: 优化插件系统 * docs: 新增插件开发文档 * perf: 优化插件管理模块 * perf: 提升插件系统核心能力 * refactor: 重构生命周期 step runner * fix: 修复lint错误 * test: 清理测试用例 * test: 调整测试目录名称 * fix: 修复前后端目录硬编码的问题 * fix: 修复插件系统安全性缺口 * refactor: 重新设计插件生命周期 Migration 事务与回滚 * perf: 优化插件系统边界问题 * refactor: 重构当前插件系统的依赖体系设计 * perf: 优化代码 * perf: 优化代码 * fix: 修复代码合并问题 * fix: 修复bug * perf: 优化代码 * perf&fix: 优化代码和修复bug * docs: 优化文档格式 * feat: 适配Vue2版本 * docs: 更新README文档 * fix: 修复ruff lint错误 * chore: 更新后端依赖文件
83 lines
2.4 KiB
Python
83 lines
2.4 KiB
Python
import importlib
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
BACKEND_DIR = Path(__file__).resolve().parents[3]
|
|
|
|
sys.path.insert(0, str(BACKEND_DIR))
|
|
cli_guards = importlib.import_module('cli.guards')
|
|
cli_guards = importlib.reload(cli_guards)
|
|
|
|
DEFAULT_DANGEROUS_COMMAND_RULES = cli_guards.DEFAULT_DANGEROUS_COMMAND_RULES
|
|
DEFAULT_DANGEROUS_COMMAND_RULE_REGISTRY = cli_guards.DEFAULT_DANGEROUS_COMMAND_RULE_REGISTRY
|
|
|
|
|
|
def test_dangerous_command_rules_cover_expected_commands() -> None:
|
|
"""
|
|
校验危险命令规则表已覆盖当前设计文档中约定的命令范围。
|
|
|
|
:return: None
|
|
"""
|
|
assert set(DEFAULT_DANGEROUS_COMMAND_RULES) == {
|
|
'cache clear',
|
|
'cache warmup',
|
|
'db upgrade',
|
|
'db init',
|
|
'db downgrade',
|
|
'db revision',
|
|
'config set',
|
|
'config sync-cache',
|
|
'crypto rotate',
|
|
'job run-once',
|
|
'job pause',
|
|
'job resume',
|
|
'job sync',
|
|
'gen import-table',
|
|
'gen create-table',
|
|
'gen export',
|
|
'gen sync-db',
|
|
'plugin install',
|
|
'plugin install-deps',
|
|
'plugin upgrade',
|
|
'plugin batch',
|
|
'plugin enable',
|
|
'plugin disable',
|
|
'plugin config set',
|
|
'plugin config import',
|
|
'plugin config export',
|
|
'plugin uninstall',
|
|
'plugin purge',
|
|
'plugin mark-success',
|
|
'plugin mark-failed',
|
|
}
|
|
|
|
|
|
def test_dangerous_command_rules_expose_risk_level_and_dry_run_metadata() -> None:
|
|
"""
|
|
校验危险命令规则能够提供风险级别和 dry-run 能力元数据。
|
|
|
|
:return: None
|
|
"""
|
|
db_upgrade_rule = DEFAULT_DANGEROUS_COMMAND_RULE_REGISTRY.get_rule('db upgrade')
|
|
cache_warmup_rule = DEFAULT_DANGEROUS_COMMAND_RULE_REGISTRY.get_rule('cache warmup')
|
|
|
|
assert db_upgrade_rule is not None
|
|
assert db_upgrade_rule.risk_level == 'high'
|
|
assert db_upgrade_rule.supports_dry_run is True
|
|
|
|
assert cache_warmup_rule is not None
|
|
assert cache_warmup_rule.risk_level == 'normal'
|
|
assert cache_warmup_rule.supports_dry_run is False
|
|
|
|
|
|
def test_require_dangerous_command_rule_rejects_unknown_command() -> None:
|
|
"""
|
|
校验未注册的危险命令名称会被显式拒绝。
|
|
|
|
:return: None
|
|
"""
|
|
with pytest.raises(ValueError, match='危险命令未注册保护规则'):
|
|
DEFAULT_DANGEROUS_COMMAND_RULE_REGISTRY.require_rule('unknown dangerous command')
|