qbo_auth: вебхук cloudevents+json (был 415), страница тестов по секретной ссылке, allowedRealmIds; требования Intuit
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { createHmac } from "node:crypto";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { buildApi } from "./http-api.js";
|
||||
import { buildApi, testsSlug } from "./http-api.js";
|
||||
import { parseWebhook, SyncTrigger, verifyWebhook } from "./webhook.js";
|
||||
import type { QboAuth } from "./service.js";
|
||||
|
||||
@@ -31,17 +31,30 @@ describe("вебхук Intuit", () => {
|
||||
expect(parseWebhook(JSON.stringify([ev, { ...ev, type: "qbo.vendor.deleted.v1", intuitentityid: "8" }])).map((e) => `${e.name}:${e.operation}`)).toEqual(["Bill:Create", "Vendor:Delete"]);
|
||||
});
|
||||
|
||||
it("страница /tests открыта, действия /tests/* закрыты токеном, заметка принимается", async () => {
|
||||
it("страница тестов: только по секретному адресу, заголовки без кэша, заметка принимается", async () => {
|
||||
const app = buildApi({} as QboAuth, "svc");
|
||||
const page = await app.inject({ url: "/tests" });
|
||||
const slug = testsSlug("svc");
|
||||
expect(slug).toMatch(/^[0-9a-f]{32}$/);
|
||||
expect((await app.inject({ url: "/tests/wrong" })).statusCode).toBe(404);
|
||||
expect((await app.inject({ url: "/tests/wrong/status" })).statusCode).toBe(404);
|
||||
expect((await app.inject({ method: "POST", url: "/tests/wrong/disconnect" })).statusCode).toBe(404);
|
||||
const page = await app.inject({ url: `/tests/${slug}` });
|
||||
expect(page.statusCode).toBe(200);
|
||||
expect(page.body).toContain("location.pathname");
|
||||
expect(page.headers["cache-control"]).toBe("no-cache, no-store");
|
||||
expect(page.headers["referrer-policy"]).toBe("no-referrer");
|
||||
expect((await app.inject({ url: "/tests/status" })).statusCode).toBe(401);
|
||||
expect((await app.inject({ method: "POST", url: "/tests/disconnect" })).statusCode).toBe(401);
|
||||
const h = { authorization: "Bearer svc", "content-type": "application/json" };
|
||||
expect((await app.inject({ method: "POST", url: "/tests/note", headers: h, payload: { text: "Bill 12.50" } })).statusCode).toBe(200);
|
||||
expect((await app.inject({ method: "POST", url: "/tests/note", headers: h, payload: { text: " " } })).statusCode).toBe(400);
|
||||
const h = { "content-type": "application/json" };
|
||||
expect((await app.inject({ method: "POST", url: `/tests/${slug}/note`, headers: h, payload: { text: "Bill 12.50" } })).statusCode).toBe(200);
|
||||
expect((await app.inject({ method: "POST", url: `/tests/${slug}/note`, headers: h, payload: { text: " " } })).statusCode).toBe(400);
|
||||
});
|
||||
|
||||
it("вебхук с типом application/cloudevents+json принимается (раньше было 415)", async () => {
|
||||
const onEvents = vi.fn();
|
||||
const app = buildApi({} as QboAuth, "svc", undefined, { tokens: ["tok"], onEvents });
|
||||
const body = JSON.stringify({ specversion: "1.0", type: "qbo.bill.created.v1", intuitentityid: "1234", intuitaccountid: "310687" });
|
||||
const r = await app.inject({ method: "POST", url: "/webhook", headers: { "content-type": "application/cloudevents+json", "intuit-signature": sign(body, "tok") }, payload: body });
|
||||
expect(r.statusCode).toBe(200);
|
||||
expect(onEvents).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("маршрут /webhook: без токенов 503, плохая подпись 401, верная 200 и вызов onEvents без Bearer-токена сервиса", async () => {
|
||||
|
||||
Reference in New Issue
Block a user