mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
test(api): fall back to raw path for unknown tool ids in adversarial negative tests
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
import { readFileSync } from "node:fs";
|
import { readFileSync } from "node:fs";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { apiToolPath } from "@snapotter/shared";
|
import { apiToolPath, TOOLS } from "@snapotter/shared";
|
||||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||||
import { buildTestApp, createMultipartPayload, loginAsAdmin, type TestApp } from "./test-server.js";
|
import { buildTestApp, createMultipartPayload, loginAsAdmin, type TestApp } from "./test-server.js";
|
||||||
|
|
||||||
@@ -41,6 +41,12 @@ afterAll(async () => {
|
|||||||
await testApp.cleanup();
|
await testApp.cleanup();
|
||||||
}, 10_000);
|
}, 10_000);
|
||||||
|
|
||||||
|
// Real catalog tools resolve to their section-prefixed path; unknown ids
|
||||||
|
// (used by the non-existent/injection negative tests below) fall back to a
|
||||||
|
// raw path that matches no route and 404s, instead of throwing in apiToolPath.
|
||||||
|
const toolUrl = (toolId: string): string =>
|
||||||
|
TOOLS.some((t) => t.id === toolId) ? apiToolPath(toolId) : `/api/v1/tools/${toolId}`;
|
||||||
|
|
||||||
/** Helper to POST a multipart payload to a tool endpoint. */
|
/** Helper to POST a multipart payload to a tool endpoint. */
|
||||||
function postTool(
|
function postTool(
|
||||||
toolId: string,
|
toolId: string,
|
||||||
@@ -54,7 +60,7 @@ function postTool(
|
|||||||
const { body, contentType } = createMultipartPayload(fields);
|
const { body, contentType } = createMultipartPayload(fields);
|
||||||
return app.inject({
|
return app.inject({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: apiToolPath(toolId),
|
url: toolUrl(toolId),
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": contentType,
|
"content-type": contentType,
|
||||||
authorization: `Bearer ${adminToken}`,
|
authorization: `Bearer ${adminToken}`,
|
||||||
@@ -76,7 +82,7 @@ function postBatch(
|
|||||||
const { body, contentType } = createMultipartPayload(fields);
|
const { body, contentType } = createMultipartPayload(fields);
|
||||||
return app.inject({
|
return app.inject({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: `${apiToolPath(toolId)}/batch`,
|
url: `${toolUrl(toolId)}/batch`,
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": contentType,
|
"content-type": contentType,
|
||||||
authorization: `Bearer ${adminToken}`,
|
authorization: `Bearer ${adminToken}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user