You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.4 KiB

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/,
);
});
});