"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const runQuirrel_1 = require("./runQuirrel");
const fastify_1 = __importDefault(require("fastify"));
const supertest_1 = __importDefault(require("supertest"));
const delay_1 = __importDefault(require("delay"));
const util_1 = require("../../client/test/util");
describe("SSRF Prevention", () => {
    let server;
    let teardown;
    let lastRequestBody = null;
    beforeAll(async () => {
        server = (0, fastify_1.default)();
        server.post("/database/drop", (request, reply) => {
            lastRequestBody = request.body;
            reply.status(200).send("OK");
        });
        await server.listen({
            port: 0,
        });
    });
    afterAll(async () => {
        await server.close();
        await teardown();
    });
    function testWithSSR(mode) {
        test("ssrf prevention " + mode, async () => {
            const res = await (0, runQuirrel_1.run)("Mock", {
                enableSSRFPrevention: mode === "enabled",
            });
            const quirrel = res.server;
            teardown = res.teardown;
            await (0, supertest_1.default)(quirrel)
                .post("/queues/" +
                encodeURIComponent((0, util_1.getAddress)(server.server) + "/database/drop"))
                .send({ body: "dropthebase" })
                .expect(201);
            await (0, delay_1.default)(500);
            if (mode === "enabled") {
                expect(lastRequestBody).toBeNull();
            }
            else {
                expect(lastRequestBody).toEqual("dropthebase");
            }
        });
    }
    testWithSSR("enabled");
    testWithSSR("disabled");
});
//# sourceMappingURL=ssrf-prevention.test.js.map