import { describe, expect, it } from "vitest"; import { imapProxyForHost, normalizeImapProxyUrl, redactProxyUrl, } from "@/lib/imap-proxy"; describe("imap-proxy", () => { it("accepts socks5 and http URLs", () => { expect(normalizeImapProxyUrl("socks5://127.0.0.1:7891")).toBe( "socks5://127.0.0.1:7891", ); expect(normalizeImapProxyUrl("http://127.0.0.1:7890")).toBe( "http://127.0.0.1:7890", ); expect(normalizeImapProxyUrl("ftp://127.0.0.1:21")).toBeUndefined(); expect(normalizeImapProxyUrl("")).toBeUndefined(); }); it("proxies Gmail but not QQ by default", () => { const proxy = "socks5://127.0.0.1:7891"; const filter = "gmail,google,outlook,office365,hotmail,live,msn"; expect(imapProxyForHost("imap.gmail.com", proxy, filter)).toBe(proxy); expect(imapProxyForHost("imap.qq.com", proxy, filter)).toBeUndefined(); expect(imapProxyForHost("imap.163.com", proxy, filter)).toBeUndefined(); }); it("proxies all hosts when filter is *", () => { const proxy = "http://127.0.0.1:7890"; expect(imapProxyForHost("imap.qq.com", proxy, "*")).toBe(proxy); }); it("redacts proxy password", () => { expect(redactProxyUrl("socks5://user:secret@127.0.0.1:1080")).toMatch( /\*\*\*\*/, ); expect(redactProxyUrl("socks5://user:secret@127.0.0.1:1080")).not.toMatch( /secret/, ); }); });