Skip to content

Commit

Permalink
PATH-routing: url was not escaped correctly
Browse files Browse the repository at this point in the history
If PATH routing was defined, the uri was not escaped correctly so the
mapping rules will not work as expected.

Reported by: Carlo Palmiari <cpalmier@redhat.com>
Fix: THREESCALE-3468
Related-to:112fdfa502483983b462fb82a5e789003ab9f750

Signed-off-by: Eloy Coto <eloy.coto@gmail.com>
  • Loading branch information
eloycoto committed Dec 17, 2019
1 parent 4de5927 commit 0b55315
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
local mapping_rules_matcher = require 'apicast.mapping_rules_matcher'
local escape = require("resty.http.uri_escape")

local _M = {}

function _M.find_service(config_store, host)
local found
local services = config_store:find_by_host(host)
local method = ngx.req.get_method()
local uri = ngx.var.uri
local uri = escape.escape_uri(ngx.var.uri)

for s=1, #services do
local service = services[s]
Expand Down
67 changes: 67 additions & 0 deletions t/apicast-path-routing.t
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,70 @@ Host: one
--- error_code: 404
--- no_error_log
[error]
=== TEST 4: multi service configuration with path based routing and special chars (spaces)
--- env eval
('APICAST_PATH_ROUTING' => '1')
--- configuration
{
"services": [
{
"id": 42,
"backend_version": 1,
"proxy": {
"api_backend": "http://test:$TEST_NGINX_SERVER_PORT/api-backend/foo/",
"hosts": [
"same"
],
"backend_authentication_type": "service_token",
"backend_authentication_value": "service-one",
"proxy_rules": [
{
"pattern": "/one/{test}",
"http_method": "GET",
"metric_system_name": "one",
"delta": 1
}
]
}
},
{
"id": 21,
"backend_version": 2,
"proxy": {
"api_backend": "http://test:$TEST_NGINX_SERVER_PORT/api-backend/bar/",
"hosts": [
"same"
],
"backend_authentication_type": "service_token",
"backend_authentication_value": "service-two",
"proxy_rules": [
{
"pattern": "/two/%20two",
"http_method": "GET",
"metric_system_name": "two",
"delta": 2
}
]
}
}
]
}
--- backend
location /transactions/authrep.xml {
content_by_lua_block { ngx.exit(200) }
}
--- upstream
location ~ /api-backend(/.+) {
echo 'yay, api backend: $1';
}
--- request eval
["GET /one/12%2012?user_key=one-key", "GET /two/%20two?app_id=two-id&app_key=two-key"]
--- more_headers eval
["Host: same", "Host: same"]
--- response_body eval
["yay, api backend: /foo/one/12 12\x{0a}", "yay, api backend: /bar/two/ two\x{0a}"]
--- error_code eval
[200, 200]
--- no_error_log
[error]

0 comments on commit 0b55315

Please sign in to comment.