feat(中间层): 实现 Lua 插件驱动的安全代理
新增固定上游的 HTTP/SSE 转发、Lua 插件生命周期和请求级进程隔离。 实现逐插件域名与内网白名单、DNS 地址固定、超时取消和受控错误收尾。 提供三个 Lua 示例插件、配置与开发文档、Docker 和 APISIX 部署示例。 通过 65 项测试及静态检查,验证真实 TCP 流式转发、取消、资源限制和 Windows 命令行启动。
This commit is contained in:
commit
d0bb045134
28 files changed
+2764
No files matched your search
@@ -0,0 +1,45 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from middleware.config import NetworkRule, Settings, load_settings
|
||||
|
||||
|
||||
def test_configuration_and_paths():
|
||||
settings = load_settings(Path(__file__).parents[1] / "config.yaml")
|
||||
assert settings.plugins[0].file.is_absolute()
|
||||
assert settings.limits.max_sessions == 4
|
||||
|
||||
|
||||
def test_duplicate_ids_and_missing_file(tmp_path):
|
||||
path = tmp_path / "config.yaml"
|
||||
path.write_text(
|
||||
"upstream: http://agent:8000\nplugins:\n - id: x\n file: absent.lua\n", encoding="utf-8"
|
||||
)
|
||||
with pytest.raises(ValueError):
|
||||
load_settings(path)
|
||||
with pytest.raises(ValidationError):
|
||||
Settings(
|
||||
upstream="http://agent",
|
||||
plugins=[
|
||||
{"id": "x", "file": "a.lua"},
|
||||
{"id": "x", "file": "b.lua"},
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("domain", ["*", "bad/example.com", "foo..com", "127.0.0.1", "*.com*"])
|
||||
def test_bad_domains(domain):
|
||||
with pytest.raises(ValueError):
|
||||
NetworkRule(domain=domain)
|
||||
|
||||
|
||||
def test_wildcard_and_idna():
|
||||
rule = NetworkRule(domain="*.EXAMPLE.com.")
|
||||
assert rule.matches("a.example.com", "https", 443)
|
||||
assert rule.matches("a.b.example.com", "https", 443)
|
||||
assert not rule.matches("example.com", "https", 443)
|
||||
assert not rule.matches("badexample.com", "https", 443)
|
||||
assert not rule.matches("a.example.com", "http", 443)
|
||||
assert NetworkRule(domain="例子.测试").domain == "xn--fsqu00a.xn--0zwm56d"
|
||||
Reference in new issue
Block a user