From 6c33a77556e4b47ee0f1c8054d5ff89c26f17355 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Thu, 5 Aug 2021 11:36:36 -0700 Subject: [PATCH] chore(protocol_tests): update protocol_tests with smithy-1.11.x (#2644) * chore(protocol_tests): update protocol_tests with smithy-1.11.x * chore(protocol_tests): skip SimpleScalarPropertiesPureWhiteSpace --- .../aws-restjson/RestJsonProtocol.ts | 37 +++++++ .../aws-restjson/RestJsonProtocolClient.ts | 22 +++++ .../commands/HttpChecksumRequiredCommand.ts | 96 +++++++++++++++++++ protocol_tests/aws-restjson/index.ts | 1 + .../aws-restjson/models/models_0.ts | 13 +++ protocol_tests/aws-restjson/package.json | 4 + .../aws-restjson/protocols/Aws_restJson1.ts | 75 +++++++++++++++ .../aws-restjson/runtimeConfig.browser.ts | 4 + protocol_tests/aws-restjson/runtimeConfig.ts | 4 + .../tests/functional/restjson1.spec.ts | 42 ++++++++ .../tests/functional/restxml.spec.ts | 96 ++++++++++++++++++- 11 files changed, 390 insertions(+), 4 deletions(-) create mode 100644 protocol_tests/aws-restjson/commands/HttpChecksumRequiredCommand.ts diff --git a/protocol_tests/aws-restjson/RestJsonProtocol.ts b/protocol_tests/aws-restjson/RestJsonProtocol.ts index f69f1655be00..2382dc1bd435 100644 --- a/protocol_tests/aws-restjson/RestJsonProtocol.ts +++ b/protocol_tests/aws-restjson/RestJsonProtocol.ts @@ -49,6 +49,11 @@ import { HostWithPathOperationCommandInput, HostWithPathOperationCommandOutput, } from "./commands/HostWithPathOperationCommand"; +import { + HttpChecksumRequiredCommand, + HttpChecksumRequiredCommandInput, + HttpChecksumRequiredCommandOutput, +} from "./commands/HttpChecksumRequiredCommand"; import { HttpEnumPayloadCommand, HttpEnumPayloadCommandInput, @@ -535,6 +540,38 @@ export class RestJsonProtocol extends RestJsonProtocolClient { } } + /** + * This example tests httpChecksumRequired trait + */ + public httpChecksumRequired( + args: HttpChecksumRequiredCommandInput, + options?: __HttpHandlerOptions + ): Promise; + public httpChecksumRequired( + args: HttpChecksumRequiredCommandInput, + cb: (err: any, data?: HttpChecksumRequiredCommandOutput) => void + ): void; + public httpChecksumRequired( + args: HttpChecksumRequiredCommandInput, + options: __HttpHandlerOptions, + cb: (err: any, data?: HttpChecksumRequiredCommandOutput) => void + ): void; + public httpChecksumRequired( + args: HttpChecksumRequiredCommandInput, + optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: HttpChecksumRequiredCommandOutput) => void), + cb?: (err: any, data?: HttpChecksumRequiredCommandOutput) => void + ): Promise | void { + const command = new HttpChecksumRequiredCommand(args); + if (typeof optionsOrCb === "function") { + this.send(command, optionsOrCb); + } else if (typeof cb === "function") { + if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`); + this.send(command, optionsOrCb || {}, cb); + } else { + return this.send(command, optionsOrCb); + } + } + public httpEnumPayload( args: HttpEnumPayloadCommandInput, options?: __HttpHandlerOptions diff --git a/protocol_tests/aws-restjson/RestJsonProtocolClient.ts b/protocol_tests/aws-restjson/RestJsonProtocolClient.ts index 87748ea9089f..93617d935ebe 100644 --- a/protocol_tests/aws-restjson/RestJsonProtocolClient.ts +++ b/protocol_tests/aws-restjson/RestJsonProtocolClient.ts @@ -29,6 +29,10 @@ import { HostWithPathOperationCommandInput, HostWithPathOperationCommandOutput, } from "./commands/HostWithPathOperationCommand"; +import { + HttpChecksumRequiredCommandInput, + HttpChecksumRequiredCommandOutput, +} from "./commands/HttpChecksumRequiredCommand"; import { HttpEnumPayloadCommandInput, HttpEnumPayloadCommandOutput } from "./commands/HttpEnumPayloadCommand"; import { HttpPayloadTraitsCommandInput, HttpPayloadTraitsCommandOutput } from "./commands/HttpPayloadTraitsCommand"; import { @@ -159,9 +163,11 @@ import { Logger as __Logger, Provider as __Provider, StreamCollector as __StreamCollector, + StreamHasher as __StreamHasher, UrlParser as __UrlParser, UserAgent as __UserAgent, } from "@aws-sdk/types"; +import { Readable } from "stream"; export type ServiceInputTypes = | AllQueryStringTypesCommandInput @@ -174,6 +180,7 @@ export type ServiceInputTypes = | EndpointWithHostLabelOperationCommandInput | GreetingWithErrorsCommandInput | HostWithPathOperationCommandInput + | HttpChecksumRequiredCommandInput | HttpEnumPayloadCommandInput | HttpPayloadTraitsCommandInput | HttpPayloadTraitsWithMediaTypeCommandInput @@ -221,6 +228,7 @@ export type ServiceOutputTypes = | EndpointWithHostLabelOperationCommandOutput | GreetingWithErrorsCommandOutput | HostWithPathOperationCommandOutput + | HttpChecksumRequiredCommandOutput | HttpEnumPayloadCommandOutput | HttpPayloadTraitsCommandOutput | HttpPayloadTraitsWithMediaTypeCommandOutput @@ -357,6 +365,20 @@ export interface ClientDefaults extends Partial<__SmithyResolvedConfiguration<__ * @internal */ defaultUserAgentProvider?: Provider<__UserAgent>; + + /** + * A function that, given a hash constructor and a stream, calculates the + * hash of the streamed value. + * @internal + */ + streamHasher?: __StreamHasher | __StreamHasher; + + /** + * A constructor for a class implementing the {@link __Hash} interface + * that computes MD5 hashes. + * @internal + */ + md5?: __HashConstructor; } type RestJsonProtocolClientConfigType = Partial<__SmithyConfiguration<__HttpHandlerOptions>> & diff --git a/protocol_tests/aws-restjson/commands/HttpChecksumRequiredCommand.ts b/protocol_tests/aws-restjson/commands/HttpChecksumRequiredCommand.ts new file mode 100644 index 000000000000..9861df0c26da --- /dev/null +++ b/protocol_tests/aws-restjson/commands/HttpChecksumRequiredCommand.ts @@ -0,0 +1,96 @@ +import { RestJsonProtocolClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../RestJsonProtocolClient"; +import { HttpChecksumRequiredInputOutput } from "../models/models_0"; +import { + deserializeAws_restJson1HttpChecksumRequiredCommand, + serializeAws_restJson1HttpChecksumRequiredCommand, +} from "../protocols/Aws_restJson1"; +import { getApplyMd5BodyChecksumPlugin } from "@aws-sdk/middleware-apply-body-checksum"; +import { getSerdePlugin } from "@aws-sdk/middleware-serde"; +import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http"; +import { Command as $Command } from "@aws-sdk/smithy-client"; +import { + FinalizeHandlerArguments, + Handler, + HandlerExecutionContext, + MiddlewareStack, + HttpHandlerOptions as __HttpHandlerOptions, + MetadataBearer as __MetadataBearer, + SerdeContext as __SerdeContext, +} from "@aws-sdk/types"; + +export interface HttpChecksumRequiredCommandInput extends HttpChecksumRequiredInputOutput {} +export interface HttpChecksumRequiredCommandOutput extends HttpChecksumRequiredInputOutput, __MetadataBearer {} + +/** + * This example tests httpChecksumRequired trait + * @example + * Use a bare-bones client and the command you need to make an API call. + * ```javascript + * import { RestJsonProtocolClient, HttpChecksumRequiredCommand } from "@aws-sdk/aws-restjson"; // ES Modules import + * // const { RestJsonProtocolClient, HttpChecksumRequiredCommand } = require("@aws-sdk/aws-restjson"); // CommonJS import + * const client = new RestJsonProtocolClient(config); + * const command = new HttpChecksumRequiredCommand(input); + * const response = await client.send(command); + * ``` + * + * @see {@link HttpChecksumRequiredCommandInput} for command's `input` shape. + * @see {@link HttpChecksumRequiredCommandOutput} for command's `response` shape. + * @see {@link RestJsonProtocolClientResolvedConfig | config} for command's `input` shape. + * + */ +export class HttpChecksumRequiredCommand extends $Command< + HttpChecksumRequiredCommandInput, + HttpChecksumRequiredCommandOutput, + RestJsonProtocolClientResolvedConfig +> { + // Start section: command_properties + // End section: command_properties + + constructor(readonly input: HttpChecksumRequiredCommandInput) { + // Start section: command_constructor + super(); + // End section: command_constructor + } + + /** + * @internal + */ + resolveMiddleware( + clientStack: MiddlewareStack, + configuration: RestJsonProtocolClientResolvedConfig, + options?: __HttpHandlerOptions + ): Handler { + this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize)); + this.middlewareStack.use(getApplyMd5BodyChecksumPlugin(configuration)); + + const stack = clientStack.concat(this.middlewareStack); + + const { logger } = configuration; + const clientName = "RestJsonProtocolClient"; + const commandName = "HttpChecksumRequiredCommand"; + const handlerExecutionContext: HandlerExecutionContext = { + logger, + clientName, + commandName, + inputFilterSensitiveLog: HttpChecksumRequiredInputOutput.filterSensitiveLog, + outputFilterSensitiveLog: HttpChecksumRequiredInputOutput.filterSensitiveLog, + }; + const { requestHandler } = configuration; + return stack.resolve( + (request: FinalizeHandlerArguments) => + requestHandler.handle(request.request as __HttpRequest, options || {}), + handlerExecutionContext + ); + } + + private serialize(input: HttpChecksumRequiredCommandInput, context: __SerdeContext): Promise<__HttpRequest> { + return serializeAws_restJson1HttpChecksumRequiredCommand(input, context); + } + + private deserialize(output: __HttpResponse, context: __SerdeContext): Promise { + return deserializeAws_restJson1HttpChecksumRequiredCommand(output, context); + } + + // Start section: command_body_extra + // End section: command_body_extra +} diff --git a/protocol_tests/aws-restjson/index.ts b/protocol_tests/aws-restjson/index.ts index 12efcdf0ce7f..af6cd9238166 100644 --- a/protocol_tests/aws-restjson/index.ts +++ b/protocol_tests/aws-restjson/index.ts @@ -10,6 +10,7 @@ export * from "./commands/EndpointOperationCommand"; export * from "./commands/EndpointWithHostLabelOperationCommand"; export * from "./commands/GreetingWithErrorsCommand"; export * from "./commands/HostWithPathOperationCommand"; +export * from "./commands/HttpChecksumRequiredCommand"; export * from "./commands/HttpEnumPayloadCommand"; export * from "./commands/HttpPayloadTraitsCommand"; export * from "./commands/HttpPayloadTraitsWithMediaTypeCommand"; diff --git a/protocol_tests/aws-restjson/models/models_0.ts b/protocol_tests/aws-restjson/models/models_0.ts index 087326788e4f..4f6b6084b90d 100644 --- a/protocol_tests/aws-restjson/models/models_0.ts +++ b/protocol_tests/aws-restjson/models/models_0.ts @@ -246,6 +246,19 @@ export namespace InvalidGreeting { }); } +export interface HttpChecksumRequiredInputOutput { + foo?: string; +} + +export namespace HttpChecksumRequiredInputOutput { + /** + * @internal + */ + export const filterSensitiveLog = (obj: HttpChecksumRequiredInputOutput): any => ({ + ...obj, + }); +} + export interface HttpPayloadTraitsInputOutput { foo?: string; blob?: Uint8Array; diff --git a/protocol_tests/aws-restjson/package.json b/protocol_tests/aws-restjson/package.json index 9e0ced2e8eab..44d00944c9b7 100644 --- a/protocol_tests/aws-restjson/package.json +++ b/protocol_tests/aws-restjson/package.json @@ -29,8 +29,12 @@ "@aws-crypto/sha256-js": "^1.0.0", "@aws-sdk/config-resolver": "3.23.0", "@aws-sdk/fetch-http-handler": "3.23.0", + "@aws-sdk/hash-blob-browser": "3.23.0", "@aws-sdk/hash-node": "3.23.0", + "@aws-sdk/hash-stream-node": "3.23.0", "@aws-sdk/invalid-dependency": "3.23.0", + "@aws-sdk/md5-js": "3.23.0", + "@aws-sdk/middleware-apply-body-checksum": "3.23.0", "@aws-sdk/middleware-content-length": "3.23.0", "@aws-sdk/middleware-host-header": "3.23.0", "@aws-sdk/middleware-logger": "3.23.0", diff --git a/protocol_tests/aws-restjson/protocols/Aws_restJson1.ts b/protocol_tests/aws-restjson/protocols/Aws_restJson1.ts index 8ec3b06abbde..01b290f66489 100644 --- a/protocol_tests/aws-restjson/protocols/Aws_restJson1.ts +++ b/protocol_tests/aws-restjson/protocols/Aws_restJson1.ts @@ -29,6 +29,10 @@ import { HostWithPathOperationCommandInput, HostWithPathOperationCommandOutput, } from "../commands/HostWithPathOperationCommand"; +import { + HttpChecksumRequiredCommandInput, + HttpChecksumRequiredCommandOutput, +} from "../commands/HttpChecksumRequiredCommand"; import { HttpEnumPayloadCommandInput, HttpEnumPayloadCommandOutput } from "../commands/HttpEnumPayloadCommand"; import { HttpPayloadTraitsCommandInput, HttpPayloadTraitsCommandOutput } from "../commands/HttpPayloadTraitsCommand"; import { @@ -468,6 +472,30 @@ export const serializeAws_restJson1HostWithPathOperationCommand = async ( }); }; +export const serializeAws_restJson1HttpChecksumRequiredCommand = async ( + input: HttpChecksumRequiredCommandInput, + context: __SerdeContext +): Promise<__HttpRequest> => { + const { hostname, protocol = "https", port, path: basePath } = await context.endpoint(); + const headers: any = { + "content-type": "application/json", + }; + let resolvedPath = `${basePath?.endsWith("/") ? basePath.slice(0, -1) : basePath || ""}` + "/HttpChecksumRequired"; + let body: any; + body = JSON.stringify({ + ...(input.foo !== undefined && input.foo !== null && { foo: input.foo }), + }); + return new __HttpRequest({ + protocol, + hostname, + port, + method: "POST", + headers, + path: resolvedPath, + body, + }); +}; + export const serializeAws_restJson1HttpEnumPayloadCommand = async ( input: HttpEnumPayloadCommandInput, context: __SerdeContext @@ -2089,6 +2117,53 @@ const deserializeAws_restJson1HostWithPathOperationCommandError = async ( return Promise.reject(Object.assign(new Error(message), response)); }; +export const deserializeAws_restJson1HttpChecksumRequiredCommand = async ( + output: __HttpResponse, + context: __SerdeContext +): Promise => { + if (output.statusCode !== 200 && output.statusCode >= 300) { + return deserializeAws_restJson1HttpChecksumRequiredCommandError(output, context); + } + const contents: HttpChecksumRequiredCommandOutput = { + $metadata: deserializeMetadata(output), + foo: undefined, + }; + const data: any = await parseBody(output.body, context); + if (data.foo !== undefined && data.foo !== null) { + contents.foo = __expectString(data.foo); + } + return Promise.resolve(contents); +}; + +const deserializeAws_restJson1HttpChecksumRequiredCommandError = async ( + output: __HttpResponse, + context: __SerdeContext +): Promise => { + const parsedOutput: any = { + ...output, + body: await parseBody(output.body, context), + }; + let response: __SmithyException & __MetadataBearer & { [key: string]: any }; + let errorCode: string = "UnknownError"; + errorCode = loadRestJsonErrorCode(output, parsedOutput.body); + switch (errorCode) { + default: + const parsedBody = parsedOutput.body; + errorCode = parsedBody.code || parsedBody.Code || errorCode; + response = { + ...parsedBody, + name: `${errorCode}`, + message: parsedBody.message || parsedBody.Message || errorCode, + $fault: "client", + $metadata: deserializeMetadata(output), + } as any; + } + const message = response.message || response.Message || errorCode; + response.message = message; + delete response.Message; + return Promise.reject(Object.assign(new Error(message), response)); +}; + export const deserializeAws_restJson1HttpEnumPayloadCommand = async ( output: __HttpResponse, context: __SerdeContext diff --git a/protocol_tests/aws-restjson/runtimeConfig.browser.ts b/protocol_tests/aws-restjson/runtimeConfig.browser.ts index 5fcbd11a0b85..54b32f2b6cb0 100644 --- a/protocol_tests/aws-restjson/runtimeConfig.browser.ts +++ b/protocol_tests/aws-restjson/runtimeConfig.browser.ts @@ -2,6 +2,8 @@ import packageInfo from "./package.json"; import { Sha256 } from "@aws-crypto/sha256-browser"; import { FetchHttpHandler, streamCollector } from "@aws-sdk/fetch-http-handler"; +import { blobHasher as streamHasher } from "@aws-sdk/hash-blob-browser"; +import { Md5 } from "@aws-sdk/md5-js"; import { DEFAULT_MAX_ATTEMPTS, DEFAULT_RETRY_MODE } from "@aws-sdk/middleware-retry"; import { fromBase64, toBase64 } from "@aws-sdk/util-base64-browser"; import { calculateBodyLength } from "@aws-sdk/util-body-length-browser"; @@ -26,10 +28,12 @@ export const getRuntimeConfig = (config: RestJsonProtocolClientConfig = {}) => { config.defaultUserAgentProvider ?? defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }), maxAttempts: config.maxAttempts ?? DEFAULT_MAX_ATTEMPTS, + md5: config.md5 ?? Md5, requestHandler: config.requestHandler ?? new FetchHttpHandler(), retryModeProvider: config.retryModeProvider ?? (() => Promise.resolve(DEFAULT_RETRY_MODE)), sha256: config.sha256 ?? Sha256, streamCollector: config.streamCollector ?? streamCollector, + streamHasher: config.streamHasher ?? streamHasher, utf8Decoder: config.utf8Decoder ?? fromUtf8, utf8Encoder: config.utf8Encoder ?? toUtf8, }; diff --git a/protocol_tests/aws-restjson/runtimeConfig.ts b/protocol_tests/aws-restjson/runtimeConfig.ts index 07bf6c0be5f9..eab665caa2a1 100644 --- a/protocol_tests/aws-restjson/runtimeConfig.ts +++ b/protocol_tests/aws-restjson/runtimeConfig.ts @@ -1,9 +1,11 @@ import packageInfo from "./package.json"; import { Hash } from "@aws-sdk/hash-node"; +import { fileStreamHasher as streamHasher } from "@aws-sdk/hash-stream-node"; import { NODE_MAX_ATTEMPT_CONFIG_OPTIONS, NODE_RETRY_MODE_CONFIG_OPTIONS } from "@aws-sdk/middleware-retry"; import { loadConfig as loadNodeConfig } from "@aws-sdk/node-config-provider"; import { NodeHttpHandler, streamCollector } from "@aws-sdk/node-http-handler"; +import { HashConstructor as __HashConstructor } from "@aws-sdk/types"; import { fromBase64, toBase64 } from "@aws-sdk/util-base64-node"; import { calculateBodyLength } from "@aws-sdk/util-body-length-node"; import { defaultUserAgent } from "@aws-sdk/util-user-agent-node"; @@ -29,10 +31,12 @@ export const getRuntimeConfig = (config: RestJsonProtocolClientConfig = {}) => { config.defaultUserAgentProvider ?? defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }), maxAttempts: config.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS), + md5: config.md5 ?? Hash.bind(null, "md5"), requestHandler: config.requestHandler ?? new NodeHttpHandler(), retryModeProvider: config.retryModeProvider ?? loadNodeConfig(NODE_RETRY_MODE_CONFIG_OPTIONS), sha256: config.sha256 ?? Hash.bind(null, "sha256"), streamCollector: config.streamCollector ?? streamCollector, + streamHasher: config.streamHasher ?? streamHasher, utf8Decoder: config.utf8Decoder ?? fromUtf8, utf8Encoder: config.utf8Encoder ?? toUtf8, }; diff --git a/protocol_tests/aws-restjson/tests/functional/restjson1.spec.ts b/protocol_tests/aws-restjson/tests/functional/restjson1.spec.ts index 9afefcbf6978..2502ca656a45 100644 --- a/protocol_tests/aws-restjson/tests/functional/restjson1.spec.ts +++ b/protocol_tests/aws-restjson/tests/functional/restjson1.spec.ts @@ -9,6 +9,7 @@ import { EndpointOperationCommand } from "../../commands/EndpointOperationComman import { EndpointWithHostLabelOperationCommand } from "../../commands/EndpointWithHostLabelOperationCommand"; import { GreetingWithErrorsCommand } from "../../commands/GreetingWithErrorsCommand"; import { HostWithPathOperationCommand } from "../../commands/HostWithPathOperationCommand"; +import { HttpChecksumRequiredCommand } from "../../commands/HttpChecksumRequiredCommand"; import { HttpEnumPayloadCommand } from "../../commands/HttpEnumPayloadCommand"; import { HttpPayloadTraitsCommand } from "../../commands/HttpPayloadTraitsCommand"; import { HttpPayloadTraitsWithMediaTypeCommand } from "../../commands/HttpPayloadTraitsWithMediaTypeCommand"; @@ -1891,6 +1892,47 @@ it("RestJsonHostWithPath:Request", async () => { } }); +/** + * Adds Content-MD5 header + */ +it("RestJsonHttpChecksumRequired:Request", async () => { + const client = new RestJsonProtocolClient({ + ...clientParams, + requestHandler: new RequestSerializationTestHandler(), + }); + + const command = new HttpChecksumRequiredCommand({ + foo: "base64 encoded md5 checksum", + } as any); + try { + await client.send(command); + fail("Expected an EXPECTED_REQUEST_SERIALIZATION_ERROR to be thrown"); + return; + } catch (err) { + if (!(err instanceof EXPECTED_REQUEST_SERIALIZATION_ERROR)) { + fail(err); + return; + } + const r = err.request; + expect(r.method).toBe("POST"); + expect(r.path).toBe("/HttpChecksumRequired"); + + expect(r.headers["content-md5"]).toBeDefined(); + expect(r.headers["content-md5"]).toBe("iB0/3YSo7maijL0IGOgA9g=="); + expect(r.headers["content-type"]).toBeDefined(); + expect(r.headers["content-type"]).toBe("application/json"); + + expect(r.body).toBeDefined(); + const utf8Encoder = client.config.utf8Encoder; + const bodyString = `{ + \"foo\":\"base64 encoded md5 checksum\" + } + `; + const unequalParts: any = compareEquivalentJsonBodies(bodyString, r.body.toString()); + expect(unequalParts).toBeUndefined(); + } +}); + it("EnumPayloadRequest:Request", async () => { const client = new RestJsonProtocolClient({ ...clientParams, diff --git a/protocol_tests/aws-restxml/tests/functional/restxml.spec.ts b/protocol_tests/aws-restxml/tests/functional/restxml.spec.ts index d6228670477e..b5befa7e80bf 100644 --- a/protocol_tests/aws-restxml/tests/functional/restxml.spec.ts +++ b/protocol_tests/aws-restxml/tests/functional/restxml.spec.ts @@ -3746,7 +3746,7 @@ it("SimpleScalarPropertiesWithWhiteSpace:Request", async () => { const command = new SimpleScalarPropertiesCommand({ foo: "Foo", - stringValue: "string with white space", + stringValue: " string with white space ", } as any); try { await client.send(command); @@ -3769,7 +3769,50 @@ it("SimpleScalarPropertiesWithWhiteSpace:Request", async () => { expect(r.body).toBeDefined(); const utf8Encoder = client.config.utf8Encoder; const bodyString = ` - string with white space + string with white space + + `; + const unequalParts: any = compareEquivalentXmlBodies(bodyString, r.body.toString()); + expect(unequalParts).toBeUndefined(); + } +}); + +/** + * Serializes string containing exclusively whitespace + */ +it.skip("SimpleScalarPropertiesPureWhiteSpace:Request", async () => { + const client = new RestXmlProtocolClient({ + ...clientParams, + requestHandler: new RequestSerializationTestHandler(), + }); + + const command = new SimpleScalarPropertiesCommand({ + foo: "Foo", + + stringValue: " ", + } as any); + try { + await client.send(command); + fail("Expected an EXPECTED_REQUEST_SERIALIZATION_ERROR to be thrown"); + return; + } catch (err) { + if (!(err instanceof EXPECTED_REQUEST_SERIALIZATION_ERROR)) { + fail(err); + return; + } + const r = err.request; + expect(r.method).toBe("PUT"); + expect(r.path).toBe("/SimpleScalarProperties"); + + expect(r.headers["content-type"]).toBeDefined(); + expect(r.headers["content-type"]).toBe("application/xml"); + expect(r.headers["x-foo"]).toBeDefined(); + expect(r.headers["x-foo"]).toBe("Foo"); + + expect(r.body).toBeDefined(); + const utf8Encoder = client.config.utf8Encoder; + const bodyString = ` + `; const unequalParts: any = compareEquivalentXmlBodies(bodyString, r.body.toString()); @@ -4127,7 +4170,52 @@ it("SimpleScalarPropertiesWithWhiteSpace:Response", async () => { }, ` - string with white space + string with white space + + ` + ), + }); + + const params: any = {}; + const command = new SimpleScalarPropertiesCommand(params); + + let r: any; + try { + r = await client.send(command); + } catch (err) { + fail("Expected a valid response to be returned, got err."); + return; + } + expect(r["$metadata"].httpStatusCode).toBe(200); + const paramsToValidate: any = [ + { + foo: "Foo", + + stringValue: " string with white space ", + }, + ][0]; + Object.keys(paramsToValidate).forEach((param) => { + expect(r[param]).toBeDefined(); + expect(equivalentContents(r[param], paramsToValidate[param])).toBe(true); + }); +}); + +/** + * Serializes string containing white space + */ +it.skip("SimpleScalarPropertiesPureWhiteSpace:Response", async () => { + const client = new RestXmlProtocolClient({ + ...clientParams, + requestHandler: new ResponseDeserializationTestHandler( + true, + 200, + { + "x-foo": "Foo", + "content-type": "application/xml", + }, + ` + + ` ), @@ -4148,7 +4236,7 @@ it("SimpleScalarPropertiesWithWhiteSpace:Response", async () => { { foo: "Foo", - stringValue: "string with white space", + stringValue: " ", }, ][0]; Object.keys(paramsToValidate).forEach((param) => {