后端补上流式透传和两个写操作,给后面几个页面铺路
原以为流量和日志要写 WebSocket 转发,实测不用:内核在没有 WebSocket 升级时把
traffic、memory、logs 退化成分块的 HTTP 流,一行一个 JSON(server.go:380-383)。
现有的透传本来就能流式传,唯一的问题是那个 15 秒超时会每隔一会儿掐断一次,
给这三个路径去掉超时即可。
写操作照旧是白名单,逐条列出:断开连接(DELETE /connections 和 /connections/{id})、
刷新订阅(PUT /providers/proxies/{名字})。两者都只改内核运行状态、不碰配置文件,
所以不走落盘那条保护链路。方法和路径都要匹配才放行,测试里有反例。
This commit is contained in:
@@ -81,6 +81,35 @@ describe('内核接口的透传白名单', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('写操作的白名单', () => {
|
||||
const write = (method: string, path: string) =>
|
||||
handle(
|
||||
new Request(`http://127.0.0.1:7580/api/kernel${path}`, {
|
||||
method,
|
||||
headers: { Authorization: `Bearer ${TOKEN}` },
|
||||
}),
|
||||
)
|
||||
|
||||
it('放行断开连接和刷新订阅', async () => {
|
||||
expect((await write('DELETE', '/connections')).status).not.toBe(403)
|
||||
expect((await write('DELETE', '/connections/abc-123')).status).not.toBe(403)
|
||||
expect((await write('PUT', '/providers/proxies/subs')).status).not.toBe(403)
|
||||
})
|
||||
|
||||
it('挡住没列出来的写操作', async () => {
|
||||
// 重启内核、切换配置这类动作不该从这里走
|
||||
expect((await write('PUT', '/configs')).status).toBe(403)
|
||||
expect((await write('DELETE', '/cache/fakeip/flush')).status).toBe(403)
|
||||
expect((await write('PUT', '/providers/proxies/subs/healthcheck')).status).toBe(403)
|
||||
})
|
||||
|
||||
it('方法对不上也挡住', async () => {
|
||||
// 断开连接是 DELETE,刷新订阅是 PUT,反过来都不行
|
||||
expect((await write('PUT', '/connections')).status).toBe(403)
|
||||
expect((await write('DELETE', '/providers/proxies/subs')).status).toBe(403)
|
||||
})
|
||||
})
|
||||
|
||||
describe('其它', () => {
|
||||
it('不存在的接口回 404 并带上说明', async () => {
|
||||
const res = await get('/api/nope')
|
||||
|
||||
Reference in New Issue
Block a user