Skip to content

Commit

Permalink
tests(hybrid): fix CP-DP compatibility tests (#8705)
Browse files Browse the repository at this point in the history
* fix: trying to correct the logic

* Update spec-ee/02-integration/14-hybrid_mode/04-config-compat_spec.lua

* fix test cases

* update comment

* test(clustering): fix cluster compat tests

Signed-off-by: Joshua Schmid <[email protected]>

---------

Signed-off-by: Joshua Schmid <[email protected]>
Co-authored-by: Joshua Schmid <[email protected]>
  • Loading branch information
vm-001 and jschmid1 authored Apr 26, 2024
1 parent 8f583a7 commit 7a47fa6
Showing 1 changed file with 26 additions and 55 deletions.
81 changes: 26 additions & 55 deletions spec-ee/02-integration/14-hybrid_mode/04-config-compat_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ local utils = require "kong.tools.utils"
local cjson = require "cjson"
local STATUS = require("kong.constants").CLUSTERING_SYNC_STATUS
local FIELDS = require("kong.clustering.compat.removed_fields")
local CHECKERS = require("kong.clustering.compat.checkers")
local version = require("kong.clustering.compat.version")
local tablex = require "pl.tablex"

local admin = require "spec.fixtures.admin_api"

local fmt = string.format
local version_num = version.string_to_number

local CP_HOST = "127.0.0.1"
local CP_PORT = 9005
Expand Down Expand Up @@ -69,6 +67,8 @@ end


local function get_plugin(node_id, node_version, name)
-- Emulates a DP connection to a CP. We're sending our node_id and version
-- and expect a payload back that contains our sanitized plugin config.
local res = cluster_client({ id = node_id, version = node_version })

local plugin
Expand All @@ -85,23 +85,6 @@ local function get_plugin(node_id, node_version, name)
return plugin, get_sync_status(node_id)
end


local function get(t, field)
local parts = utils.split(field, ".")
local ref = t

for i = 1, #parts do
if type(ref) ~= "table" then
return
end

ref = ref[parts[i]]
end

return ref
end


for _, strategy in helpers.each_strategy() do

describe("CP/DP config compat #" .. strategy, function()
Expand All @@ -119,40 +102,28 @@ describe("CP/DP config compat #" .. strategy, function()
plugin_entity = case.init_plugin and case.init_plugin(plugin_entity) or plugin_entity

local plugin = admin.plugins:insert(plugin_entity)
local id = utils.uuid()
for k, v in pairs(case.config) do
-- assert that the config was created with the expected values from the case struct
-- This is mere a safety check to ensure the test doesn't start wrong.
assert.is_same(plugin.config[k], v, "initial plugin configuration isn't sane.")
end

local id = utils.uuid()
local conf, status
helpers.wait_until(function()
-- Connect to a CP and await config.
-- The config should be shaped as described in the validator func
-- as the get_plugin function connects to the CP, which
-- runs the required compatibility checkers (functions)
-- to ensure a compatible config is sent back to us.
conf, status = get_plugin(id, dp_version, case.plugin)
return status == case.status
end, 5, 0.25)

assert.equals(case.status, status)

if case.status == STATUS.NORMAL then
for _, chkrs in pairs(case.checker or EMPTY) do
local ver = chkrs[1]
local fn = chkrs[2]
if ver == version_num(dp_version) then
local plugins_table = { plugins = {{ config = conf, name = plugin.name }}}
fn(plugins_table, dp_version, "")
end
end
for _, field in ipairs(case.removed or {}) do
assert.not_nil(get(plugin.config, field),
"field '" .. field .. "' is missing from the " ..
"configured plugin")

assert.is_nil(get(conf, field),
"field '" .. field .. "' was not removed from the " ..
"data plane copy of the plugin config")
end
else
assert.is_nil(conf, "expected config sync to fail")
end

if case.validator then
assert(case.validator(conf), "unexpected config received")
assert.is_truthy(case.validator(conf), "unexpected config received")
end
end

Expand Down Expand Up @@ -198,6 +169,8 @@ describe("CP/DP config compat #" .. strategy, function()
end)

describe("3.4.x.y", function()
-- When a data-plane lower than the version of the control-plane
-- connects, it should receive the config as described in the validator func
local CASES = {
{
plugin = "opentelemetry",
Expand All @@ -218,12 +191,14 @@ describe("CP/DP config compat #" .. strategy, function()
local test = case.pending and pending or it

test(fmt("%s - %s", case.plugin, case.label), function()
do_assert(case, "3.4.0.0")
do_assert(case, "3.3.9.9")
end)
end
end)

describe("3.5.x.y", function()
-- When a data-plane lower than the version of the control-plane
-- connects, it should receive the config as described in the validator func
local CASES = {
{
plugin = "acl",
Expand All @@ -245,12 +220,14 @@ describe("CP/DP config compat #" .. strategy, function()
local test = case.pending and pending or it

test(fmt("%s - %s", case.plugin, case.label), function()
do_assert(case, "3.5.0.0")
do_assert(case, "3.4.9.9")
end)
end
end)

describe("3.6.x.y", function()
-- When a data-plane lower than the version of the control-plane
-- connects, it should receive the config as described in the validator func
local CASES = {
{
plugin = "rate-limiting-advanced",
Expand All @@ -262,7 +239,6 @@ describe("CP/DP config compat #" .. strategy, function()
identifier = "consumer-group",
},
status = STATUS.NORMAL,
checker = CHECKERS,
validator = function(config)
return config.identifier == 'consumer'
end
Expand All @@ -276,7 +252,6 @@ describe("CP/DP config compat #" .. strategy, function()
limit_by = "consumer-group"
},
status = STATUS.NORMAL,
checker = CHECKERS,
validator = function(config)
return config.limit_by == 'consumer'
end
Expand All @@ -299,7 +274,6 @@ describe("CP/DP config compat #" .. strategy, function()
revocation_endpoint_auth_method = "self_signed_tls_client_auth"
},
status = STATUS.NORMAL,
checker = CHECKERS,
validator = function(config)
return tablex.compare({ "client_secret_post", "client_secret_basic" }, config.client_auth, "==") and
config.token_endpoint_auth_method == nil and
Expand Down Expand Up @@ -343,12 +317,14 @@ describe("CP/DP config compat #" .. strategy, function()
local test = case.pending and pending or it

test(fmt("%s - %s", case.plugin, case.label), function()
do_assert(case, "3.6.0.0")
do_assert(case, "3.5.9.9")
end)
end
end)

describe("3.7.x.y", function()
-- When a data-plane lower than the version of the control-plane
-- connects, it should receive the config as described in the validator func
local CASES = {
{
plugin = "openid-connect",
Expand All @@ -359,7 +335,6 @@ describe("CP/DP config compat #" .. strategy, function()
response_mode = "query.jwt"
},
status = STATUS.NORMAL,
checker = CHECKERS,
validator = function(config)
return config.response_mode == "query"
end
Expand All @@ -373,7 +348,6 @@ describe("CP/DP config compat #" .. strategy, function()
response_mode = "form_post.jwt"
},
status = STATUS.NORMAL,
checker = CHECKERS,
validator = function(config)
return config.response_mode == "form_post"
end
Expand All @@ -387,7 +361,6 @@ describe("CP/DP config compat #" .. strategy, function()
response_mode = "fragment.jwt"
},
status = STATUS.NORMAL,
checker = CHECKERS,
validator = function(config)
return config.response_mode == "fragment"
end
Expand All @@ -401,7 +374,6 @@ describe("CP/DP config compat #" .. strategy, function()
response_mode = "jwt"
},
status = STATUS.NORMAL,
checker = CHECKERS,
validator = function(config)
return config.response_mode == "query"
end
Expand All @@ -415,7 +387,6 @@ describe("CP/DP config compat #" .. strategy, function()
display_name = "test.service",
},
status = STATUS.NORMAL,
checker = CHECKERS,
init_plugin = function(plugin)
local service = admin.services:insert()
plugin["service"] = service
Expand Down Expand Up @@ -567,7 +538,7 @@ describe("CP/DP config compat #" .. strategy, function()
local test = case.pending and pending or it

test(fmt("%s - %s", case.plugin, case.label), function()
do_assert(case, "3.6.0.0")
do_assert(case, "3.6.9.9")
end)
end
end)
Expand Down

0 comments on commit 7a47fa6

Please sign in to comment.