From 558cad7b73c5fea747dda681bc8fb0c68424a00d Mon Sep 17 00:00:00 2001 From: Dhruv Sarawagi <62890722+dhruvd11@users.noreply.github.com> Date: Mon, 9 Aug 2021 15:32:43 +0530 Subject: [PATCH] chore: add test cases (#1) --- .editorconfig | 2 +- kong/plugins/advanced-router/handler.lua | 13 +- kong/plugins/advanced-router/io.lua | 20 +- kong/plugins/advanced-router/schema.lua | 39 ++- kong/plugins/advanced-router/utils.lua | 6 +- spec/advanced-router/01-access_spec.lua | 389 ++++++++++++++++++----- spec/fixtures/custom_nginx.template | 95 +++++- 7 files changed, 442 insertions(+), 122 deletions(-) diff --git a/.editorconfig b/.editorconfig index 2129842..71f6efa 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,7 +10,7 @@ end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true charset = utf-8 - +quote_type = double [*.{yml,yaml}] indent_size = 2 diff --git a/kong/plugins/advanced-router/handler.lua b/kong/plugins/advanced-router/handler.lua index a6bc120..87391c9 100644 --- a/kong/plugins/advanced-router/handler.lua +++ b/kong/plugins/advanced-router/handler.lua @@ -28,9 +28,9 @@ end function generate_boolean_function(proposition) if proposition['condition'] == 'default' then - return assert(loadstring("return " .. "\"" .. proposition["value"] .. "\"")) + return assert(loadstring("return " .. "\"" .. proposition["upstream_url"] .. "\"")) end - return assert(loadstring("if " .. proposition["condition"] .. "then return " .. "\"" .. proposition["value"] .. "\"" .. " end")) + return assert(loadstring("if " .. proposition["condition"] .. "then return " .. "\"" .. proposition["upstream_url"] .. "\"" .. " end")) end function get_upstream_url(conf) @@ -60,10 +60,13 @@ end function set_upstream(upstream_url) local parsed_url = url.parse(upstream_url) + local scheme = parsed_url['port'] or 'http' local host = parsed_url['host'] local path = parsed_url['path'] local port = tonumber(parsed_url['port']) or 80 - kong.log.debug("Upstream set by advanced router::" .. inspect(upstream_url)) + kong.service.request.set_scheme(scheme) + kong.log.debug("Upstream URL::" .. inspect(upstream_url)) + kong.log.debug("Parsed Upstream URL::" .. inspect(parsed_url)) kong.service.set_target(host, port) if path then kong.service.request.set_path(path) @@ -75,7 +78,7 @@ function AdvancedRouterHandler:access(conf) local io_data, err = get_io_data(conf) if err then kong.log.err("Error in getting io data" .. inspect(err)) - return kong.response.exit(500, "Error in getting io data") + return kong.response.exit(500, { error = "Error in getting io data" .. inspect(err) }) end kong.ctx.plugin.io_data = io_data @@ -83,7 +86,7 @@ function AdvancedRouterHandler:access(conf) if not upstream_url then return kong.response.exit(500, "Not able to resolve upstream in advanced router") end - upstream_url = replaceStringEnvVariables(upstream_url) + upstream_url = replaceStringEnvVariables(upstream_url, io_data) set_upstream(upstream_url) end diff --git a/kong/plugins/advanced-router/io.lua b/kong/plugins/advanced-router/io.lua index cc672d7..54f7718 100644 --- a/kong/plugins/advanced-router/io.lua +++ b/kong/plugins/advanced-router/io.lua @@ -20,13 +20,15 @@ local function get_http_client(conf) end function extract_from_request(object, key) + local value if object == 'headers' then - local r = extract(key, kong.request.get_headers()) - return r + value = extract(string.lower(key), kong.request.get_headers()) + return value else - local r = extract(key, kong.request.get_query()) - return r + value = extract(key, kong.request.get_query()) + return value end + return value end function extract_io_data_from_request(conf) @@ -37,7 +39,6 @@ function extract_io_data_from_request(conf) body = {} } local req_parts = { "headers", "query", "body" } - for _, part in ipairs(req_parts) do if io_request_template[part] then for key, value in pairs(io_request_template[part]) do @@ -55,7 +56,6 @@ function extract_io_data_from_request(conf) end end end - return io_req end @@ -78,15 +78,18 @@ function get_io_data_from_remote(request_data, conf) query = request_data.query } ) + kong.log.debug("IO call error::" .. inspect(err1)) if not res or err1 then return nil, err1 end - + if not err1 and res and res.status ~= 200 then + return nil, "IO call failed - Response status:" .. res.status + end local bodyJson, err2 = cjson_safe.decode(res["body"]) if not bodyJson then return nil, err2 end - + kong.log.debug("Data from I/O::" .. inspect(bodyJson.data)) local cacheTTL if conf.cache_io_response then cacheTTL = res.headers[conf.cache_ttl_header] or conf["default_edge_ttl_sec"] @@ -116,6 +119,7 @@ end function create_io_request(conf) local io_request = extract_io_data_from_request(conf) + kong.log.debug("conf" .. inspect(conf)) io_request["io_url"] = replaceStringEnvVariables(conf.io_url) io_request["io_http_method"] = conf.io_http_method return io_request diff --git a/kong/plugins/advanced-router/schema.lua b/kong/plugins/advanced-router/schema.lua index edaff58..a17a764 100644 --- a/kong/plugins/advanced-router/schema.lua +++ b/kong/plugins/advanced-router/schema.lua @@ -1,18 +1,43 @@ local typedefs = require "kong.db.schema.typedefs" local json_safe = require "cjson.safe" +local url = require "socket.url" + +local belongs = require "kong.plugins.advanced-router.utils".belongs local function json_validator(config_string) - local config_table, err = json_safe.decode(config_string) + local decoded, err = json_safe.decode(config_string) - if config_table == nil then + if decoded == nil then return nil, "Invalid Json " .. inspect(err) end + return true, nil, decoded +end + +local function validate_propositions_json(config_string) + -- This functions validates the port and protocols of the upstream urls in the propositions_json + local result, err, propositions_json = json_validator(config_string) + if not result then + return nil, err + end + local valid_schemes = { 'http', 'https' } + for _, v in ipairs(propositions_json) do + local upstream_url = v['upstream_url'] + local parsed_url = url.parse(upstream_url) + local scheme = parsed_url['port'] or 'http' + if not belongs(scheme, valid_schemes) then + return nil, "Invalid protocol: " .. scheme " for url: " .. upstream_url + end + + if parsed_url['port'] and not tonumber(parsed_url['port']) then + return nil, "Invalid port: " .. parsed_url['port'] " for url: " .. upstream_url + end + end return true end local function schema_validator(conf) - return json_validator(conf.propositions_json) and json_validator(conf.io_request_template) + return validate_propositions_json(conf.propositions_json) and json_validator(conf.io_request_template) end return { @@ -27,21 +52,19 @@ return { { propositions_json = { type = "string", - default = "[\n {\n \"condition\":\"extract('a') == 'x' and extract('b') == 'y'\",\n \"value\":\"alpha.com\"\n },\n {\n \"condition\":\"extract('a') == z or extract('b') == 'z'\",\n \"value\":\"beta.com\"\n },\n {\n \"condition\":\"default\",\n \"value\":\"default.com\"\n }\n]" + default = "[\n {\n \"condition\":\"extract_from_io_response('a') == 'x' and extract_from_io_response('b') == 'y'\",\n \"upstream_url\":\"alpha.com\"\n },\n {\n \"condition\":\"extract_from_io_response('a') == z or extract_from_io_response('b') == 'z'\",\n \"upstream_url\":\"beta.com\"\n },\n {\n \"condition\":\"default\",\n \"upstream_url\":\"default.com\"\n }\n]" } }, { io_url = { type = "string", - default = "http://192.168.1.40/round" - + default = "http://io-call%placeholder%/round" } }, { io_request_template = { type = "string", - default = "{\n \"header\": {\n \"a\":extract_from_request(\"header.x\")\n },\n \"query\": {\n \"b\": extract_from_request(\"query.y\")\n },\n \"body\": {\n \"c\": extract_from_request(\"body.z\"),\n \"d\": \"hardcoded\"\n }\n}" - + default = "{\n \"headers\": {\n \"a\":\"headers.x\"\n },\n \"query\": {\n \"b\": \"query.y\"\n },\n \"body\": {\n \"c\": \"query.z\",\n \"d\": \"hardcoded\"\n }\n}" } }, { diff --git a/kong/plugins/advanced-router/utils.lua b/kong/plugins/advanced-router/utils.lua index df56af7..1ac96a5 100644 --- a/kong/plugins/advanced-router/utils.lua +++ b/kong/plugins/advanced-router/utils.lua @@ -1,6 +1,7 @@ local pl_utils = require "pl.utils" local sha256 = require "resty.sha256" local encode_base64 = ngx.encode_base64 +local inspect = require "inspect" local _M = {} @@ -8,15 +9,18 @@ function _M.replaceStringEnvVariables(s, data) return string.gsub( s, - "%%[A-Za-z_]+%%", + "%%[A-Za-z_%.]+%%", function(str) + local variable = string.sub(str, 2, string.len(str) - 1) + kong.log.debug("string=" .. variable) if data then local value_from_data = _M.extract(variable, data) if value_from_data then return value_from_data end end + kong.log.debug("from env=" .. inspect(os.getenv(variable))) return os.getenv(variable) end ) diff --git a/spec/advanced-router/01-access_spec.lua b/spec/advanced-router/01-access_spec.lua index 815ab5c..f0e1739 100644 --- a/spec/advanced-router/01-access_spec.lua +++ b/spec/advanced-router/01-access_spec.lua @@ -1,86 +1,303 @@ ---local helpers = require "spec.helpers" --- ---for _, strategy in helpers.each_strategy() do --- describe("circuit breaker plugin [#" .. strategy .. "]", function() --- local mock_host = helpers.mock_upstream_host; --- --- local bp, db = helpers.get_db_utils(strategy, {"routes", "services", "plugins"}, {"advanced-router"}); --- --- local test_service = bp.services:insert( --- { --- protocol = "http", --- host = mock_host, -- Just a dummy value. Not honoured --- port = mock_port, -- Just a dummy value. Not honoured --- name = "test", --- connect_timeout = 2000 --- }) --- --- assert(bp.routes:insert({ --- methods = {"GET"}, --- protocols = {"http"}, --- paths = {"/main_route"}, --- strip_path = false, --- preserve_host = true, --- service = test_service --- })) --- --- assert(bp.routes:insert({ --- methods = {"GET"}, --- protocols = {"http"}, --- paths = {"/test"}, --- strip_path = false, --- preserve_host = true, --- service = test_service --- })) --- --- --- --- local get_and_assert = function (res_status_to_be_generated, res_status_expected, put_delay) --- local proxy_client = helpers.proxy_client() --- local res = assert(proxy_client:send( --- { --- method = "GET", --- path = "/test", --- headers = {response_http_code = res_status_to_be_generated, put_delay = put_delay or 0} --- })) --- assert.are.same(res_status_expected, res.status) --- proxy_client:close() --- end --- --- local change_config = function (patch) --- local admin_client = helpers.admin_client() --- local url = "/plugins/" .. circuit_breaker_plugin["id"] --- --- local admin_res = assert( --- admin_client:patch(url, { --- headers = {["Content-Type"] = "application/json"}, --- body = { --- name = "advanced-router", --- config = patch --- } --- })) --- assert.res_status(200, admin_res) --- admin_client:close() --- end --- --- assert(helpers.start_kong({ --- database = strategy, --- plugins = "advanced-router", --- nginx_conf = "spec/fixtures/custom_nginx.template" --- }, nil, nil, fixtures.fixtures)) --- --- --- --- lazy_teardown(function() --- db:truncate() --- end) --- --- before_each(function () --- --- end) --- after_each(function () --- helpers.stop_kong() --- end) --- --- end) ---end +local helpers = require "spec.helpers" +local cjson = require "cjson.safe" +local inspect = require "inspect" + +for _, strategy in helpers.each_strategy() do + + describe("advanced router plugin I/O data from headers [#" .. strategy .. "]", function() + local KONG_IO_CALL_HOST_ENV = "-io-call" + local KONG_SERVICE_ONE_HOST_ENV = "-one" + + local service_io_call_host_variable = 'service%KONG_IO_CALL_HOST_ENV%.com' + local service_io_call_host = 'service' .. KONG_IO_CALL_HOST_ENV .. '.com' + + local service_one_host = 'service' .. KONG_SERVICE_ONE_HOST_ENV .. '.com' + local service_one_host_interpolate = 'service%KONG_SERVICE_ONE_HOST_ENV%.com' + + local service_two_host = 'service-two.com' + local service_two_host_interpolate = 'service%data.service_host%.com' + + local service_default_host = 'service-default.com' + + local service_io_call_route = '/io-call' + local service_one_route = '/service-one-route' + local service_two_route = '/service-two-route' + local service_default_route = '/service-default-route' + + local bp, db = helpers.get_db_utils(strategy, { "routes", "services", "plugins" }, { "advanced-router" }); + + + local fixtures = { + dns_mock = helpers.dns_mock.new() + } + + fixtures.dns_mock:SRV { + name = service_one_host, + target = "127.0.0.1", + port = 15555 + } + fixtures.dns_mock:SRV { + name = service_two_host, + target = "127.0.0.1", + port = 15555 + } + fixtures.dns_mock:SRV { + name = service_default_host, + target = "127.0.0.1", + port = 15555 + } + fixtures.dns_mock:SRV { + name = service_io_call_host, + target = "127.0.0.1", + port = 15555 + } + + function setup_db(propositions_json, io_request_template, service_io_call_host) + local test_service = assert(bp.services:insert( + { + protocol = "http", + host = "dummy", + port = 15555, + name = "test", + connect_timeout = 2000 + })) + + local main_route = assert(bp.routes:insert({ + methods = { "GET", "POST" }, + protocols = { "http" }, + paths = { "/main-route" }, + strip_path = false, + preserve_host = true, + service = test_service, + })) + + assert(bp.plugins:insert { + name = "advanced-router", + config = { + propositions_json = cjson.encode(propositions_json), + io_url = "http://" .. service_io_call_host .. service_io_call_route, + io_request_template = cjson.encode(io_request_template), + cache_io_response = true, + io_http_method = "GET", + cache_ttl_header = "edge_ttl", + default_edge_ttl_sec = 10 + }, + route = main_route + }) + + assert(helpers.start_kong({ + SERVICE_ONE_HOST_ENV = KONG_SERVICE_ONE_HOST_ENV, + IO_CALL_HOST_ENV = KONG_IO_CALL_HOST_ENV, + database = strategy, + plugins = "bundled, advanced-router", + nginx_conf = "/kong-plugin/spec/fixtures/custom_nginx.template" + }, nil, nil, fixtures)) + end + + function assert_upstream(expected, resp) + local fields_to_verify = { 'host', 'uri', 'scheme' } + for _, v in ipairs(fields_to_verify) do + assert.are.same(expected[v], resp['vars'][v]) + end + end + + function get_and_assert_upstream(req_data, expected_resp) + local proxy_client = helpers.proxy_client() + + local res = assert(proxy_client:send( + { + method = req_data.method or "GET", + path = "/main-route", + headers = kong.table.merge({ ['Content-type'] = 'application/json' }, req_data.headers), + query = req_data.query, + body = cjson.encode(req_data.body) + })) + assert.are.same(200, res.status) + local res_body = assert(res:read_body()) + res_body = cjson.decode(res_body) + assert_upstream(expected_resp, res_body) + proxy_client:close() + end + + describe("Should generate correct I/O call using I/O request template #template", function() + + lazy_setup(function() + local propositions_json = { + { condition = "extract_from_io_response('data.service_host') == '-one' and extract_from_io_response('data.route') == '/one'", upstream_url = "http://" .. service_one_host .. service_one_route }, + { condition = "default", upstream_url = "http://" .. service_default_host .. service_default_route }, + } + + local io_request_template = { + headers = { + ['service_host'] = "headers.service_host", + ['route'] = "headers.route" + }, + query = { + ['service_host'] = "query.service_host", + ['route'] = "query.route" + }, + body = { + ['service_host'] = "query.service_host1", + ['route'] = "query.route1" + } + } + setup_db(propositions_json, io_request_template, service_io_call_host) + end) + + teardown(function() + helpers.stop_kong() + db:truncate() + end) + + it("Should send data in headers correctly #template_header", function() + local req_data = { headers = { service_host = '-one', route = '/one' } } + local expected_resp = { host = service_one_host, uri = service_one_route, scheme = 'http' } + get_and_assert_upstream(req_data, expected_resp) + end) + + it("Should send data in query parameters correctly #template_query", function() + local req_data = { query = { service_host = '-one', route = '/one' } } + local expected_resp = { host = service_one_host, uri = service_one_route, scheme = 'http' } + get_and_assert_upstream(req_data, expected_resp) + end) + + it("Should send data in body correctly #template_body", function() + local req_data = { query = { service_host1 = '-one', route1 = '/one', method = 'POST' } } + local expected_resp = { host = service_one_host, uri = service_one_route, scheme = 'http' } + get_and_assert_upstream(req_data, expected_resp) + end) + end) + + describe("Should evaluate conditions using IO data correctly #static", function() + + lazy_setup(function() + local propositions_json = { + { condition = "extract_from_io_response('data.service_host') == '-one' and extract_from_io_response('data.route') == '/one'", upstream_url = "http://" .. service_one_host .. service_one_route }, + { condition = "extract_from_io_response('data.service_host') == '-two' and extract_from_io_response('data.route') == '/two'", upstream_url = "http://" .. service_two_host .. service_two_route }, + { condition = "default", upstream_url = "http://" .. service_default_host .. service_default_route }, + } + + local io_request_template = { + headers = { + ['service_host'] = "headers.service_host", + ['route'] = "headers.route", + ['roundstarttime'] = "headers.roundstarttime" + } + } + setup_db(propositions_json, io_request_template, service_io_call_host) + end) + + teardown(function() + helpers.stop_kong() + db:truncate() + end) + + it("Should match first condition #service_one", function() + local req_data = { headers = { service_host = '-one', route = '/one', roundstarttime = "2925-10-17T11:15:14.000Z" } } + local expected_resp = { host = service_one_host, uri = service_one_route, scheme = 'http' } + get_and_assert_upstream(req_data, expected_resp) + end) + + it("Should match second condition #service_two", function() + local req_data = { headers = { service_host = '-two', route = '/two', roundstarttime = "1925-10-17T11:15:14.000Z" } } + local expected_resp = { host = service_two_host, uri = service_two_route, scheme = 'http' } + get_and_assert_upstream(req_data, expected_resp) + end) + + it("Should match default condition when none of the above is satisfied #service_default", function() + local req_data = { headers = { route = '/default', roundstarttime = "1925-10-17T11:15:14.000Z" } } + local expected_resp = { host = service_default_host, uri = service_default_route, scheme = 'http' } + get_and_assert_upstream(req_data, expected_resp) + end) + end) + + describe("Should evaluate conditions using timestamp correctly #time", function() + + lazy_setup(function() + local propositions_json = { + { condition = "get_timestamp_utc(extract_from_io_response('data.roundstarttime')) > get_current_timestamp_utc() and extract_from_io_response('data.route') == '/one'", upstream_url = "http://" .. service_one_host .. service_one_route }, + { condition = "get_timestamp_utc(extract_from_io_response('data.roundstarttime')) < get_current_timestamp_utc() and extract_from_io_response('data.route') == '/two'", upstream_url = "http://" .. service_two_host .. service_two_route }, + { condition = "default", upstream_url = "http://" .. service_default_host .. service_default_route }, + } + + local io_request_template = { + headers = { + ['service_host'] = "headers.service_host", + ['route'] = "headers.route", + ['roundstarttime'] = "headers.roundstarttime" + } + } + setup_db(propositions_json, io_request_template, service_io_call_host) + end) + + teardown(function() + helpers.stop_kong() + db:truncate() + end) + + it("Should match first condition #service_one1", function() + local req_data = { headers = { service_host = '-one', route = '/one', roundstarttime = "2925-10-17T11:15:14.000Z" } } + local expected_resp = { host = service_one_host, uri = service_one_route, scheme = 'http' } + get_and_assert_upstream(req_data, expected_resp) + end) + + it("Should match second condition #service_two2", function() + local req_data = { headers = { service_host = '-two', route = '/two', roundstarttime = "1925-10-17T11:15:14.000Z" } } + local expected_resp = { host = service_two_host, uri = service_two_route, scheme = 'http' } + get_and_assert_upstream(req_data, expected_resp) + end) + + it("Should match default condition #service_default1", function() + local req_data = { headers = { service_host = '-two', route = '/one', roundstarttime = "1925-10-17T11:15:14.000Z" } } + local expected_resp = { host = service_default_host, uri = service_default_route, scheme = 'http' } + get_and_assert_upstream(req_data, expected_resp) + end) + end) + + describe("Should interpolate I/O call host and Upstream urls correctly #interpolate", function() + + lazy_setup(function() + local propositions_json = { + { condition = "extract_from_io_response('data.service_host') == '-one' and extract_from_io_response('data.route') == '/one'", upstream_url = "http://" .. service_one_host_interpolate .. service_one_route }, + { condition = "extract_from_io_response('data.service_host') == '-two' and extract_from_io_response('data.route') == '/two'", upstream_url = "http://" .. service_two_host_interpolate .. service_two_route }, + { condition = "default", upstream_url = "http://" .. service_default_host .. service_default_route }, + } + + local io_request_template = { + headers = { + ['service_host'] = "headers.service_host", + ['route'] = "headers.route", + ['roundstarttime'] = "headers.roundstarttime" + } + } + setup_db(propositions_json, io_request_template, service_io_call_host_variable) + end) + + teardown(function() + helpers.stop_kong() + db:truncate() + end) + + it("Should interpolate I/O Host using environment variables #IOCall", function() + local req_data = { headers = { service_host = '-default', route = '/default' } } + local expected_resp = { host = service_default_host, uri = service_default_route, scheme = 'http' } + get_and_assert_upstream(req_data, expected_resp) + end) + + it("Should interpolate upstream_url of first condition from env variable #UpEnv", function() + local req_data = { headers = { service_host = '-one', route = '/one' } } + local expected_resp = { host = service_one_host, uri = service_one_route, scheme = 'http' } + get_and_assert_upstream(req_data, expected_resp) + end) + + it("Should interpolate upstream_url of second condition from I/O data #UpIO", function() + local req_data = { headers = { service_host = '-two', route = '/two' } } + local expected_resp = { host = service_two_host, uri = service_two_route, scheme = 'http' } + get_and_assert_upstream(req_data, expected_resp) + end) + + end) + + end) + break +end diff --git a/spec/fixtures/custom_nginx.template b/spec/fixtures/custom_nginx.template index 3c8aa25..35b1727 100644 --- a/spec/fixtures/custom_nginx.template +++ b/spec/fixtures/custom_nginx.template @@ -8,7 +8,7 @@ error_log ${{PROXY_ERROR_LOG}} ${{LOG_LEVEL}}; $(el.name) $(el.value); > end -env ENV_ONE; env ENV_TWO; +env KONG_SERVICE_ONE_HOST_ENV; env KONG_IO_CALL_HOST_ENV; events { # injected nginx_events_* directives @@ -447,16 +447,6 @@ http { } } - location /get { - default_type application/json; - content_by_lua_block { - Kong.status_content() - } - header_filter_by_lua_block { - Kong.status_header_filter() - } - } - location /nginx_status { internal; access_log off; @@ -551,15 +541,94 @@ http { } } - location /gethost { + location /io-call { access_by_lua_block { local mu = require "spec.fixtures.mock_upstream" return mu.filter_access_by_method("GET") } content_by_lua_block { + + local cjson = require "cjson.safe" + local inspect = require "inspect" + + local mu = require "spec.fixtures.mock_upstream" local incoming_headers = ngx.req.get_headers() + local uri_args = ngx.req.get_uri_args() + ngx.req.read_body() + local request_body = ngx.req.get_body_data() + if request_body then + request_body = cjson.decode(request_body) + end + + ngx.header["Content-Type"] = "application/json" + print("incoming_headers::" .. inspect(incoming_headers)) + print("uri_args::" .. inspect(uri_args)) + print("request_body::" .. inspect(request_body)) + + local data = {} + + if incoming_headers.service_host then + + data = { + service_host = incoming_headers.service_host, + route = incoming_headers.route, + roundstarttime = incoming_headers.roundstarttime + } + elseif uri_args.service_host then + data = { + service_host = uri_args.service_host, + route = uri_args.route, + roundstarttime = uri_args.roundstarttime + } + elseif request_body.service_host then + data = { + service_host = request_body.service_host, + route = request_body.route, + roundstarttime = request_body.roundstarttime + } + end + return mu.send_default_json_response({data = data}) + } + } + + location /main-route { + access_by_lua_block { local mu = require "spec.fixtures.mock_upstream" - return mu.send_default_json_response({}, {["incoming-host"] = incoming_headers["host"]}) + return mu.filter_access_by_method("GET") + } + content_by_lua_block { + local mu = require "spec.fixtures.mock_upstream" + return mu.send_default_json_response() + } + } + location /service-one-route { + access_by_lua_block { + local mu = require "spec.fixtures.mock_upstream" + return mu.filter_access_by_method("GET") + } + content_by_lua_block { + local mu = require "spec.fixtures.mock_upstream" + return mu.send_default_json_response() + } + } + location /service-two-route { + access_by_lua_block { + local mu = require "spec.fixtures.mock_upstream" + return mu.filter_access_by_method("GET") + } + content_by_lua_block { + local mu = require "spec.fixtures.mock_upstream" + return mu.send_default_json_response() + } + } + location /service-default-route { + access_by_lua_block { + local mu = require "spec.fixtures.mock_upstream" + return mu.filter_access_by_method("GET") + } + content_by_lua_block { + local mu = require "spec.fixtures.mock_upstream" + return mu.send_default_json_response() } }