Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

More mock

Fang-Pen Lin146524ac2d8a
diff --git a/backend/src/server/routes/v1/bdd-nock-router.ts b/backend/src/server/routes/v1/bdd-nock-router.ts
index 5237ce6aeb..7b492df9fc 100644
--- a/backend/src/server/routes/v1/bdd-nock-router.ts
+++ b/backend/src/server/routes/v1/bdd-nock-router.ts
@@ -7,6 +7,15 @@ import { AuthMode } from "@app/services/auth/auth-type";
import nock, { Definition } from "nock";
export const registerBddNockRouter = async (server: FastifyZodProvider) => {
+ const checkIfBddNockApiEnabled = () => {
+ const appCfg = getConfig();
+ // Note: Please note that this API is only available in development mode and only for BDD tests.
+ // This endpoint should NEVER BE ENABLED IN PRODUCTION!
+ if (appCfg.NODE_ENV !== "development" || !appCfg.isBddNockApiEnabled) {
+ throw new ForbiddenRequestError({ message: "BDD Nock API is not enabled" });
+ }
+ };
+
server.route({
method: "POST",
url: "/define",
@@ -18,16 +27,43 @@ export const registerBddNockRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
- const appCfg = getConfig();
- // Note: Please note that this API is only available in development mode and only for BDD tests.
- // This endpoint should NEVER BE ENABLED IN PRODUCTION!
- if (appCfg.NODE_ENV !== "development" || !appCfg.isBddNockApiEnabled) {
- throw new ForbiddenRequestError({ message: "BDD Nock API is not enabled" });
- }
+ checkIfBddNockApiEnabled();
const { body } = req;
const { definition } = body;
nock.define(definition as unknown as Definition[]);
return { status: "ok" };
}
});
+
+ server.route({
+ method: "POST",
+ url: "/restore",
+ schema: {
+ response: {
+ 200: z.object({ status: z.string() })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.JWT]),
+ handler: async (req) => {
+ checkIfBddNockApiEnabled();
+ nock.restore();
+ return { status: "ok" };
+ }
+ });
+
+ server.route({
+ method: "POST",
+ url: "/clear-all",
+ schema: {
+ response: {
+ 200: z.object({ status: z.string() })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.JWT]),
+ handler: async (req) => {
+ checkIfBddNockApiEnabled();
+ nock.cleanAll();
+ return { status: "ok" };
+ }
+ });
};