fix(api): проверять параметры и подтверждать результат MTU

This commit is contained in:
Denozordec committed 2026-10-01 08:49:54 +07:00
1 parent 68ccc49135
commit 33185fddae
6 files changed
+72 -45

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@ const app=Fastify();app.setValidatorCompiler(validatorCompiler);app.setSerialize
let lookups=0
await app.register(createExecRoutes({getServer:async()=>{lookups++;return undefined},createClient:()=>{throw new Error("unused")}}),{prefix:"/api"})
await app.register(createProbeRoutes({getServer:async()=>{lookups++;return undefined},createClient:()=>{throw new Error("unused")}}),{prefix:"/api"})
const send=(token?:string,url="/api/servers/1/exec")=>app.inject({method:"POST",url,payload:{command:"interface print"},headers:token?{authorization:"Bearer "+token}:{}})
const send=(token?:string,url="/api/servers/1/exec")=>app.inject({method:"POST",url,payload:url.endsWith("/probes/run")?{tool:"ping",target:"192.0.2.2"}:{command:"interface print"},headers:token?{authorization:"Bearer "+token}:{}})
assert.equal((await send()).statusCode,401);assert.equal(lookups,0)
for(const url of ["/api/servers/1/exec","/api/servers/1/probes/run"])for(const permission of ["mm:servers:read","mm:network:write","mm:servers:write","mm:servers:admin"]){
const token=await new SignJWT({sub:"test",apps:["mm"],permissions:[permission]}).setProtectedHeader({alg:"HS256"}).setIssuer("https://auth.test.local").setExpirationTime("1h").sign(new TextEncoder().encode("terminal-test-secret"))