Skip to content

Commit

Permalink
tests(router) extend regression tests for #5438
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Jan 20, 2020
1 parent eca08e1 commit c0d9cf2
Showing 1 changed file with 142 additions and 9 deletions.
151 changes: 142 additions & 9 deletions spec/02-integration/05-proxy/02-router_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ for _, strategy in helpers.each_strategy() do
end)
end)

describe("[headers]", function()
describe("[#headers]", function()
local routes

after_each(function()
Expand Down Expand Up @@ -1307,7 +1307,7 @@ for _, strategy in helpers.each_strategy() do
end)
end)

describe("[paths] + [headers]", function()
describe("[paths] + [#headers]", function()
local routes

lazy_setup(function()
Expand Down Expand Up @@ -1377,7 +1377,7 @@ for _, strategy in helpers.each_strategy() do
end)
end)

describe("[snis] for gRPCs connections", function()
describe("[snis] for #grpcs connections", function()
local routes
local grpcs_proxy_ssl_client

Expand Down Expand Up @@ -1445,37 +1445,170 @@ for _, strategy in helpers.each_strategy() do

lazy_setup(function()
routes = insert_routes(bp, {
{
[1] = {
strip_path = true,
methods = { "GET" },
paths = { "/unrelated/longer/uri/that/should/not/match", "/root/fixture" },
hosts = { "ahost.test" },
service = { path = "/status/201" },
},
{
[2] = {
strip_path = true,
methods = { "GET" },
paths = { "/root/fixture/get" },
hosts = { "ahost.test" },
service = { path = "/status/202" },
},
{
[3] = {
strip_path = true,
methods = { "GET" },
paths = { "/root/fixture/get" },
hosts = { "anotherhost.test" },
service = { path = "/status/203" },
},
{
[4] = {
strip_path = true,
methods = { "GET" },
paths = { "/root/fixture/get" },
hosts = { "onemorehost.test" },
service = { path = "/status/204" },
},

[5] = {
strip_path = true,
name = "public-apiv1",
paths = { "/rest/devportal/api/v1", "/rest/devportal" },
hosts = { "api.local" },
service = { path = "/status/205" },
},
[6] = {
strip_path = true,
name = "aux",
paths = { "/rest/devportal/aux" },
hosts = { "api.local" },
service = { path = "/status/206" },
},
[7] = {
strip_path = true,
name = "aux-host",
paths = { "/rest/devportal/aux" },
hosts = { "test-api.local" },
service = { path = "/status/207" },
},
[8] = {
strip_path = true,
name = "aux-host2",
paths = { "/rest/devportal/aux" },
hosts = { "atest-api.local" },
service = { path = "/status/208" },
},
[9] = {
strip_path = true,
name = "devportal-route-2",
paths = { "/rest/devportal" },
hosts = { "atest-api.local" },
service = { path = "/status/209" },
},

[10] = {
strip_path = true,
name = "concat_test-public-apiv1",
paths = { "/concat_test/devportal/api/v1", "/concat_test/devportal" },
hosts = { "api.local" },
},
[11] = {
strip_path = true,
name = "concat_test-aux",
paths = { "/concat_test/devportal/aux" },
hosts = { "api.local" },
},
[12] = {
strip_path = true,
name = "concat_test-aux-host",
paths = { "/concat_test/devportal/aux" },
hosts = { "test-api.local" },
},
[13] = {
strip_path = true,
name = "concat_test-aux-host2",
paths = { "/concat_test/devportal/aux" },
hosts = { "atest-api.local" },
},
[14] = {
strip_path = true,
name = "concat_test-devportal-route-2",
paths = { "/concat_test/devportal" },
hosts = { "atest-api.local" },
},

})
end)

lazy_teardown(function()
remove_routes(strategy, routes)
end)

it("regression test for #5438", function()
for i = 1, 9 do
for j = 1, #routes[i].paths do
local res = assert(proxy_client:send {
method = "GET",
path = routes[i].paths[j],
headers = {
["kong-debug"] = 1,
["host"] = routes[i].hosts[1],
}
})

assert.res_status(200 + i, res)

assert.equal(routes[i].id, res.headers["kong-route-id"])
assert.equal(routes[i].service.id, res.headers["kong-service-id"])
assert.equal(routes[i].service.name, res.headers["kong-service-name"])

end
end
end)

it("regression test for #5438 concatenating paths", function()
for i = 10, 14 do
for j = 1, #routes[i].paths do
local res = assert(proxy_client:send {
method = "GET",
path = routes[i].paths[j] .. "/status/418",
headers = {
["kong-debug"] = 1,
["host"] = routes[i].hosts[1],
}
})

assert.res_status(418, res)

assert.equal(routes[i].id, res.headers["kong-route-id"])
assert.equal(routes[i].service.id, res.headers["kong-service-id"])
assert.equal(routes[i].service.name, res.headers["kong-service-name"])

end
end
end)

it("regression test for #5438 part 2", function()
local res = assert(proxy_client:send {
method = "GET",
path = "/rest/devportal",
headers = {
["kong-debug"] = 1,
["host"] = "atest-api.local",
}
})

assert.res_status(209, res)

assert.equal(routes[9].id, res.headers["kong-route-id"])
assert.equal(routes[9].service.id, res.headers["kong-service-id"])
assert.equal(routes[9].service.name, res.headers["kong-service-name"])
end)

it("prioritizes longer URIs", function()
local res = assert(proxy_client:send {
method = "GET",
Expand All @@ -1486,7 +1619,7 @@ for _, strategy in helpers.each_strategy() do
}
})

assert.res_status(200, res)
assert.res_status(202, res)

assert.equal(routes[2].id, res.headers["kong-route-id"])
assert.equal(routes[2].service.id, res.headers["kong-service-id"])
Expand All @@ -1503,7 +1636,7 @@ for _, strategy in helpers.each_strategy() do
}
})

assert.res_status(200, res)
assert.res_status(203, res)

assert.equal(routes[3].id, res.headers["kong-route-id"])
assert.equal(routes[3].service.id, res.headers["kong-service-id"])
Expand Down

0 comments on commit c0d9cf2

Please sign in to comment.