Skip to content

Commit

Permalink
fix test-access-token tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-smile committed Oct 9, 2023
1 parent fe89232 commit 284bb16
Showing 1 changed file with 6 additions and 47 deletions.
53 changes: 6 additions & 47 deletions src/apisix/editions/ee/tests/bk-cache/test-access-token.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,22 @@
-- to the current version of the project delivered to anyone in the future.
--
local access_token_cache = require("apisix.plugins.bk-cache.access-token")
local bkauth_component = require("apisix.plugins.bk-components.bkauth")
local ssm_component = require("apisix.plugins.bk-components.ssm")
local uuid = require("resty.jit-uuid")

describe(
"access_token cache", function()

local bkauth_verify_access_token_result
local bkauth_verify_access_token_err
local ssm_verify_access_token_result
local ssm_verify_access_token_err
local ssm_is_configured

before_each(
function()
bkauth_verify_access_token_result = nil
bkauth_verify_access_token_err = nil
ssm_verify_access_token_result = nil
ssm_verify_access_token_err = nil
ssm_is_configured = false

stub(
bkauth_component, "verify_access_token", function()
return bkauth_verify_access_token_result, bkauth_verify_access_token_err
end
)

stub(
ssm_component, "verify_access_token", function()
return ssm_verify_access_token_result, ssm_verify_access_token_err
Expand All @@ -59,39 +48,15 @@ describe(

after_each(
function()
bkauth_component.verify_access_token:revert()
ssm_component.verify_access_token:revert()
ssm_component.is_configured:revert()
end
)

context(
"local get_access_token", function()
-- it(
-- "bkauth verify ok", function()
-- bkauth_verify_access_token_result = {
-- bk_app_code = "my-app",
-- username = "admin",
-- expires_in = 10,
-- }
-- bkauth_verify_access_token_err = nil

-- local result = access_token_cache._get_access_token("fake-access-token")
-- assert.is_same(
-- result.token, {
-- app_code = "my-app",
-- user_id = "admin",
-- expires_in = 10,
-- }
-- )
-- assert.is_nil(result.err)
-- end
-- )

it(
"bkauth verify fail, ssm verify ok", function()
bkauth_verify_access_token_result = nil
bkauth_verify_access_token_err = "bkauth err"
"ssm verify ok", function()
ssm_verify_access_token_result = {
bk_app_code = "my-foo",
username = "kitty",
Expand All @@ -113,9 +78,7 @@ describe(
)

it(
"bkauth verify fail, ssm verify fail", function()
bkauth_verify_access_token_result = nil
bkauth_verify_access_token_err = "bkauth error"
"ssm verify fail, and is configured", function()
ssm_verify_access_token_result = nil
ssm_verify_access_token_err = "ssm error"
ssm_is_configured = true
Expand All @@ -127,23 +90,19 @@ describe(
)

it(
"bkauth verify fail, ssm is not configured", function()
bkauth_verify_access_token_result = nil
bkauth_verify_access_token_err = "bkauth error"
"ssm verify fail, but not configured", function()
ssm_verify_access_token_result = nil
ssm_verify_access_token_err = "ssm error"
ssm_is_configured = nil

local result = access_token_cache._get_access_token("fake-access-token")
assert.is_nil(result.token)
-- assert.is_equal(result.err, "bkauth error")
assert.is_equal(result.err, "authentication based on access_token is not supported")
end
)

it(
"bkauth verify fail, ssm is not configured", function()
bkauth_verify_access_token_result = nil
bkauth_verify_access_token_err = "bkauth error"
"ssm verify ok, but not configured", function()
ssm_verify_access_token_result = {
bk_app_code = "my-foo",
username = "kitty",
Expand All @@ -154,7 +113,7 @@ describe(

local result = access_token_cache._get_access_token("fake-access-token")
assert.is_nil(result.token)
-- assert.is_equal(result.err, "bkauth error")
assert.is_equal(result.err, "authentication based on access_token is not supported")
end
)
end
Expand Down

0 comments on commit 284bb16

Please sign in to comment.