fix(api): проверить контекст GRE и завершить локальную приёмку этапа 9
This commit is contained in:
1 parent
a29ee31052
commit
919d0c4714
5 files changed
+28
-3
No files matched your search
@@ -2,14 +2,19 @@ import assert from "node:assert/strict"
|
||||
import Fastify from "fastify"
|
||||
import { validatorCompiler, serializerCompiler } from "@fastify/type-provider-zod"
|
||||
import filtersRoutes from "./filters.js"
|
||||
import greRoutes from "./gre.js"
|
||||
const app = Fastify()
|
||||
app.setValidatorCompiler(validatorCompiler)
|
||||
app.setSerializerCompiler(serializerCompiler)
|
||||
await app.register(filtersRoutes, { prefix: "/api" })
|
||||
for (const id of ["srv1", "0", "1abc", "-1"]) {
|
||||
await app.register(greRoutes, { prefix: "/api" })
|
||||
for (const id of ["srv1", "0", "1abc", "-1", ""]) {
|
||||
const response = await app.inject({ method: "GET", url: "/api/filters/gre-tunnels?serverId=" + encodeURIComponent(id) })
|
||||
assert.equal(response.statusCode, 400)
|
||||
assert.equal(response.json().error, "Некорректный serverId GRE-каталога")
|
||||
const direct = await app.inject({ method: "GET", url: "/api/gre/tunnels?serverId=" + encodeURIComponent(id) })
|
||||
assert.equal(direct.statusCode, 400)
|
||||
assert.equal(direct.json().error, "Некорректный serverId GRE")
|
||||
}
|
||||
await app.close()
|
||||
console.log("GRE invalid selected context: HTTP 400 without DB/RouterOS passed")
|
||||
@@ -103,6 +103,7 @@ const greRoutes: FastifyPluginAsyncZod = async (app) => {
|
||||
app.get("/gre/tunnels", async (req, reply) => {
|
||||
const q = req.query as { serverId?: string | number }
|
||||
const sid = parseDbServerId(q.serverId)
|
||||
if (q.serverId !== undefined && sid === null) return reply.status(400).send({ error: "Некорректный serverId GRE" })
|
||||
const result = await listGreTunnels({ serverId: sid !== null ? String(sid) : undefined })
|
||||
return reply.send(result)
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user