import { describe, expect, test } from "vitest"; import { feedbackRedactionMarkers, redactFeedbackText } from "./FeedbackRedaction.server"; describe("redactFeedbackText", () => { test("trims and preserves benign feedback text", () => { expect(redactFeedbackText(" The export button is hard to find on mobile. ")).toBe("The export button is hard to find on mobile."); expect(redactFeedbackText(null)).toBe(""); expect(redactFeedbackText(undefined)).toBe(""); }); test("redacts email addresses", () => { const redacted = redactFeedbackText("Please contact alex.user+demo@example.com about this bug."); expect(redacted).toContain(feedbackRedactionMarkers.email); expect(redacted).not.toContain("alex.user+demo@example.com"); }); test("redacts bearer tokens and api-key style values", () => { const bearer = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"; const apiKey = "api_key=sk_live_1234567890abcdef"; const token = "accessToken: app-token-1234567890"; const redacted = redactFeedbackText(`${bearer} ${apiKey} ${token}`); expect(redacted).toContain(`Bearer ${feedbackRedactionMarkers.token}`); expect(redacted).toContain(`api_key=${feedbackRedactionMarkers.token}`); expect(redacted).toContain(`accessToken: ${feedbackRedactionMarkers.token}`); expect(redacted).not.toContain("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"); expect(redacted).not.toContain("sk_live_1234567890abcdef"); expect(redacted).not.toContain("app-token-1234567890"); }); test("redacts sensitive query parameter values", () => { const url = "https://app.example.com/feedback?token=raw-token-123&next=/home&client_secret=super-secret-value"; const redacted = redactFeedbackText(url); expect(redacted).toContain(`token=${feedbackRedactionMarkers.token}`); expect(redacted).toContain(`client_secret=${feedbackRedactionMarkers.token}`); expect(redacted).toContain("next=/home"); expect(redacted).not.toContain("raw-token-123"); expect(redacted).not.toContain("super-secret-value"); }); test("redacts long hex and base64-like secrets", () => { const hexSecret = "0123456789abcdef0123456789abcdef01234567"; const base64Secret = "AbCdEfGhIjKlMnOpQrStUvWxYz1234567890+/=="; const redacted = redactFeedbackText(`hex ${hexSecret} base64 ${base64Secret}`); expect(redacted).toContain(feedbackRedactionMarkers.secret); expect(redacted).not.toContain(hexSecret); expect(redacted).not.toContain(base64Secret); }); test("redacts mixed sensitive feedback while preserving context", () => { const email = "owner@example.com"; const token = "Bearer secret-token-value"; const hexSecret = "abcdefabcdefabcdefabcdefabcdefabcdefabcd"; const redacted = redactFeedbackText(`Login failed for ${email} using ${token}; trace ${hexSecret}.`); expect(redacted).toBe( `Login failed for ${feedbackRedactionMarkers.email} using Bearer ${feedbackRedactionMarkers.token}; trace ${feedbackRedactionMarkers.secret}.`, ); expect(redacted).not.toContain(email); expect(redacted).not.toContain("secret-token-value"); expect(redacted).not.toContain(hexSecret); }); });