82 lines
3.0 KiB
TypeScript
82 lines
3.0 KiB
TypeScript
import { describe, it, expect } from "bun:test";
|
|
import { parseHeadersOrCurl } from "../../core/auth/login.js";
|
|
import { resolveCorpCluster } from "../../core/auth/easo.js";
|
|
import { handleCorpsCommand } from "./corps.js";
|
|
import type { CliRuntime } from "../types.js";
|
|
|
|
describe("core/auth/login > parseHeadersOrCurl & URL link parsing", () => {
|
|
it("successfully parses standard thirdparty.html assistance links", () => {
|
|
const url = "https://wx2.ekuaibao.com/web/thirdparty.html?accessToken=token123&ekbCorpId=corpABC&pageType=home";
|
|
const parsed = parseHeadersOrCurl(url);
|
|
|
|
expect(parsed.baseUrl).toBe("https://wx2.ekuaibao.com");
|
|
expect(parsed.accessToken).toBe("token123");
|
|
expect(parsed.corpId).toBe("corpABC");
|
|
});
|
|
|
|
it("extracts custom staffId and standard corpId query params", () => {
|
|
const url = "https://app.ekuaibao.com/thirdparty.html?token=secret999&corpId=corpXYZ&staffId=corpXYZ:user1";
|
|
const parsed = parseHeadersOrCurl(url);
|
|
|
|
expect(parsed.baseUrl).toBe("https://app.ekuaibao.com");
|
|
expect(parsed.accessToken).toBe("secret999");
|
|
expect(parsed.corpId).toBe("corpXYZ");
|
|
expect(parsed.staffId).toBe("corpXYZ:user1");
|
|
});
|
|
|
|
it("handles curl command lines with assistance URL", () => {
|
|
const curl = `curl "https://wx.ekuaibao.com/web/thirdparty.html?accessToken=testToken&ekbCorpId=testCorp" -H "User-Agent: Mozilla"`;
|
|
const parsed = parseHeadersOrCurl(curl);
|
|
|
|
expect(parsed.baseUrl).toBe("https://wx.ekuaibao.com");
|
|
expect(parsed.accessToken).toBe("testToken");
|
|
expect(parsed.corpId).toBe("testCorp");
|
|
});
|
|
});
|
|
|
|
describe("core/auth/easo > resolveCorpCluster", () => {
|
|
it("prioritizes explicit cluster config", () => {
|
|
expect(resolveCorpCluster({ cluster: "wx2", baseUrl: "https://app.ekuaibao.com" })).toBe("wx2");
|
|
});
|
|
|
|
it("extracts cluster from hostname subdomain", () => {
|
|
expect(resolveCorpCluster({ baseUrl: "https://wx2.ekuaibao.com" })).toBe("wx2");
|
|
expect(resolveCorpCluster({ baseUrl: "https://wx.ekuaibao.com" })).toBe("wx");
|
|
expect(resolveCorpCluster({ baseUrl: "https://app.ekuaibao.com" })).toBe("app");
|
|
});
|
|
|
|
it("falls back to app when unknown", () => {
|
|
expect(resolveCorpCluster({})).toBe("app");
|
|
expect(resolveCorpCluster({ baseUrl: "https://custom-domain.com" })).toBe("app");
|
|
});
|
|
});
|
|
|
|
describe("cli/commands/corps > handleCorpsCommand add-link", () => {
|
|
const dummyRuntime: CliRuntime = {
|
|
corpContext: {
|
|
listCorps: () => [],
|
|
getCurrent: () => null,
|
|
switchCorp: () => false,
|
|
resolve: () => null,
|
|
} as any,
|
|
selectedCorp: null,
|
|
jsonMode: false,
|
|
};
|
|
|
|
it("returns error exit code when no link URL is provided", async () => {
|
|
const res = await handleCorpsCommand(
|
|
{
|
|
area: "corps",
|
|
action: "add-link",
|
|
args: [],
|
|
options: {},
|
|
raw: ["corps", "add-link"],
|
|
},
|
|
dummyRuntime
|
|
);
|
|
|
|
expect(res.exitCode).toBe(1);
|
|
expect(res.stderr).toContain("必须提供协助/免密链接 URL");
|
|
});
|
|
});
|