Skip to content

Commit

Permalink
fix: fix incorrect x-amz-content-sha256 header (#1326)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
AllanZhengYP committed Jul 6, 2020
1 parent e75fe71 commit 68f9315
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 10 deletions.
34 changes: 34 additions & 0 deletions clients/client-lex-runtime-service/LexRuntimeService.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/// <reference types="mocha" />
import { expect } from "chai";
import { LexRuntimeService } from "./LexRuntimeService";
import { SerializeMiddleware } from "@aws-sdk/types";
import { HttpRequest } from "@aws-sdk/protocol-http";

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({});
client.middlewareStack.add(validator, {
step: "serialize",
name: "endpointValidator",
priority: "low"
});
return await client.postContent({
botAlias: "alias",
botName: "bot",
userId: "user",
contentType: "text/plain; charset=utf-8",
inputStream: "hello world!"
});
});
});
});
6 changes: 4 additions & 2 deletions clients/client-lex-runtime-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"remove-documentation": "rimraf ./docs",
"remove-js": "rimraf *.js && rimraf ./commands/*.js && rimraf ./models/*.js && rimraf ./protocols/*.js",
"remove-maps": "rimraf *.js.map && rimraf ./commands/*.js.map && rimraf ./models/*.js.map && rimraf ./protocols/*.js.map",
"test": "exit 0",
"test:unit": "mocha **/cjs/**/*.spec.js",
"test": "yarn test:unit",
"build:es": "tsc -p tsconfig.es.json",
"build": "yarn pretest && yarn build:es"
},
Expand Down Expand Up @@ -60,8 +61,9 @@
"tslib": "^1.8.0"
},
"devDependencies": {
"@types/chai": "^4.2.11",
"@types/mocha": "^7.0.2",
"@types/node": "^12.7.5",
"jest": "^25.1.0",
"rimraf": "^3.0.0",
"tslib": "^1.8.0",
"typedoc": "^0.15.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export const serializeAws_restJson1PostContentCommand = async (
): Promise<__HttpRequest> => {
const headers: any = {
"Content-Type": "application/octet-stream",
"x-amz-content-sha256": "UNSIGNED_PAYLOAD",
"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
...(isSerializableHeaderValue(input.accept) && { Accept: input.accept! }),
...(isSerializableHeaderValue(input.contentType) && {
"Content-Type": input.contentType!
Expand Down
3 changes: 2 additions & 1 deletion clients/client-lex-runtime-service/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"incremental": true,
"resolveJsonModule": true,
"declarationDir": "./types",
"outDir": "dist/cjs"
"outDir": "dist/cjs",
"types": ["mocha", "node"]
},
"typedocOptions": {
"exclude": "**/node_modules/**",
Expand Down
31 changes: 31 additions & 0 deletions clients/client-mediastore-data/MidiaStoreData.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/// <reference types="mocha" />
import { expect } from "chai";
import { MediaStoreData } from "./MediaStoreData";
import { SerializeMiddleware } from "@aws-sdk/types";
import { HttpRequest } from "@aws-sdk/protocol-http";

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({});
client.middlewareStack.add(validator, {
step: "serialize",
name: "endpointValidator",
priority: "low"
});
return await client.putObject({
Path: "foo.avi",
Body: "binary body"
});
});
});
});
6 changes: 4 additions & 2 deletions clients/client-mediastore-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"remove-documentation": "rimraf ./docs",
"remove-js": "rimraf *.js && rimraf ./commands/*.js && rimraf ./models/*.js && rimraf ./protocols/*.js",
"remove-maps": "rimraf *.js.map && rimraf ./commands/*.js.map && rimraf ./models/*.js.map && rimraf ./protocols/*.js.map",
"test": "exit 0",
"test:unit": "mocha **/cjs/**/*.spec.js",
"test": "yarn test:unit",
"build:es": "tsc -p tsconfig.es.json",
"build": "yarn pretest && yarn build:es"
},
Expand Down Expand Up @@ -60,8 +61,9 @@
"tslib": "^1.8.0"
},
"devDependencies": {
"@types/chai": "^4.2.11",
"@types/mocha": "^7.0.2",
"@types/node": "^12.7.5",
"jest": "^25.1.0",
"rimraf": "^3.0.0",
"tslib": "^1.8.0",
"typedoc": "^0.15.0",
Expand Down
2 changes: 1 addition & 1 deletion clients/client-mediastore-data/protocols/Aws_restJson1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const serializeAws_restJson1PutObjectCommand = async (
): Promise<__HttpRequest> => {
const headers: any = {
"Content-Type": "application/octet-stream",
"x-amz-content-sha256": "UNSIGNED_PAYLOAD",
"x-amz-content-sha256": "UNSIGNED-PAYLOAD",
...(isSerializableHeaderValue(input.CacheControl) && {
"Cache-Control": input.CacheControl!
}),
Expand Down
3 changes: 2 additions & 1 deletion clients/client-mediastore-data/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"incremental": true,
"resolveJsonModule": true,
"declarationDir": "./types",
"outDir": "dist/cjs"
"outDir": "dist/cjs",
"types": ["mocha"]
},
"typedocOptions": {
"exclude": "**/node_modules/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class AwsProtocolUtils {
private AwsProtocolUtils() {}

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

operation.getTrait(UnsignedPayloadTrait.class)
.ifPresent(trait -> {
writer.write("'x-amz-content-sha256': 'UNSIGNED_PAYLOAD',");
writer.write("'x-amz-content-sha256': 'UNSIGNED-PAYLOAD',");
});
}

Expand Down

0 comments on commit 68f9315

Please sign in to comment.