Skip to content

Commit 68f9315

Browse files
authored
fix: fix incorrect x-amz-content-sha256 header (#1326)
* fix: fix incorrect x-amz-content-sha256 header * chore: codegen fixing incorrect x-amz-sha256 * test(client-lex-runtime-service): add functional test * test(client-mediastore-data): add functional test
1 parent e75fe71 commit 68f9315

File tree

9 files changed

+81
-10
lines changed

9 files changed

+81
-10
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference types="mocha" />
2+
import { expect } from "chai";
3+
import { LexRuntimeService } from "./LexRuntimeService";
4+
import { SerializeMiddleware } from "@aws-sdk/types";
5+
import { HttpRequest } from "@aws-sdk/protocol-http";
6+
7+
describe("@aws-sdk/client-lex-runtime-service", () => {
8+
describe("PostContent", () => {
9+
it("should contain correct x-amz-content-sha256 header", async () => {
10+
const validator: SerializeMiddleware<any, any> = next => args => {
11+
// middleware intercept the request and return it early
12+
const request = args.request as HttpRequest;
13+
expect(request.headers).to.have.property(
14+
"x-amz-content-sha256",
15+
"UNSIGNED-PAYLOAD"
16+
);
17+
return Promise.resolve({ output: {} as any, response: {} as any });
18+
};
19+
const client = new LexRuntimeService({});
20+
client.middlewareStack.add(validator, {
21+
step: "serialize",
22+
name: "endpointValidator",
23+
priority: "low"
24+
});
25+
return await client.postContent({
26+
botAlias: "alias",
27+
botName: "bot",
28+
userId: "user",
29+
contentType: "text/plain; charset=utf-8",
30+
inputStream: "hello world!"
31+
});
32+
});
33+
});
34+
});

clients/client-lex-runtime-service/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"remove-documentation": "rimraf ./docs",
1313
"remove-js": "rimraf *.js && rimraf ./commands/*.js && rimraf ./models/*.js && rimraf ./protocols/*.js",
1414
"remove-maps": "rimraf *.js.map && rimraf ./commands/*.js.map && rimraf ./models/*.js.map && rimraf ./protocols/*.js.map",
15-
"test": "exit 0",
15+
"test:unit": "mocha **/cjs/**/*.spec.js",
16+
"test": "yarn test:unit",
1617
"build:es": "tsc -p tsconfig.es.json",
1718
"build": "yarn pretest && yarn build:es"
1819
},
@@ -60,8 +61,9 @@
6061
"tslib": "^1.8.0"
6162
},
6263
"devDependencies": {
64+
"@types/chai": "^4.2.11",
65+
"@types/mocha": "^7.0.2",
6366
"@types/node": "^12.7.5",
64-
"jest": "^25.1.0",
6567
"rimraf": "^3.0.0",
6668
"tslib": "^1.8.0",
6769
"typedoc": "^0.15.0",

clients/client-lex-runtime-service/protocols/Aws_restJson1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export const serializeAws_restJson1PostContentCommand = async (
179179
): Promise<__HttpRequest> => {
180180
const headers: any = {
181181
"Content-Type": "application/octet-stream",
182-
"x-amz-content-sha256": "UNSIGNED_PAYLOAD",
182+
"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
183183
...(isSerializableHeaderValue(input.accept) && { Accept: input.accept! }),
184184
...(isSerializableHeaderValue(input.contentType) && {
185185
"Content-Type": input.contentType!

clients/client-lex-runtime-service/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"incremental": true,
1313
"resolveJsonModule": true,
1414
"declarationDir": "./types",
15-
"outDir": "dist/cjs"
15+
"outDir": "dist/cjs",
16+
"types": ["mocha", "node"]
1617
},
1718
"typedocOptions": {
1819
"exclude": "**/node_modules/**",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference types="mocha" />
2+
import { expect } from "chai";
3+
import { MediaStoreData } from "./MediaStoreData";
4+
import { SerializeMiddleware } from "@aws-sdk/types";
5+
import { HttpRequest } from "@aws-sdk/protocol-http";
6+
7+
describe("@aws-sdk/client-mediastore-data", () => {
8+
describe("PutObject", () => {
9+
it("should contain correct x-amz-content-sha256 header", async () => {
10+
const validator: SerializeMiddleware<any, any> = next => args => {
11+
// middleware intercept the request and return it early
12+
const request = args.request as HttpRequest;
13+
expect(request.headers).to.have.property(
14+
"x-amz-content-sha256",
15+
"UNSIGNED-PAYLOAD"
16+
);
17+
return Promise.resolve({ output: {} as any, response: {} as any });
18+
};
19+
const client = new MediaStoreData({});
20+
client.middlewareStack.add(validator, {
21+
step: "serialize",
22+
name: "endpointValidator",
23+
priority: "low"
24+
});
25+
return await client.putObject({
26+
Path: "foo.avi",
27+
Body: "binary body"
28+
});
29+
});
30+
});
31+
});

clients/client-mediastore-data/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"remove-documentation": "rimraf ./docs",
1313
"remove-js": "rimraf *.js && rimraf ./commands/*.js && rimraf ./models/*.js && rimraf ./protocols/*.js",
1414
"remove-maps": "rimraf *.js.map && rimraf ./commands/*.js.map && rimraf ./models/*.js.map && rimraf ./protocols/*.js.map",
15-
"test": "exit 0",
15+
"test:unit": "mocha **/cjs/**/*.spec.js",
16+
"test": "yarn test:unit",
1617
"build:es": "tsc -p tsconfig.es.json",
1718
"build": "yarn pretest && yarn build:es"
1819
},
@@ -60,8 +61,9 @@
6061
"tslib": "^1.8.0"
6162
},
6263
"devDependencies": {
64+
"@types/chai": "^4.2.11",
65+
"@types/mocha": "^7.0.2",
6366
"@types/node": "^12.7.5",
64-
"jest": "^25.1.0",
6567
"rimraf": "^3.0.0",
6668
"tslib": "^1.8.0",
6769
"typedoc": "^0.15.0",

clients/client-mediastore-data/protocols/Aws_restJson1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export const serializeAws_restJson1PutObjectCommand = async (
184184
): Promise<__HttpRequest> => {
185185
const headers: any = {
186186
"Content-Type": "application/octet-stream",
187-
"x-amz-content-sha256": "UNSIGNED_PAYLOAD",
187+
"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
188188
...(isSerializableHeaderValue(input.CacheControl) && {
189189
"Cache-Control": input.CacheControl!
190190
}),

clients/client-mediastore-data/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"incremental": true,
1313
"resolveJsonModule": true,
1414
"declarationDir": "./types",
15-
"outDir": "dist/cjs"
15+
"outDir": "dist/cjs",
16+
"types": ["mocha"]
1617
},
1718
"typedocOptions": {
1819
"exclude": "**/node_modules/**",

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class AwsProtocolUtils {
4545
private AwsProtocolUtils() {}
4646

4747
/**
48-
* Writes an {@code 'x-amz-content-sha256' = 'UNSIGNED_PAYLOAD'} header for an
48+
* Writes an {@code 'x-amz-content-sha256' = 'UNSIGNED-PAYLOAD'} header for an
4949
* {@code @aws.api#unsignedPayload} trait that specifies the {@code "aws.v4"} auth scheme.
5050
*
5151
* @see <a href=https://awslabs.github.io/smithy/spec/aws-core.html#aws-api-unsignedpayload-trait>@aws.api#unsignedPayload trait</a>
@@ -58,7 +58,7 @@ static void generateUnsignedPayloadSigV4Header(GenerationContext context, Operat
5858

5959
operation.getTrait(UnsignedPayloadTrait.class)
6060
.ifPresent(trait -> {
61-
writer.write("'x-amz-content-sha256': 'UNSIGNED_PAYLOAD',");
61+
writer.write("'x-amz-content-sha256': 'UNSIGNED-PAYLOAD',");
6262
});
6363
}
6464

0 commit comments

Comments
 (0)