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(jwt) remove unique constraint on secret #2548

Merged
merged 1 commit into from
May 26, 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
2 changes: 1 addition & 1 deletion kong/plugins/jwt/daos.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local SCHEMA = {
created_at = {type = "timestamp", immutable = true, dao_insert_value = true},
consumer_id = {type = "id", required = true, foreign = "consumers:id"},
key = {type = "string", unique = true, default = utils.random_string},
secret = {type = "string", unique = true, default = utils.random_string},
secret = {type = "string", default = utils.random_string},
rsa_public_key = {type = "string"},
algorithm = {type = "string", enum = {"HS256", "RS256", "ES256"}, default = 'HS256'}
},
Expand Down
9 changes: 9 additions & 0 deletions kong/plugins/jwt/migrations/postgres.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,14 @@ return {
ALTER TABLE jwt_secrets DROP COLUMN algorithm;
ALTER TABLE jwt_secrets DROP COLUMN rsa_public_key;
]]
},
{
name = "2017-05-22-jwt_secret_not_unique",
up = [[
ALTER TABLE jwt_secrets DROP CONSTRAINT IF EXISTS jwt_secrets_secret_key;
]],
down = [[
ALTER TABLE jwt_secrets ADD CONSTRAINT jwt_secrets_secret_key UNIQUE(secret);
]],
}
}
40 changes: 39 additions & 1 deletion spec/03-plugins/17-jwt/02-api_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ describe("Plugin: jwt (API)", function()
consumer = assert(helpers.dao.consumers:insert {
username = "bob"
})
assert(helpers.dao.consumers:insert {
username = "alice"
})
end)

describe("POST", function()
Expand Down Expand Up @@ -60,6 +63,41 @@ describe("Plugin: jwt (API)", function()
assert.equal("tooshort", body.secret)
jwt2 = body
end)
it("accepts duplicate `secret` parameters across jwt_secrets", function()
local res = assert(admin_client:send {
method = "POST",
path = "/consumers/alice/jwt/",
body = {
key = "alice",
secret = "foobarbaz"
},
headers = {
["Content-Type"] = "application/json"
}
})
local body = cjson.decode(assert.res_status(201, res))
assert.equal("alice", body.key)
assert.equal("foobarbaz", body.secret)
jwt1 = body

res = assert(admin_client:send {
method = "POST",
path = "/consumers/bob/jwt/",
body = {
key = "bobsyouruncle",
secret = "foobarbaz"
},
headers = {
["Content-Type"] = "application/json"
}
})
body = cjson.decode(assert.res_status(201, res))
assert.equal("bobsyouruncle", body.key)
assert.equal("foobarbaz", body.secret)
jwt2 = body

assert.equals(jwt1.secret, jwt2.secret)
end)
it("accepts a valid public key for RS256 when posted urlencoded", function()
local rsa_public_key = fixtures.rs256_public_key
rsa_public_key = rsa_public_key:gsub("\n", "\r\n")
Expand Down Expand Up @@ -180,7 +218,7 @@ describe("Plugin: jwt (API)", function()
path = "/consumers/bob/jwt/",
})
local body = cjson.decode(assert.res_status(200, res))
assert.equal(4, #(body.data))
assert.equal(6, #(body.data))
end)
end)
end)
Expand Down