Skip to content

Commit

Permalink
Merge pull request #2158 from Mashape/fix/hmac_default_key
Browse files Browse the repository at this point in the history
fix(hmac-auth) generate a credential secret if none provided
  • Loading branch information
p0pr0ck5 authored Mar 14, 2017
2 parents 91267eb + 31af708 commit 7f9d342
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
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

0 comments on commit 7f9d342

Please sign in to comment.