-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(http-log) Add basic auth header if credentials provided (Kong#2432)
* Add Authorization header if userinfo is present * test(http-log) test Authorization header
- Loading branch information
Showing
3 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ end | |
|
||
local mock_bin_http = create_mock_bin() | ||
local mock_bin_https = create_mock_bin() | ||
local mock_bin_http_basic_auth = create_mock_bin() | ||
|
||
describe("Plugin: http-log (log)", function() | ||
local client | ||
|
@@ -54,7 +55,21 @@ describe("Plugin: http-log (log)", function() | |
} | ||
}) | ||
|
||
local api3 = assert(helpers.dao.apis:insert { | ||
name = "api-3", | ||
hosts = { "http_basic_auth_logging.com" }, | ||
upstream_url = "http://mockbin.com" | ||
}) | ||
assert(helpers.dao.plugins:insert { | ||
api_id = api3.id, | ||
name = "http-log", | ||
config = { | ||
http_endpoint = "http://testuser:[email protected]/bin/"..mock_bin_http_basic_auth | ||
} | ||
}) | ||
|
||
assert(helpers.start_kong()) | ||
|
||
end) | ||
teardown(function() | ||
helpers.stop_kong() | ||
|
@@ -124,4 +139,36 @@ describe("Plugin: http-log (log)", function() | |
end | ||
end, 10) | ||
end) | ||
|
||
it("adds authorization if userinfo is present", function() | ||
local res = assert(client:send({ | ||
method = "GET", | ||
path = "/status/200", | ||
headers = { | ||
["Host"] = "http_basic_auth_logging.com" | ||
} | ||
})) | ||
assert.res_status(200, res) | ||
|
||
helpers.wait_until(function() | ||
local client = assert(helpers.http_client(mockbin_ip, 80)) | ||
local res = assert(client:send { | ||
method = "GET", | ||
path = "/bin/"..mock_bin_http_basic_auth.."/log", | ||
headers = { | ||
Host = "mockbin.org", | ||
Accept = "application/json" | ||
} | ||
}) | ||
local body = cjson.decode(assert.res_status(200, res)) | ||
if #body.log.entries == 1 then | ||
for key, value in pairs(body.log.entries[1].request.headers) do | ||
if value.name == "authorization" then | ||
assert.same("Basic dGVzdHVzZXI6dGVzdHBhc3N3b3Jk", value.value) | ||
return true | ||
end | ||
end | ||
end | ||
end, 10) | ||
end) | ||
end) |