Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("sets the x-amz-glacier-version header", async () => {
const handler = addGlacierApiVersionMiddleware({
apiVersion: "1970-01-01"
})(mockNextHandler, {} as any);
await handler({
input: {},
request: new HttpRequest({
headers: {}
})
});
// ensure the next handler was called
expect(mockNextHandler.mock.calls.length).toBe(1);
const { request } = mockNextHandler.mock.calls[0][0];
expect(request.headers["x-amz-glacier-version"]).toBe("1970-01-01");
});
});
mockHttpsServer.addListener(
"request",
createResponseFunction(mockResponse)
);
const spy = jest.spyOn(https, "request").mockImplementationOnce(() => {
let calls = spy.mock.calls;
let currentIndex = calls.length - 1;
return https.request(calls[currentIndex][0], calls[currentIndex][1]);
});
// clear data held from previous tests
spy.mockClear();
const nodeHttpHandler = new NodeHttpHandler();
await expect(
nodeHttpHandler.handle(
new HttpRequest({
hostname: "localhost",
method: "GET",
port: (mockHttpsServer.address() as AddressInfo).port,
protocol: "https:",
path: "/",
headers: {}
}),
{
abortSignal: {
aborted: true
}
}
)
).rejects.toHaveProperty("name", "AbortError");
expect(spy.mock.calls.length).toBe(0);
import { prepareRequest } from "./prepareRequest";
import { HttpRequest } from "@aws-sdk/protocol-http";
import { AMZ_DATE_HEADER, AUTH_HEADER, DATE_HEADER } from "./constants";
const minimalRequest = new HttpRequest({
method: "POST",
protocol: "https:",
path: "/",
headers: {
host: "foo.us-bar-1.amazonaws.com"
},
hostname: "foo.us-bar-1.amazonaws.com"
});
describe("prepareRequest", () => {
it("should clone requests", () => {
const prepared = prepareRequest(minimalRequest);
expect(prepared).toEqual(prepareRequest(minimalRequest));
expect(prepared).not.toBe(prepareRequest(minimalRequest));
});
import { moveHeadersToQuery } from "./moveHeadersToQuery";
import { HttpRequest } from "@aws-sdk/protocol-http";
const minimalRequest = new HttpRequest({
method: "POST",
protocol: "https:",
path: "/",
headers: {
host: "foo.us-east-1.amazonaws.com"
},
hostname: "foo.us-east-1.amazonaws.com"
});
describe("moveHeadersToQuery", () => {
it('should hoist "x-amz-" headers to the querystring', () => {
const req = moveHeadersToQuery(
new HttpRequest({
...minimalRequest,
headers: {
Host: "www.example.com",
describe("getPayloadHash", () => {
const minimalRequest = new HttpRequest({
method: "POST",
protocol: "https:",
path: "/",
headers: {},
hostname: "foo.us-east-1.amazonaws.com"
});
it("should return the SHA-256 hash of an empty string if a request has no payload (body)", async () => {
await expect(getPayloadHash(minimalRequest, Sha256)).resolves.toBe(
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
);
});
it(`should return the value in the '${SHA256_HEADER}' header (if present)`, async () => {
await expect(
getPayloadHash(
it("should downcase all headers", () => {
expect(
getCanonicalHeaders(
new HttpRequest({
method: "POST",
protocol: "https:",
path: "/",
headers: {
fOo: "bar",
BaZ: "QUUX",
HoSt: "foo.us-east-1.amazonaws.com"
},
hostname: "foo.us-east-1.amazonaws.com"
})
)
).toEqual({
foo: "bar",
baz: "QUUX",
host: "foo.us-east-1.amazonaws.com"
});
it("should ignore previously set authorization, date, and x-amz-date headers", async () => {
const { headers } = prepareRequest(
new HttpRequest({
...minimalRequest,
headers: {
[AUTH_HEADER]: "foo",
[AMZ_DATE_HEADER]: "bar",
[DATE_HEADER]: "baz"
}
})
);
expect(headers[AUTH_HEADER]).toBeUndefined();
expect(headers[AMZ_DATE_HEADER]).toBeUndefined();
expect(headers[DATE_HEADER]).toBeUndefined();
});
});
describe("URI encoding paths", () => {
const minimalRequest = new HttpRequest({
method: "POST",
protocol: "https:",
path: "/foo%3Dbar",
headers: {
host: "foo.us-bar-1.amazonaws.com"
},
hostname: "foo.us-bar-1.amazonaws.com"
});
it("should URI-encode the path by default", async () => {
const { query = {} } = await signer.presignRequest(
minimalRequest,
expiration,
presigningOptions
);
expect(query[SIGNATURE_QUERY_PARAM]).toBe(
it("does not set the Expect header to 100-continue for browser runtime", async () => {
const handler = addExpectContinueMiddleware({ runtime: "browser" })(
mockNextHandler,
{} as any
);
await handler({
input: {},
request: new HttpRequest({
body: "foo",
headers: {}
})
});
const { calls } = (mockNextHandler as any).mock;
expect(calls.length).toBe(1);
const { request } = mockNextHandler.mock.calls[0][0];
expect(request.headers["Expect"]).toBeUndefined();
});
});
it("should prefer the request ID from the standard header", () => {
expect(
extractMetadata(new HttpResponse({
...httpResponseOptions,
headers: {
"X-Amz-Request-ID": "id",
"X-Amz-RequestId": "alt_id"
}
})).requestId
).toBe("id");
});