From e779ca67c49639dff6e2d3129ad94199787e8186 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Thu, 21 Jul 2016 00:02:50 +0200 Subject: [PATCH] extends test to validate unique random keys (#1385) --- spec/03-plugins/key-auth/01-api_spec.lua | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/spec/03-plugins/key-auth/01-api_spec.lua b/spec/03-plugins/key-auth/01-api_spec.lua index 648ccc9cd16..8645876a79c 100644 --- a/spec/03-plugins/key-auth/01-api_spec.lua +++ b/spec/03-plugins/key-auth/01-api_spec.lua @@ -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 = {}, @@ -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)