Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions clients/client-lex-runtime-service/test/LexRuntimeService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
import { HttpRequest } from "@smithy/protocol-http";
import { SerializeMiddleware } from "@smithy/types";
import { describe, expect, test as it } from "vitest";
import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src";
import { Readable } from "node:stream";
import { describe, test as it } from "vitest";

import { LexRuntimeService } from "../src/LexRuntimeService";

describe("@aws-sdk/client-lex-runtime-service", () => {
describe("PostContent", () => {
it("should contain correct x-amz-content-sha256 header", async () => {
const validator: SerializeMiddleware<any, any> = (next) => (args) => {
// middleware intercept the request and return it early
const request = args.request as HttpRequest;
expect(request.headers).to.have.property("x-amz-content-sha256", "UNSIGNED-PAYLOAD");
return Promise.resolve({ output: {} as any, response: {} as any });
};
const client = new LexRuntimeService({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
client.middlewareStack.add(validator, {
step: "serialize",
name: "endpointValidator",
priority: "low",

requireRequestsFrom(client).toMatch({
headers: {
"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
},
});

return await client.postContent({
botAlias: "alias",
botName: "bot",
userId: "user",
contentType: "text/plain; charset=utf-8",
inputStream: "hello world!",
inputStream: Readable.from(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than always being set to UNSIGNED-PAYLOAD because the operation is modeled as having a data stream, in schema-serde the sigv4 signer sets a sha256 hash if the input is buffered (string or Buffer) and UNSIGNED-PAYLOAD only when it is a stream.

});
});
});
Expand Down
24 changes: 10 additions & 14 deletions clients/client-mediastore-data/test/MediaStoreData.spec.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
import { HttpRequest } from "@smithy/protocol-http";
import { SerializeMiddleware } from "@smithy/types";
import { describe, expect, test as it } from "vitest";
import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src";
import { Readable } from "node:stream";
import { describe, test as it } from "vitest";

import { MediaStoreData } from "../src/MediaStoreData";

describe("@aws-sdk/client-mediastore-data", () => {
describe("PutObject", () => {
it("should contain correct x-amz-content-sha256 header", async () => {
const validator: SerializeMiddleware<any, any> = (next) => (args) => {
// middleware intercept the request and return it early
const request = args.request as HttpRequest;
expect(request.headers).to.have.property("x-amz-content-sha256", "UNSIGNED-PAYLOAD");
return Promise.resolve({ output: {} as any, response: {} as any });
};
const client = new MediaStoreData({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
client.middlewareStack.add(validator, {
step: "serialize",
name: "endpointValidator",
priority: "low",

requireRequestsFrom(client).toMatch({
headers: {
"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
},
});

return await client.putObject({
Path: "foo.avi",
Body: "binary body",
Body: Readable.from(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as LexRuntime

});
});
});
Expand Down
63 changes: 50 additions & 13 deletions clients/client-s3/test/integ/s3-selectObjectContent.integ.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src";
import { S3 } from "@aws-sdk/client-s3";
import { HttpResponse } from "@smithy/protocol-http";
import { Readable } from "stream";
import { describe, expect, test as it } from "vitest";

import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src";

describe("selectObjectContent", () => {
const credentials = {
accessKeyId: "INTEG",
Expand Down Expand Up @@ -34,16 +32,49 @@ describe("selectObjectContent", () => {
.respondWith(
new HttpResponse({
statusCode: 200,
body: Readable.from([
`<?xml version="1.0" encoding="UTF-8"?>`,
`<Payload>`,
`<Records><Payload>blob</Payload></Records>`,
`<Stats><Details><BytesProcessed>100</BytesProcessed><BytesReturned>50</BytesReturned><BytesScanned>100</BytesScanned></Details></Stats>`,
`<Progress><Details><BytesProcessed>100</BytesProcessed><BytesReturned>50</BytesReturned><BytesScanned>100</BytesScanned></Details></Progress>`,
`<Cont></Cont>`,
`<End></End>`,
`</Payload>`,
]),
headers: {
"x-amz-checksum-crc32": "3117266289",
},
body: {
*[Symbol.asyncIterator]() {
// see https://docs.aws.amazon.com/AmazonS3/latest/API/RESTSelectObjectAppendix.html
yield new Uint8Array([
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These bytes are the actual event stream whereas the previous XML was from a generated structural example and not what is actually sent.

/* message size */ ...[0, 0, 0, 97],
/* header size */ ...[0, 0, 0, 81],
/* prelude crc */ ...[221, 28, 224, 246],
/* headers */
/* :event-type */
11,
...[58, 101, 118, 101, 110, 116, 45, 116, 121, 112, 101],
7,
/* End */
0,
3,
...[69, 110, 100],
/* :content-type */
13,
...[58, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101],
7,
/* application/octet-stream */
0,
24,
...[
97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 111, 99, 116, 101, 116, 45, 115, 116, 114,
101, 97, 109,
],
/* :message-type */
13,
...[58, 109, 101, 115, 115, 97, 103, 101, 45, 116, 121, 112, 101],
7,
/* event */
0,
5,
...[101, 118, 101, 110, 116],
/* message crc */
...[75, 107, 103, 102],
]);
},
},
})
);

Expand All @@ -69,5 +100,11 @@ describe("selectObjectContent", () => {
expect(response.$metadata.httpStatusCode).toBe(200);
expect(response).toHaveProperty("Payload");
expect(response.Payload).toBeDefined();

const events = [];
for await (const event of response.Payload!) {
events.push(event);
}
expect(events).toEqual([{ End: {} }]);
});
});
Loading