From f8e5fb502c2ec78403656346feb60fcf269c9238 Mon Sep 17 00:00:00 2001 From: George Fu Date: Wed, 26 Apr 2023 00:37:41 +0000 Subject: [PATCH] fix(sqs): adapt to protocol change in sqs --- .../next-release/feature-SQS-943e34bf.json | 5 ++ lib/services/sqs.js | 5 +- test/services/sqs.spec.js | 50 +++++++++++++++++-- 3 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 .changes/next-release/feature-SQS-943e34bf.json diff --git a/.changes/next-release/feature-SQS-943e34bf.json b/.changes/next-release/feature-SQS-943e34bf.json new file mode 100644 index 0000000000..dcb1685713 --- /dev/null +++ b/.changes/next-release/feature-SQS-943e34bf.json @@ -0,0 +1,5 @@ +{ + "type": "feature", + "category": "SQS", + "description": "handle XML/JSON protocol change in SQS tests" +} \ No newline at end of file diff --git a/lib/services/sqs.js b/lib/services/sqs.js index 42aaf2ec1f..6fdca05052 100644 --- a/lib/services/sqs.js +++ b/lib/services/sqs.js @@ -5,7 +5,7 @@ AWS.util.update(AWS.SQS.prototype, { * @api private */ setupRequestListeners: function setupRequestListeners(request) { - request.addListener('build', this.buildEndpoint); + request.addListener('build', this.buildEndpoint.bind(this)); if (request.service.config.computeChecksums) { if (request.operation === 'sendMessage') { @@ -118,7 +118,8 @@ AWS.util.update(AWS.SQS.prototype, { * @api private */ buildEndpoint: function buildEndpoint(request) { - var url = request.httpRequest.params.QueueUrl; + var params = request.httpRequest.params || this.config.params; + var url = params.QueueUrl; if (url) { request.httpRequest.endpoint = new AWS.Endpoint(url); diff --git a/test/services/sqs.spec.js b/test/services/sqs.spec.js index 28eea59375..2fbefff687 100644 --- a/test/services/sqs.spec.js +++ b/test/services/sqs.spec.js @@ -1,4 +1,6 @@ -// Generated by CoffeeScript 1.12.3 +var sqsModel = require('../../apis/sqs-2012-11-05.min.json'); +var isJsonProtocol = sqsModel.metadata.protocol === 'json'; + (function() { var AWS, helpers; @@ -7,8 +9,7 @@ AWS = helpers.AWS; describe('AWS.SQS', function() { - var checksumValidate, sqs; - sqs = null; + var sqs = null; beforeEach(function() { return sqs = new AWS.SQS({ params: { @@ -16,10 +17,13 @@ } }); }); - checksumValidate = function(operation, input, response, shouldPass, cb) { + var checksumValidate = function(operation, input, response, shouldPass, cb) { helpers.mockHttpResponse(200, {}, response); return sqs[operation](input).send(function(err, data) { if (shouldPass) { + if (err !== null) { + throw err; + } expect(err).to.equal(null); } else { expect(err).not.to.equal(null); @@ -51,6 +55,12 @@ }; md5 = 'acbd18db4cc2f85cedef654fccc4a4d8'; payload = function(md5) { + if (isJsonProtocol) { + return JSON.stringify({ + MD5OfMessageBody: md5, + MessageId: 'MSGID', + }, null, 2); + } return '\n ' + md5 + '\n MSGID\n'; }; it('correctly validates MD5 of message input', function(done) { @@ -92,6 +102,27 @@ md5foo = 'acbd18db4cc2f85cedef654fccc4a4d8'; md5bar = '37b51d194a7513e45b56f6524f2d51f2'; payload = function(md5a, md5b, md5c) { + if (isJsonProtocol) { + return JSON.stringify({ + Successful: [ + { + Id: 'a', + MessageId: 'MSGID1', + MD5OfMessageBody: md5a + }, + { + Id: 'b', + MessageId: 'MSGID2', + MD5OfMessageBody: md5b + }, + { + Id: 'c', + MessageId: 'MSGID3', + MD5OfMessageBody: md5c + } + ] + }, null, 2); + } return '\n \n a\n MSGID1\n ' + md5a + '\n \n \n b\n MSGID2\n ' + md5b + '\n \n \n c\n MSGID3\n ' + md5c + '\n \n'; }; it('correctly validates MD5 of operation', function(done) { @@ -126,6 +157,17 @@ var md5, payload; md5 = 'acbd18db4cc2f85cedef654fccc4a4d8'; payload = function(body, md5, id) { + if (isJsonProtocol) { + return JSON.stringify({ + Messages: [ + { + Body: body, + MD5OfBody: md5, + MessageId: id + } + ] + }, null, 2); + } return '\n ' + body + '\n ' + md5 + '\n ' + id + '\n'; }; it('correctly validates MD5 of operation', function(done) {