From 1ffb85478a25b4cc93ca64899b34dc89d91dc3bc Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Fri, 14 Jun 2024 12:33:31 +0200 Subject: [PATCH 1/2] fix(request): unspecified location goes in body, also for blob previously a "blob" type without location given would be added as a nested data element which was incorrect. --- README.md | 5 +++++ src/resty/aws/request/build.lua | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ab06a1d..d0598e8 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,11 @@ Release process: 1. test installing the rock from LuaRocks +### 1.x.x unreleased + +- fix: when a "blob" type has no location specified, then use it as the body, same as with other types. + [120](https://github.com/Kong/lua-resty-aws/pull/120) + ### 1.5.0 (20-May-2024) - feat: decode AWS api response json body with array metatable diff --git a/src/resty/aws/request/build.lua b/src/resty/aws/request/build.lua index d2bcef2..22b78f6 100644 --- a/src/resty/aws/request/build.lua +++ b/src/resty/aws/request/build.lua @@ -187,8 +187,6 @@ local function build_request(operation, config, params) if config.protocol == "query" then -- no location specified, but protocol is query, so it goes into query request.query[name] = param_value - elseif member_config.type == "blob" then - request.body = param_value else -- nowhere else to go, so put it in the body (for json and xml) body_tbl[name] = param_value From b07928dc7c61a1a27aba8292c70474b28d1d3323 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Mon, 17 Jun 2024 13:13:39 +0200 Subject: [PATCH 2/2] added to testcase --- spec/02-requests/02-build_request_spec.lua | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/spec/02-requests/02-build_request_spec.lua b/spec/02-requests/02-build_request_spec.lua index 6a0d58b..6c6e55f 100644 --- a/spec/02-requests/02-build_request_spec.lua +++ b/spec/02-requests/02-build_request_spec.lua @@ -9,6 +9,7 @@ describe("operations protocol", function() local config local params local snapshot + local binary_data setup(function() snapshot = assert:snapshot() @@ -26,6 +27,8 @@ describe("operations protocol", function() before_each(function() + binary_data = "abcd" --"\00\01\02\03" + operation = { name = "AssumeRole", http = { @@ -76,6 +79,9 @@ describe("operations protocol", function() RoleSessionName = { type = "string", }, + BinaryData = { + type = "blob", + }, subStructure = { locationName = "someSubStructure", type = "structure", @@ -124,7 +130,8 @@ describe("operations protocol", function() hello = "the default hello thinghy", world = "the default world thinghy" }, - subList = { 1, 2 ,3, } + subList = { 1, 2 ,3, }, + BinaryData = binary_data, } end) @@ -164,6 +171,7 @@ describe("operations protocol", function() Action = "AssumeRole", Version = "2011-06-15", nice = '', + BinaryData = binary_data, } }, request) end) @@ -182,7 +190,7 @@ describe("operations protocol", function() assert.same({ headers = { ["X-Sooper-Secret"] = "towel", - ["Content-Length"] = 152, + ["Content-Length"] = 172, ["Content-Type"] = "application/x-amz-json-1.0", ["X-Amz-Target"] = "sts.AssumeRole", ["Host"] = "sts.amazonaws.com", @@ -199,11 +207,12 @@ describe("operations protocol", function() subList = { 1,2,3 }, RoleArn = "hello", RoleSessionName = "world", + BinaryData = binary_data, }, query = { UserId = "Arthur Dent", nice = '', - } + }, }, request) end) @@ -221,7 +230,7 @@ describe("operations protocol", function() assert.same({ headers = { ["X-Sooper-Secret"] = "towel", - ["Content-Length"] = 152, + ["Content-Length"] = 172, ["Content-Type"] = "application/x-amz-json-1.0", ["X-Amz-Target"] = "sts.AssumeRole", ["Host"] = "sts.amazonaws.com", @@ -238,6 +247,7 @@ describe("operations protocol", function() subList = { 1,2,3 }, RoleArn = "hello", RoleSessionName = "world", + BinaryData = binary_data, }, query = { UserId = "Arthur Dent", @@ -280,7 +290,7 @@ describe("operations protocol", function() assert.same({ headers = { ["X-Sooper-Secret"] = "towel", - ["Content-Length"] = 424, + ["Content-Length"] = 456, ["Content-Type"] = "application/xml", ["X-Amz-Target"] = "sts.AssumeRole", ["Host"] = "sts.amazonaws.com", @@ -294,6 +304,8 @@ describe("operations protocol", function() [1] = 'hello' }, RoleSessionName = { [1] = 'world' }, + BinaryData = { + [1] = binary_data }, attr = { [1] = 'xmlns', xmlns = 'cool-name-space' },