diff --git a/clients/client-lex-runtime-service/protocols/Aws_restJson1.ts b/clients/client-lex-runtime-service/protocols/Aws_restJson1.ts index 517f19a9aa8f..8baf8faa5cc8 100644 --- a/clients/client-lex-runtime-service/protocols/Aws_restJson1.ts +++ b/clients/client-lex-runtime-service/protocols/Aws_restJson1.ts @@ -153,19 +153,21 @@ export const serializeAws_restJson1PostContentCommand = async ( "content-type": "application/octet-stream", "x-amz-content-sha256": "UNSIGNED-PAYLOAD", ...(isSerializableHeaderValue(input.sessionAttributes) && { - "x-amz-lex-session-attributes": Buffer.from(__LazyJsonString.fromObject(input.sessionAttributes!)).toString( - "base64" + "x-amz-lex-session-attributes": context.base64Encoder( + Buffer.from(__LazyJsonString.fromObject(input.sessionAttributes!)) ), }), ...(isSerializableHeaderValue(input.requestAttributes) && { - "x-amz-lex-request-attributes": Buffer.from(__LazyJsonString.fromObject(input.requestAttributes!)).toString( - "base64" + "x-amz-lex-request-attributes": context.base64Encoder( + Buffer.from(__LazyJsonString.fromObject(input.requestAttributes!)) ), }), ...(isSerializableHeaderValue(input.contentType) && { "content-type": input.contentType! }), ...(isSerializableHeaderValue(input.accept) && { accept: input.accept! }), ...(isSerializableHeaderValue(input.activeContexts) && { - "x-amz-lex-active-contexts": Buffer.from(__LazyJsonString.fromObject(input.activeContexts!)).toString("base64"), + "x-amz-lex-active-contexts": context.base64Encoder( + Buffer.from(__LazyJsonString.fromObject(input.activeContexts!)) + ), }), }; let resolvedPath = @@ -575,20 +577,22 @@ export const deserializeAws_restJson1PostContentCommand = async ( } if (output.headers["x-amz-lex-nlu-intent-confidence"] !== undefined) { contents.nluIntentConfidence = new __LazyJsonString( - Buffer.from(output.headers["x-amz-lex-nlu-intent-confidence"], "base64").toString("ascii") + Buffer.from(context.base64Decoder(output.headers["x-amz-lex-nlu-intent-confidence"])).toString("utf8") ); } if (output.headers["x-amz-lex-alternative-intents"] !== undefined) { contents.alternativeIntents = new __LazyJsonString( - Buffer.from(output.headers["x-amz-lex-alternative-intents"], "base64").toString("ascii") + Buffer.from(context.base64Decoder(output.headers["x-amz-lex-alternative-intents"])).toString("utf8") ); } if (output.headers["x-amz-lex-slots"] !== undefined) { - contents.slots = new __LazyJsonString(Buffer.from(output.headers["x-amz-lex-slots"], "base64").toString("ascii")); + contents.slots = new __LazyJsonString( + Buffer.from(context.base64Decoder(output.headers["x-amz-lex-slots"])).toString("utf8") + ); } if (output.headers["x-amz-lex-session-attributes"] !== undefined) { contents.sessionAttributes = new __LazyJsonString( - Buffer.from(output.headers["x-amz-lex-session-attributes"], "base64").toString("ascii") + Buffer.from(context.base64Decoder(output.headers["x-amz-lex-session-attributes"])).toString("utf8") ); } if (output.headers["x-amz-lex-sentiment"] !== undefined) { @@ -623,7 +627,7 @@ export const deserializeAws_restJson1PostContentCommand = async ( } if (output.headers["x-amz-lex-active-contexts"] !== undefined) { contents.activeContexts = new __LazyJsonString( - Buffer.from(output.headers["x-amz-lex-active-contexts"], "base64").toString("ascii") + Buffer.from(context.base64Decoder(output.headers["x-amz-lex-active-contexts"])).toString("utf8") ); } const data: any = output.body; @@ -940,11 +944,13 @@ export const deserializeAws_restJson1PutSessionCommand = async ( contents.intentName = output.headers["x-amz-lex-intent-name"]; } if (output.headers["x-amz-lex-slots"] !== undefined) { - contents.slots = new __LazyJsonString(Buffer.from(output.headers["x-amz-lex-slots"], "base64").toString("ascii")); + contents.slots = new __LazyJsonString( + Buffer.from(context.base64Decoder(output.headers["x-amz-lex-slots"])).toString("utf8") + ); } if (output.headers["x-amz-lex-session-attributes"] !== undefined) { contents.sessionAttributes = new __LazyJsonString( - Buffer.from(output.headers["x-amz-lex-session-attributes"], "base64").toString("ascii") + Buffer.from(context.base64Decoder(output.headers["x-amz-lex-session-attributes"])).toString("utf8") ); } if (output.headers["x-amz-lex-message"] !== undefined) { @@ -967,7 +973,7 @@ export const deserializeAws_restJson1PutSessionCommand = async ( } if (output.headers["x-amz-lex-active-contexts"] !== undefined) { contents.activeContexts = new __LazyJsonString( - Buffer.from(output.headers["x-amz-lex-active-contexts"], "base64").toString("ascii") + Buffer.from(context.base64Decoder(output.headers["x-amz-lex-active-contexts"])).toString("utf8") ); } const data: any = output.body; diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java index eab35238a5dc..20d0d2233f25 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java @@ -326,11 +326,6 @@ private static boolean filterMalformedRequestTests( if (testCase.getId().equals("RestJsonBodyMalformedMapNullValue")) { return true; } - //TODO: Buffer.from isn't decoding base64 strictly. - if (testCase.getId().equals("RestJsonBodyMalformedBlobInvalidBase64_case1") - || testCase.getId().equals("RestJsonBodyMalformedBlobInvalidBase64_case2")) { - return true; - } //TODO: Fixed after Smithy 1.11.0 if (testCase.getId().equals("RestJsonPathTimestampDefaultRejectsDifferent8601Formats_case14")) { diff --git a/protocol_tests/aws-restjson/protocols/Aws_restJson1.ts b/protocol_tests/aws-restjson/protocols/Aws_restJson1.ts index 3748cc335dfa..b4afc9ca9a5d 100644 --- a/protocol_tests/aws-restjson/protocols/Aws_restJson1.ts +++ b/protocol_tests/aws-restjson/protocols/Aws_restJson1.ts @@ -1282,7 +1282,7 @@ export const serializeAws_restJson1MediaTypeHeaderCommand = async ( const { hostname, protocol = "https", port, path: basePath } = await context.endpoint(); const headers: any = { ...(isSerializableHeaderValue(input.json) && { - "x-json": Buffer.from(__LazyJsonString.fromObject(input.json!)).toString("base64"), + "x-json": context.base64Encoder(Buffer.from(__LazyJsonString.fromObject(input.json!))), }), }; let resolvedPath = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + "/MediaTypeHeader"; @@ -3299,7 +3299,7 @@ export const deserializeAws_restJson1MediaTypeHeaderCommand = async ( json: undefined, }; if (output.headers["x-json"] !== undefined) { - contents.json = new __LazyJsonString(Buffer.from(output.headers["x-json"], "base64").toString("ascii")); + contents.json = new __LazyJsonString(Buffer.from(context.base64Decoder(output.headers["x-json"])).toString("utf8")); } await collectBody(output.body, context); return Promise.resolve(contents);