Skip to content

Commit

Permalink
fix(*): fix AWS_CONTAINER_CREDENTIALS_FULL_URI parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
windmgc committed Jul 27, 2023
1 parent d2a24c3 commit 080f5f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion spec/03-credentials/04-RemoteCredentials_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ describe("RemoteCredentials", function()
end)



it("fetches credentials", function()
local cred = RemoteCredentials:new()
local success, key, secret, token = cred:get()
Expand All @@ -61,3 +60,28 @@ describe("RemoteCredentials", function()
end)

end)


describe("RemoteCredentials with customized full URI", function ()
it("fetches credentials", function ()
local RemoteCredentials

restore()
restore.setenv("AWS_CONTAINER_CREDENTIALS_FULL_URI", "http://localhost:12345/test/path")

local _ = require("resty.aws.config").global -- load config before mocking http client
package.loaded["resty.luasocket.http"] = http

RemoteCredentials = require "resty.aws.credentials.RemoteCredentials"
finally(function()
restore()
end)

local cred = RemoteCredentials:new()
local success, key, secret, token = cred:get()
assert.equal(true, success)
assert.equal("access", key)
assert.equal("secret", secret)
assert.equal("token", token)
end)
end)
2 changes: 1 addition & 1 deletion src/resty/aws/credentials/RemoteCredentials.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ local FullUri do
end

if (not FULL_URI_UNRESTRICTED_PROTOCOLS[parsed_url.scheme]) and
(not FULL_URI_ALLOWED_HOSTNAMES[parsed_url.hostname]) then
(not FULL_URI_ALLOWED_HOSTNAMES[parsed_url.host]) then
return nil, 'Unsupported hostname: AWS.RemoteCredentials only supports '
.. table.concat(FULL_URI_ALLOWED_HOSTNAMES, ',') .. ' for '
.. parsed_url.scheme .. '; ' .. parsed_url.scheme .. '://'
Expand Down

0 comments on commit 080f5f8

Please sign in to comment.