From 87bced3c7fa24816557459c7c96bae48f278716e Mon Sep 17 00:00:00 2001 From: chronolaw Date: Tue, 12 Sep 2023 14:36:15 +0800 Subject: [PATCH] more cases --- spec/01-unit/08-router_spec.lua | 41 ++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/spec/01-unit/08-router_spec.lua b/spec/01-unit/08-router_spec.lua index a5b08beddb9a..8fd09b16fad0 100644 --- a/spec/01-unit/08-router_spec.lua +++ b/spec/01-unit/08-router_spec.lua @@ -4860,7 +4860,7 @@ end do local flavor = "expressions" - describe("Router (flavor = " .. flavor .. ") [http] ", function() + describe("Router (flavor = " .. flavor .. ") [http]", function() reload_router(flavor) local use_case, router @@ -4964,21 +4964,31 @@ do end) - describe("Router (flavor = " .. flavor .. ") [stream] ", function() + describe("#only Router (flavor = " .. flavor .. ") [stream]", function() reload_router(flavor, "stream") local use_case, router + local service = { + name = "service-invalid", + protocol = "tcp", + } + lazy_setup(function() use_case = { - -- query has one value { - service = { - name = "service-tls-passthough-invalid", - protocol = "tcp", - }, + service = service, route = { id = "e8fb37f1-102d-461e-9c51-6608a6bb8101", + protocols = { "tls" }, + expression = [[tls.sni == "www.example.com"]], + priority = 100, + }, + }, + { + service = service, + route = { + id = "e8fb37f1-102d-461e-9c51-6608a6bb8102", protocols = { "tls_passthough" }, expression = [[tls.sni == "www.example.org"]], priority = 100, @@ -4989,6 +4999,21 @@ do router = assert(new_router(use_case)) end) + it("exec() should match tls with tls.sni", function() + local _ngx = { + var = { + remote_port = 1000, + server_port = 1000, + ssl_preread_server_name = "www.example.com", + }, + } + router._set_ngx(_ngx) + local match_t = router:exec() + assert.truthy(match_t) + + assert.same(use_case[1].route, match_t.route) + end) + it("exec() should match tls_passthough with tls.sni", function() local _ngx = { var = { @@ -5001,7 +5026,7 @@ do local match_t = router:exec() assert.truthy(match_t) - assert.same(use_case[1].route, match_t.route) + assert.same(use_case[2].route, match_t.route) end) end)