import type { ErrorEvent } from "@sentry/node"; import { scrubRequest } from "./sentry"; describe("scrubRequest", () => { it("should filter sensitive query parameters and headers", () => { const event: ErrorEvent = { type: undefined, request: { url: "https://app.getoutline.com/auth/google.callback?code=secret&state=jwt&iss=google&access_token=abc&sig=xyz", query_string: "code=secret&state=jwt&iss=google&access_token=abc&sig=xyz", headers: { authorization: "Bearer x", "user-agent": "test" }, }, }; scrubRequest(event); const filtered = "code=%5BFiltered%5D&state=%5BFiltered%5D&iss=google&access_token=%5BFiltered%5D&sig=%5BFiltered%5D"; expect(event.request).toEqual({ url: `https://app.getoutline.com/auth/google.callback?${filtered}`, query_string: filtered, headers: { "user-agent": "test" }, }); }); it("should leave requests without a query string unchanged", () => { const event: ErrorEvent = { type: undefined, request: { url: "https://app.getoutline.com/api/documents.info" }, }; scrubRequest(event); expect(event.request).toEqual({ url: "https://app.getoutline.com/api/documents.info", }); }); });