Skip to content

Commit

Permalink
apicast-mapping-rules.t: test mapping rules are matched when POST par…
Browse files Browse the repository at this point in the history
…ams in uri & body
  • Loading branch information
davidor committed Sep 29, 2017
1 parent c0b5f28 commit 6cedfd4
Showing 1 changed file with 145 additions and 0 deletions.
145 changes: 145 additions & 0 deletions t/010-apicast-mapping-rules.t
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,148 @@ GET /staging/video/encode?size=100&speed=3x&user_key=foo&speed=2x
--- response_body
yay, api backend
--- error_code: 200
=== TEST 2: mapping rules when POST request has url parms
url params in a POST call are taken into account when matching mapping rules.
--- http_config
include $TEST_NGINX_UPSTREAM_CONFIG;
lua_package_path "$TEST_NGINX_LUA_PATH";
init_by_lua_block {
require('configuration_loader').mock({
services = {
{
id = 42,
backend_version = 1,
proxy = {
api_backend = 'http://127.0.0.1:$TEST_NGINX_SERVER_PORT/api/',
proxy_rules = {
{ pattern = '/foo?bar=baz',
querystring_parameters = { bar = 'baz' },
http_method = 'POST',
metric_system_name = 'bar',
delta = 7 }
}
}
},
}
})
}
--- config
include $TEST_NGINX_APICAST_CONFIG;
set $backend_endpoint 'http://127.0.0.1:$TEST_NGINX_SERVER_PORT';
location /api/ {
echo "api response";
}
location /transactions/authrep.xml {
content_by_lua_block { ngx.exit(200) }
}
--- request
POST /foo?bar=baz&user_key=somekey
--- response_body
api response
--- error_code: 200
--- response_headers
X-3scale-matched-rules: /foo?bar=baz
X-3scale-usage: usage%5Bbar%5D=7
=== TEST 3: mapping rules when POST request has body params
request body params in a POST call are taken into account when matching mapping rules.
--- http_config
include $TEST_NGINX_UPSTREAM_CONFIG;
lua_package_path "$TEST_NGINX_LUA_PATH";
init_by_lua_block {
require('configuration_loader').mock({
services = {
{
id = 42,
backend_version = 1,
proxy = {
api_backend = 'http://127.0.0.1:$TEST_NGINX_SERVER_PORT/api/',
proxy_rules = {
{ pattern = '/foo?bar=baz',
querystring_parameters = { bar = 'baz' },
http_method = 'POST',
metric_system_name = 'bar',
delta = 7 }
}
}
},
}
})
}
--- config
include $TEST_NGINX_APICAST_CONFIG;
set $backend_endpoint 'http://127.0.0.1:$TEST_NGINX_SERVER_PORT';
location /api/ {
echo "api response";
}
location /transactions/authrep.xml {
content_by_lua_block { ngx.exit(200) }
}
--- request
POST /foo?user_key=somekey
bar=baz
--- response_body
api response
--- error_code: 200
--- response_headers
X-3scale-matched-rules: /foo?bar=baz
X-3scale-usage: usage%5Bbar%5D=7
=== TEST 4: mapping rules when POST request has body params and url params
Both body params and url params are taken into account when matching mapping
rules. When a param is both in the url and the body, the one in the body takes
precedence.
--- http_config
include $TEST_NGINX_UPSTREAM_CONFIG;
lua_package_path "$TEST_NGINX_LUA_PATH";
init_by_lua_block {
require('configuration_loader').mock({
services = {
{
id = 42,
backend_version = 1,
proxy = {
api_backend = 'http://127.0.0.1:$TEST_NGINX_SERVER_PORT/api/',
proxy_rules = {
{ pattern = '/foo?a_param=val1&another_param=val2',
querystring_parameters = { a_param = 'val1', another_param = 'val2' },
http_method = 'POST',
metric_system_name = 'bar',
delta = 7 }
}
}
},
}
})
}
--- config
include $TEST_NGINX_APICAST_CONFIG;
set $backend_endpoint 'http://127.0.0.1:$TEST_NGINX_SERVER_PORT';
location /api/ {
echo "api response";
}
location /transactions/authrep.xml {
content_by_lua_block { ngx.exit(200) }
}
--- request
POST /foo?a_param=val3&another_param=val2&user_key=somekey
a_param=val1
--- response_body
api response
--- error_code: 200
--- response_headers
X-3scale-matched-rules: /foo?a_param=val1&another_param=val2
X-3scale-usage: usage%5Bbar%5D=7

0 comments on commit 6cedfd4

Please sign in to comment.