|
| 1 | +/// <reference types="mocha" /> |
| 2 | +import { FinalizeRequestMiddleware } from "@aws-sdk/types"; |
| 3 | +import chai from "chai"; |
| 4 | +import chaiAsPromised from "chai-as-promised"; |
| 5 | + |
| 6 | +import { EventBridge } from "../src/EventBridge"; |
| 7 | + |
| 8 | +chai.use(chaiAsPromised); |
| 9 | +const { expect } = chai; |
| 10 | + |
| 11 | +describe("EventBridge", () => { |
| 12 | + const client = new EventBridge({}); |
| 13 | + // Middleware intercept request and return it before reaching the HTTP client. It records the request and context |
| 14 | + // and return them in the Metadata. |
| 15 | + const interceptionMiddleware: FinalizeRequestMiddleware<any, any> = (next, context) => (args) => { |
| 16 | + return Promise.resolve({ output: { $metadata: { request: args.request } }, response: "" as any }); |
| 17 | + }; |
| 18 | + client.middlewareStack.add(interceptionMiddleware, { step: "finalizeRequest", name: "interceptionMiddleware" }); |
| 19 | + describe("putEvents", () => { |
| 20 | + it("should use sign request with sigv4a with EventId presents", async () => { |
| 21 | + const { |
| 22 | + // @ts-ignore request is set in $metadata by interception middleware. |
| 23 | + $metadata: { request }, |
| 24 | + } = await client.putEvents({ |
| 25 | + Entries: [], |
| 26 | + EndpointId: "endpointId", |
| 27 | + }); |
| 28 | + expect(request.hostname).eql("endpointId.endpoint.events.amazonaws.com"); |
| 29 | + expect(request.headers["X-Amz-Region-Set"]).eql("*"); |
| 30 | + expect(request.headers["Authorization"]).includes("AWS4-ECDSA-P256-SHA256"); |
| 31 | + }); |
| 32 | + }); |
| 33 | +}); |
0 commit comments