-
Notifications
You must be signed in to change notification settings - Fork 633
test(clients): update payload types in client tests #7373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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])), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as LexRuntime |
||
}); | ||
}); | ||
}); | ||
|
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", | ||
|
@@ -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([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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], | ||
]); | ||
}, | ||
}, | ||
}) | ||
); | ||
|
||
|
@@ -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: {} }]); | ||
}); | ||
}); |
There was a problem hiding this comment.
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.