Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hmac-auth) generate a credential secret if none provided #2158

Merged
merged 1 commit into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
## [Unreleased][unreleased]

## [0.10.0] - 2017/03/07
### Fixed

- Plugins:
- hmac: generate an HMAC secret value if none is provided.
[#2158](https://github.com/Mashape/kong/pull/2158)


## [0.10.0] - 2016/03/07

Kong 0.10 is one of most significant releases to this day. It ships with
exciting new features that have been havily requested for the last few months,
Expand Down
4 changes: 3 additions & 1 deletion kong/plugins/hmac-auth/daos.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local utils = require "kong.tools.utils"

local SCHEMA = {
primary_key = {"id"},
table = "hmacauth_credentials",
Expand All @@ -6,7 +8,7 @@ local SCHEMA = {
created_at = {type = "timestamp", immutable = true, dao_insert_value = true},
consumer_id = {type = "id", required = true, foreign = "consumers:id"},
username = {type = "string", required = true, unique = true},
secret = {type = "string"}
secret = {type = "string", default = utils.random_string}
},
marshall_event = function(self, t)
return {id = t.id, consumer_id = t.consumer_id, username = t.username}
Expand Down
14 changes: 14 additions & 0 deletions spec/03-plugins/20-hmac-auth/02-api_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ describe("Plugin: hmac-auth (API)", function()
credential = cjson.decode(body)
assert.equal(consumer.id, credential.consumer_id)
end)
it("[SUCCESS] should create a hmac-auth credential with a random secret", function()
local res = assert(client:send {
method = "POST",
path = "/consumers/bob/hmac-auth/",
body = {
username = "bob",
},
headers = {["Content-Type"] = "application/json"}
})

local body = assert.res_status(201, res)
credential = cjson.decode(body)
assert.is.not_nil(credential.secret)
end)
it("[FAILURE] should return proper errors", function()
local res = assert(client:send {
method = "POST",
Expand Down