Skip to content

fix: fix incorrect x-amz-content-sha256 header #1326

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

Merged
merged 4 commits into from
Jul 6, 2020
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
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