Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests that expect debug output without enabling the option #577

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions gateway/src/apicast/proxy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,15 @@ local function error_service_not_found(host)
end
-- End Error Codes

local function get_debug_value(service)
return ngx.var.http_x_3scale_debug == service.backend_authentication.value
local function debug_header_enabled(service)
local debug_header_value = ngx.var.http_x_3scale_debug
return debug_header_value and debug_header_value == service.backend_authentication.value
end

local function output_debug_headers(service, usage, credentials)
ngx.log(ngx.INFO, 'usage: ', usage, ' credentials: ', credentials)

if get_debug_value(service) then
if debug_header_enabled(service) then
ngx.header["X-3scale-matched-rules"] = ngx.ctx.matched_patterns
ngx.header["X-3scale-credentials"] = credentials
ngx.header["X-3scale-usage"] = usage
Expand Down
12 changes: 12 additions & 0 deletions t/apicast-mapping-rules.t
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ url params in a POST call are taken into account when matching mapping rules.
{
id = 42,
backend_version = 1,
backend_authentication_type = 'service_token',
backend_authentication_value = 'my-token',
proxy = {
api_backend = 'http://127.0.0.1:$TEST_NGINX_SERVER_PORT/api/',
proxy_rules = {
Expand All @@ -88,6 +90,8 @@ url params in a POST call are taken into account when matching mapping rules.
}
--- request
POST /foo?bar=baz&user_key=somekey
--- more_headers
X-3scale-Debug: my-token
--- response_body
api response
--- error_code: 200
Expand All @@ -107,6 +111,8 @@ request body params in a POST call are taken into account when matching mapping
{
id = 42,
backend_version = 1,
backend_authentication_type = 'service_token',
backend_authentication_value = 'my-token',
proxy = {
api_backend = 'http://127.0.0.1:$TEST_NGINX_SERVER_PORT/api/',
proxy_rules = {
Expand Down Expand Up @@ -134,6 +140,8 @@ request body params in a POST call are taken into account when matching mapping
--- request
POST /foo?user_key=somekey
bar=baz
--- more_headers
X-3scale-Debug: my-token
--- response_body
api response
--- error_code: 200
Expand All @@ -155,6 +163,8 @@ precedence.
{
id = 42,
backend_version = 1,
backend_authentication_type = 'service_token',
backend_authentication_value = 'my-token',
proxy = {
api_backend = 'http://127.0.0.1:$TEST_NGINX_SERVER_PORT/api/',
proxy_rules = {
Expand Down Expand Up @@ -182,6 +192,8 @@ precedence.
--- request
POST /foo?a_param=val3&another_param=val2&user_key=somekey
a_param=val1
--- more_headers
X-3scale-Debug: my-token
--- response_body
api response
--- error_code: 200
Expand Down
8 changes: 8 additions & 0 deletions t/apicast.t
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ When mapping rule has a parameter with fixed value it has to be matched.
{
id = 42,
backend_version = 1,
backend_authentication_type = 'service_token',
backend_authentication_value = 'my-token',
proxy = {
api_backend = 'http://127.0.0.1:$TEST_NGINX_SERVER_PORT/api/',
proxy_rules = {
Expand All @@ -333,6 +335,8 @@ When mapping rule has a parameter with fixed value it has to be matched.
}
--- request
GET /foo?bar=baz&user_key=somekey
--- more_headers
X-3scale-Debug: my-token
--- response_body
api response
--- response_headers
Expand All @@ -352,6 +356,8 @@ When mapping rule has a parameter with variable value it has to exist.
{
id = 42,
backend_version = 1,
backend_authentication_type = 'service_token',
backend_authentication_value = 'my-token',
proxy = {
api_backend = 'http://127.0.0.1:$TEST_NGINX_SERVER_PORT/api/',
proxy_rules = {
Expand All @@ -376,6 +382,8 @@ When mapping rule has a parameter with variable value it has to exist.
}
--- request
GET /foo?bar={foo}&user_key=somekey
--- more_headers
X-3scale-Debug: my-token
--- response_body
api response
--- error_code: 200
Expand Down