From 415d11594a2889c49b94a5cd305ac8fc4b037ad6 Mon Sep 17 00:00:00 2001 From: Chrono Date: Wed, 24 Jan 2024 16:25:28 +0800 Subject: [PATCH] chore(deps): bump atc-router to v1.6.0 and add changelog entry for "not" operator support in ATC (#12405) KAG-3605 --------- Co-authored-by: Datong Sun --- .requirements | 2 +- .../unreleased/expressions_not_operator.yml | 3 ++ changelog/unreleased/kong/bump-atc-router.yml | 2 +- .../01-db/01-schema/06-routes_spec.lua | 19 ++++++++++++ spec/01-unit/08-router_spec.lua | 30 +++++++++++++++++++ 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/expressions_not_operator.yml diff --git a/.requirements b/.requirements index 6f0a9321bdf5..eebecebb8000 100644 --- a/.requirements +++ b/.requirements @@ -10,7 +10,7 @@ LUA_KONG_NGINX_MODULE=4fbc3ddc7dcbc706ed286b95344f3cb6da17e637 # 0.8.0 LUA_RESTY_LMDB=951926f20b674a0622236a0e331b359df1c02d9b # 1.3.0 LUA_RESTY_EVENTS=8448a92cec36ac04ea522e78f6496ba03c9b1fd8 # 0.2.0 LUA_RESTY_WEBSOCKET=60eafc3d7153bceb16e6327074e0afc3d94b1316 # 0.4.0 -ATC_ROUTER=ee6bb38f9c71becb750041f605bfe0fffc2c70fe # 1.5.1 +ATC_ROUTER=1abb9286947b70b4e302d8df953961c1280a0289 # 1.6.0 KONG_MANAGER=v3.5.0.0 NGX_WASM_MODULE=388d5720293f5091ccee1f859a42683fbfd14e7d # prerelease-0.2.0 diff --git a/changelog/unreleased/expressions_not_operator.yml b/changelog/unreleased/expressions_not_operator.yml new file mode 100644 index 000000000000..dd6bd2394165 --- /dev/null +++ b/changelog/unreleased/expressions_not_operator.yml @@ -0,0 +1,3 @@ +message: The expressions route now supports the `!` (not) operator, which allows creating routes like `!(http.path =^)` and `!(http.path == "/a" || http.path == "/b")` +type: "feature" +scope: "Core" diff --git a/changelog/unreleased/kong/bump-atc-router.yml b/changelog/unreleased/kong/bump-atc-router.yml index 64aa27ac154c..c4d7c1140644 100644 --- a/changelog/unreleased/kong/bump-atc-router.yml +++ b/changelog/unreleased/kong/bump-atc-router.yml @@ -1,3 +1,3 @@ -message: Bumped atc-router from 1.2.0 to 1.5.1 +message: Bumped atc-router from 1.2.0 to 1.6.0 type: dependency scope: Core diff --git a/spec/01-unit/01-db/01-schema/06-routes_spec.lua b/spec/01-unit/01-db/01-schema/06-routes_spec.lua index 0e90e75dbe5b..a0796c8ab587 100644 --- a/spec/01-unit/01-db/01-schema/06-routes_spec.lua +++ b/spec/01-unit/01-db/01-schema/06-routes_spec.lua @@ -1425,6 +1425,25 @@ describe("routes schema (flavor = expressions)", function() reload_flavor("expressions") setup_global_env() + it("validates a 'not' expression", function() + local route = { + id = a_valid_uuid, + name = "my_route", + protocols = { "http" }, + expression = [[!(http.method == "GET") && !(http.host == "example.com") && !(http.path ^= "/foo")]], + priority = 100, + strip_path = false, + preserve_host = true, + service = { id = another_uuid }, + } + route = Routes:process_auto_fields(route, "insert") + assert.truthy(route.created_at) + assert.truthy(route.updated_at) + assert.same(route.created_at, route.updated_at) + assert.truthy(Routes:validate(route)) + assert.falsy(route.strip_path) + end) + it("validates a valid http route", function() local route = { id = a_valid_uuid, diff --git a/spec/01-unit/08-router_spec.lua b/spec/01-unit/08-router_spec.lua index 478d681eae6e..02d993c3a6b1 100644 --- a/spec/01-unit/08-router_spec.lua +++ b/spec/01-unit/08-router_spec.lua @@ -5631,5 +5631,35 @@ do assert.same(ctx.route_match_cached, "pos") end) end) + + describe("Router (flavor = " .. flavor .. ") [http]", function() + reload_router(flavor) + + it("select() should match not expression", function() + local use_case = { + { + service = service, + route = { + id = "e8fb37f1-102d-461e-9c51-6608a6bb8101", + expression = [[!(http.path ^= r#"/foo"#)]], + priority = 100, + }, + }, + } + + local router = assert(new_router(use_case)) + + local match_t = router:select("GET", "/123/foo/bar") + assert.truthy(match_t) + assert.same(use_case[1].route, match_t.route) + + local match_t = router:select("GET", "/xyz/hello-world/bar") + assert.truthy(match_t) + assert.same(use_case[1].route, match_t.route) + + local match_t = router:select("GET", "/foo/bar") + assert.falsy(match_t) + end) + end) end -- local flavor = "expressions"