Skip to content

Commit e918c4a

Browse files
authored
fix(*): fix AWS_CONTAINER_CREDENTIALS_FULL_URI parsing (#65)
The RemoteCredential does not support a full URI with port number now, the error log shows as follow: ``` 2023/07/27 15:48:41 [debug] 46876#0: [lua] RemoteCredentials.lua:70: Failed to construct RemoteCredentials url: Unsupported hostname: AWS.RemoteCredentials only supports localhost,127.0.0.1 for http; http://localhost requested. ``` It seems that the code is using wrong reference for host, it should be host instead of hostname. The document of socket.url.parse: ``` url.parse(url, default) Parses an URL given as a string into a Lua table with its components. Url is the URL to be parsed. If the default table is present, it is used to store the parsed fields. Only fields present in the URL are overwritten. Therefore, this table can be used to pass default values for each field. The function returns a table with all the URL components: parsed_url = { url = string, scheme = string, authority = string, path = string, params = string, query = string, fragment = string, userinfo = string, host = string, port = string, user = string, password = string } ```
1 parent d2a24c3 commit e918c4a

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ Release process:
166166
1. upload using: `VERSION=x.y.z APIKEY=abc... make upload`
167167
1. test installing the rock from LuaRocks
168168

169+
### Unreleased
170+
171+
- fix: fix AWS_CONTAINER_CREDENTIALS_FULL_URI parsing.
172+
[#65](https://github.com/Kong/lua-resty-aws/pull/65)
173+
169174
### 1.2.3 (20-Jul-2023)
170175

171176
- fix: fix assumeRole function name on STS.

spec/03-credentials/04-RemoteCredentials_spec.lua

+25-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ describe("RemoteCredentials", function()
5050
end)
5151

5252

53-
5453
it("fetches credentials", function()
5554
local cred = RemoteCredentials:new()
5655
local success, key, secret, token = cred:get()
@@ -61,3 +60,28 @@ describe("RemoteCredentials", function()
6160
end)
6261

6362
end)
63+
64+
65+
describe("RemoteCredentials with customized full URI", function ()
66+
it("fetches credentials", function ()
67+
local RemoteCredentials
68+
69+
restore()
70+
restore.setenv("AWS_CONTAINER_CREDENTIALS_FULL_URI", "http://localhost:12345/test/path")
71+
72+
local _ = require("resty.aws.config").global -- load config before mocking http client
73+
package.loaded["resty.luasocket.http"] = http
74+
75+
RemoteCredentials = require "resty.aws.credentials.RemoteCredentials"
76+
finally(function()
77+
restore()
78+
end)
79+
80+
local cred = RemoteCredentials:new()
81+
local success, key, secret, token = cred:get()
82+
assert.equal(true, success)
83+
assert.equal("access", key)
84+
assert.equal("secret", secret)
85+
assert.equal("token", token)
86+
end)
87+
end)

src/resty/aws/credentials/RemoteCredentials.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ local FullUri do
4848
end
4949

5050
if (not FULL_URI_UNRESTRICTED_PROTOCOLS[parsed_url.scheme]) and
51-
(not FULL_URI_ALLOWED_HOSTNAMES[parsed_url.hostname]) then
51+
(not FULL_URI_ALLOWED_HOSTNAMES[parsed_url.host]) then
5252
return nil, 'Unsupported hostname: AWS.RemoteCredentials only supports '
5353
.. table.concat(FULL_URI_ALLOWED_HOSTNAMES, ',') .. ' for '
5454
.. parsed_url.scheme .. '; ' .. parsed_url.scheme .. '://'

0 commit comments

Comments
 (0)