qbo_auth: вебхук cloudevents+json (был 415), страница тестов по секретной ссылке, allowedRealmIds; требования Intuit
All checks were successful
ci / test (push) Successful in 36s
ci / deploy (push) Successful in 2m37s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 09:28:24 +03:00
parent e90b9f352d
commit 9a1a2a8a6b
9 changed files with 85 additions and 28 deletions

View File

@@ -123,6 +123,26 @@ describe("токены", () => {
});
});
describe("защита от чужой компании", () => {
it("realmId вне списка отклоняется до обмена кода; из списка подключается", async () => {
const st = new MemoryStore();
const f = fakeFetch([{ body: tokens(1) }]);
const notes: string[] = [];
const auth = new QboAuth({
store: st, fetchFn: f.fn, env: "sandbox", clientId: "cid", clientSecret: "csec", redirectUri: "https://x/cb", scope: "s", keepAliveHours: 20,
allowedRealmIds: ["R-OK"], notify: async (t) => { notes.push(t); },
});
const s1 = new URL((await auth.startConnect()).url).searchParams.get("state")!;
await expect(auth.handleCallback({ code: "c", state: s1, realmId: "R-OTHER" })).rejects.toThrow(/allowedRealmIds/);
expect(f.calls.length).toBe(0);
expect(notes[0]).toContain("R-OTHER");
expect(await st.read("sandbox")).toBeNull();
const s2 = new URL((await auth.startConnect()).url).searchParams.get("state")!;
await auth.handleCallback({ code: "c", state: s2, realmId: "R-OK" });
expect((await st.read("sandbox"))?.realmId).toBe("R-OK");
});
});
describe("HTTP", () => {
it("служебные ручки требуют токен; /healthz и /callback открыты; в status нет секретов", async () => {
const ctx = mk([{ body: tokens(1) }]);