Skip to content

Commit

Permalink
extends test to validate unique random keys (#1385)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske authored Jul 20, 2016
1 parent 05db709 commit e779ca6
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions spec/03-plugins/key-auth/01-api_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,24 @@ describe("Plugin: key-auth (API)", function()
assert.equal(consumer.id, json.consumer_id)
assert.equal("1234", json.key)
end)
it("creates a key-auth auto-generating the key", function()
local res = assert(admin_client:send {
it("creates a key-auth auto-generating a unique key", function()
local res = assert(admin_client:send {
method = "POST",
path = "/consumers/bob/key-auth",
body = {},
headers = {
["Content-Type"] = "application/json"
}
})
local body = assert.res_status(201, res)
local json = cjson.decode(body)
assert.equal(consumer.id, json.consumer_id)
assert.is_string(json.key)

local first_key = json.key
helpers.dao:truncate_table("keyauth_credentials")

local res = assert(admin_client:send {
method = "POST",
path = "/consumers/bob/key-auth",
body = {},
Expand All @@ -53,6 +69,8 @@ describe("Plugin: key-auth (API)", function()
local json = cjson.decode(body)
assert.equal(consumer.id, json.consumer_id)
assert.is_string(json.key)

assert.not_equal(first_key, json.key)
end)
end)

Expand Down

1 comment on commit e779ca6

@thibaultcha
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests(key-auth) extend unique random keys test case

Please sign in to comment.