From 2121263945758397bf43240089f0b7df79a3720e Mon Sep 17 00:00:00 2001 From: Xiaoyan Rao <270668624@qq.com> Date: Tue, 25 Jun 2024 14:54:58 +0800 Subject: [PATCH] add test cases --- spec/02-integration/03-db/14-dao_spec.lua | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/spec/02-integration/03-db/14-dao_spec.lua b/spec/02-integration/03-db/14-dao_spec.lua index 313ebd9bd650..21c481faf6bc 100644 --- a/spec/02-integration/03-db/14-dao_spec.lua +++ b/spec/02-integration/03-db/14-dao_spec.lua @@ -16,6 +16,7 @@ for _, strategy in helpers.all_strategies() do "services", "consumers", "acls", + "keyauth_credentials", }) _G.kong.db = db @@ -98,6 +99,7 @@ for _, strategy in helpers.all_strategies() do db.consumers:truncate() db.plugins:truncate() db.services:truncate() + db.keyauth_credentials:truncate() end) it("select_by_cache_key()", function() @@ -185,6 +187,33 @@ for _, strategy in helpers.all_strategies() do assert.same(new_plugin_config.config.redis.host, read_plugin.config.redis.host) assert.same(new_plugin_config.config.redis.host, read_plugin.config.redis_host) -- legacy field is included end) + + it("keyauth_credentials can be deleted or selected before run ttl cleanup in background timer", function() + local b_keyauth_credentials = bp.keyauth_credentials:insert({ + consumer = { id = consumer.id }, + }, { ttl = 5 }) + + -- wait for 5 seconds. + ngx.sleep(5) + + -- select or delete keyauth_credentials after ttl expired. + + local expired_keyauth_credentials = bp.keyauth_credentials:select({ consumer = { id = consumer.id } }) + assert.is_nil(expired_keyauth_credentials) + bp.keyauth_credentials:delete({ consumer = { id = consumer.id } }) + + -- select or delete keyauth_credentials with skip_ttl=true after ttl expired. + expired_keyauth_credentials = bp.keyauth_credentials:select({ consumer = { id = consumer.id } }, + { skip_ttl = true }) + assert.not_nil(expired_keyauth_credentials) + assert.same(expired_keyauth_credentials.id, b_keyauth_credentials.id) + bp.keyauth_credentials:delete({ consumer = { id = consumer.id } }, { skip_ttl = true }) + + -- check again + expired_keyauth_credentials = bp.keyauth_credentials:select({ consumer = { id = consumer.id } }, + { skip_ttl = true }) + assert.is_nil(expired_keyauth_credentials) + end) end) end