From 9f29a06545633a84db1e4f56b05cc39d7950d621 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Tue, 22 Mar 2016 17:34:54 -0700 Subject: [PATCH 1/3] refactor(constants) introduce _G._KONG - introduce kong.meta - introduce a _KONG global that contains _NAME and _VERSION - nuke constants when not relevant (plugin-specific and such) --- .luacheckrc | 24 ---------- Makefile | 15 +++--- bin/kong | 5 +- kong-0.7.0-0.rockspec | 1 - kong/api/routes/kong.lua | 17 ++++--- kong/cli/cmds/start.lua | 9 ++-- kong/cli/cmds/version.lua | 4 +- kong/cli/utils/luarocks.lua | 47 ------------------- kong/constants.lua | 10 ---- kong/core/error_handlers.lua | 5 +- kong/core/handler.lua | 17 ++----- kong/kong.lua | 13 +++-- kong/meta.lua | 16 +++++++ kong/plugins/basic-auth/access.lua | 17 ++++--- kong/plugins/key-auth/handler.lua | 10 ++-- kong/tools/responses.lua | 5 +- kong/tools/syslog.lua | 10 ++-- .../admin_api/kong_routes_spec.lua | 35 +++++++------- spec/integration/cli/cmds/version_spec.lua | 10 ++-- spec/integration/proxy/resolver_spec.lua | 5 +- spec/plugins/basic-auth/access_spec.lua | 6 +-- spec/plugins/key-auth/access_spec.lua | 14 +++--- spec/unit/statics_spec.lua | 5 +- spec/unit/tools/responses_spec.lua | 22 ++------- spec/unit/tools/syslog_spec.lua | 13 +++-- 25 files changed, 129 insertions(+), 206 deletions(-) delete mode 100644 .luacheckrc delete mode 100644 kong/cli/utils/luarocks.lua create mode 100644 kong/meta.lua diff --git a/.luacheckrc b/.luacheckrc deleted file mode 100644 index aad87cb2bb1..00000000000 --- a/.luacheckrc +++ /dev/null @@ -1,24 +0,0 @@ -redefined = false -unused_args = false -globals = {"ngx", "app"} - -files["kong/"] = { - std = "luajit" -} - -files["kong/vendor/lapp.lua"] = { - ignore = {"lapp", "typespec"} -} - -files["kong/vendor/ssl.lua"] = { - ignore = {"FFI_DECLINED"} -} - -files["kong/vendor/resty_http.lua"] = { - global = false, - unused = false -} - -files["spec/"] = { - globals = {"describe", "it", "before_each", "setup", "after_each", "teardown", "stub", "mock", "spy", "finally", "pending", "build"} -} diff --git a/Makefile b/Makefile index de8748f685d..0957c616c78 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,14 @@ doc: @ldoc -c config.ld kong lint: - @find kong spec -name '*.lua' -not -name 'invalid-module.lua' -not -path 'kong/vendor/*' | xargs luacheck -q + @luacheck -q . \ + --exclude-files 'kong/vendor/**/*.lua' \ + --exclude-files 'spec/unit/fixtures/invalid-module.lua' \ + --std 'ngx_lua+busted' \ + --globals '_KONG' \ + --globals 'ngx' \ + --no-redefined \ + --no-unused-args test: @busted -v spec/unit @@ -50,12 +57,6 @@ test-plugins: test-all: @busted -v spec/ -test-model: - @busted -v -o gtest spec/integration/model - -test-model-only: - @busted -v -o gtest --tags=only spec/integration/model - coverage: @rm -f luacov.* @busted --coverage spec/ diff --git a/bin/kong b/bin/kong index 59de54d7b6d..0b4e0fce8af 100755 --- a/bin/kong +++ b/bin/kong @@ -10,8 +10,7 @@ -- This script is not parsed by lapp due to limitations of the said framework as it -- is currently implemented. -local luarocks = require "kong.cli.utils.luarocks" -local infos = luarocks.get_kong_infos() +local meta = require "kong.meta" local commands = { db = "kong.cli.cmds.db", stop = "kong.cli.cmds.stop", @@ -36,7 +35,7 @@ Usage: kong kong --help print this message kong --help print the help message of a command -%s@%s]], infos.name, infos.version) +%s@%s]], meta.name, tostring(meta.version)) -- Determine validity of the given command local cmd = arg[1] diff --git a/kong-0.7.0-0.rockspec b/kong-0.7.0-0.rockspec index 1cc3c6ca9ae..ed6ccd3c3fe 100644 --- a/kong-0.7.0-0.rockspec +++ b/kong-0.7.0-0.rockspec @@ -48,7 +48,6 @@ build = { ["kong.singletons"] = "kong/singletons.lua", ["kong.cli.utils.logger"] = "kong/cli/utils/logger.lua", - ["kong.cli.utils.luarocks"] = "kong/cli/utils/luarocks.lua", ["kong.cli.utils.ssl"] = "kong/cli/utils/ssl.lua", ["kong.cli.utils.input"] = "kong/cli/utils/input.lua", ["kong.cli.utils.services"] = "kong/cli/utils/services.lua", diff --git a/kong/api/routes/kong.lua b/kong/api/routes/kong.lua index 5dc06e93e98..79cb7585b58 100644 --- a/kong/api/routes/kong.lua +++ b/kong/api/routes/kong.lua @@ -1,7 +1,10 @@ +local utils = require "kong.tools.utils" local singletons = require "kong.singletons" -local constants = require "kong.constants" local route_helpers = require "kong.api.route_helpers" -local utils = require "kong.tools.utils" + +local tagline = "Welcome to ".._KONG._NAME +local version = _KONG._VERSION +local lua_version = jit and jit.version or _VERSION return { ["/"] = { @@ -21,9 +24,9 @@ return { distinct_plugins[#distinct_plugins + 1] = plugin_name end - return helpers.responses.send_HTTP_OK({ - tagline = "Welcome to Kong", - version = constants.VERSION, + return helpers.responses.send_HTTP_OK { + tagline = tagline, + version = version, hostname = utils.get_hostname(), timers = { running = ngx.timer.running_count(), @@ -33,9 +36,9 @@ return { available_on_server = singletons.configuration.plugins, enabled_in_cluster = distinct_plugins }, - lua_version = jit and jit.version or _VERSION, + lua_version = lua_version, configuration = singletons.configuration - }) + } end }, ["/status"] = { diff --git a/kong/cli/cmds/start.lua b/kong/cli/cmds/start.lua index f20efb7ce34..d9620b3e479 100755 --- a/kong/cli/cmds/start.lua +++ b/kong/cli/cmds/start.lua @@ -1,9 +1,10 @@ #!/usr/bin/env luajit -local constants = require "kong.constants" -local config_loader = require "kong.tools.config_loader" +local meta = require "kong.meta" local logger = require "kong.cli.utils.logger" local services = require "kong.cli.utils.services" +local constants = require "kong.constants" +local config_loader = require "kong.tools.config_loader" local args = require("lapp")(string.format([[ Start Kong with given configuration. Kong will run in the configured 'nginx_working_dir' directory. @@ -14,7 +15,7 @@ Options: -c,--config (default %s) path to configuration file ]], constants.CLI.GLOBAL_KONG_CONF)) -logger:info("Kong "..constants.VERSION) +logger:info(meta.name.." "..tostring(meta.version)) local configuration, configuration_path = config_loader.load_default(args.config) @@ -35,4 +36,4 @@ if not ok then os.exit(1) end -logger:success("Started") \ No newline at end of file +logger:success("Started") diff --git a/kong/cli/cmds/version.lua b/kong/cli/cmds/version.lua index 312fd46810f..60fe6c18d70 100644 --- a/kong/cli/cmds/version.lua +++ b/kong/cli/cmds/version.lua @@ -1,6 +1,6 @@ #!/usr/bin/env luajit local logger = require "kong.cli.utils.logger" -local constants = require "kong.constants" +local meta = require "kong.meta" -logger:print(string.format("Kong version: %s", constants.VERSION)) +logger:print(string.format("%s version: %s", meta.name, tostring(meta.version))) diff --git a/kong/cli/utils/luarocks.lua b/kong/cli/utils/luarocks.lua deleted file mode 100644 index 2f27b7849ae..00000000000 --- a/kong/cli/utils/luarocks.lua +++ /dev/null @@ -1,47 +0,0 @@ -local constants = require "kong.constants" -local lpath = require "luarocks.path" - -local Luarocks = {} - --- --- Luarocks --- -function Luarocks.get_kong_infos() - return { name = constants.NAME, version = constants.ROCK_VERSION } -end - -function Luarocks.get_dir() - local cfg = require "luarocks.cfg" - local search = require "luarocks.search" - local infos = Luarocks.get_kong_infos() - - local tree_map = {} - local results = {} - - for _, tree in ipairs(cfg.rocks_trees) do - local rocks_dir = lpath.rocks_dir(tree) - tree_map[rocks_dir] = tree - search.manifest_search(results, rocks_dir, search.make_query(infos.name:lower(), infos.version)) - end - - local version - for k, _ in pairs(results.kong) do - version = k - end - - return tree_map[results.kong[version][1].repo] -end - -function Luarocks.get_config_dir() - local repo = Luarocks.get_dir() - local infos = Luarocks.get_kong_infos() - return lpath.conf_dir(infos.name:lower(), infos.version, repo) -end - -function Luarocks.get_install_dir() - local repo = Luarocks.get_dir() - local infos = Luarocks.get_kong_infos() - return lpath.install_dir(infos.name:lower(), infos.version, repo) -end - -return Luarocks \ No newline at end of file diff --git a/kong/constants.lua b/kong/constants.lua index 4ff64180bd3..dab5a3f0fba 100644 --- a/kong/constants.lua +++ b/kong/constants.lua @@ -1,9 +1,4 @@ -local VERSION = "0.7.0" - return { - NAME = "kong", - VERSION = VERSION, - ROCK_VERSION = VERSION.."-0", SYSLOG = { ADDRESS = "kong-hf.mashape.com", PORT = 61828, @@ -32,11 +27,6 @@ return { RATELIMIT_LIMIT = "X-RateLimit-Limit", RATELIMIT_REMAINING = "X-RateLimit-Remaining" }, - AUTHENTICATION = { - QUERY = "query", - BASIC = "basic", - HEADER = "header" - }, RATELIMIT = { PERIODS = { "second", diff --git a/kong/core/error_handlers.lua b/kong/core/error_handlers.lua index 570c9b2356d..642ebead6b6 100644 --- a/kong/core/error_handlers.lua +++ b/kong/core/error_handlers.lua @@ -1,4 +1,3 @@ -local constants = require "kong.constants" local find = string.find local format = string.format @@ -20,7 +19,7 @@ local BODIES = { default = "The upstream server responded with %d" } -local SERVER_HEADER = constants.NAME.."/"..constants.VERSION +local SERVER_HEADER = _KONG._NAME.."/".._KONG._VERSION return function(ngx) local accept_header = ngx.req.get_headers()["accept"] @@ -49,4 +48,4 @@ return function(ngx) ngx.header["Server"] = SERVER_HEADER ngx.header["Content-Type"] = content_type ngx.say(format(template, message)) -end \ No newline at end of file +end diff --git a/kong/core/handler.lua b/kong/core/handler.lua index 5ebb90de271..9fc2f18b3e0 100644 --- a/kong/core/handler.lua +++ b/kong/core/handler.lua @@ -7,24 +7,15 @@ -- -- In the `access_by_lua` phase, it is responsible for retrieving the API being proxied by -- a Consumer. Then it is responsible for loading the plugins to execute on this request. --- --- In other phases, we create different variables and timers. --- Variables: --- `plugins_to_execute`: an array of plugin to be executed for this request. --- Timers: --- `KONG__STARTED_AT`: time at which a given context is started to be executed by all Kong plugins. --- `KONG__ENDED_AT`: time at which all plugins have been executed by Kong for this context. --- `KONG__TIME`: time taken by Kong to execute all the plugins for this context --- --- @see https://github.com/openresty/lua-nginx-module#ngxctx -local reports = require "kong.core.reports" local utils = require "kong.tools.utils" +local reports = require "kong.core.reports" local cluster = require "kong.core.cluster" local resolver = require "kong.core.resolver" local constants = require "kong.constants" local certificate = require "kong.core.certificate" local ngx_now = ngx.now +local server_header = _KONG._NAME.."/".._KONG._VERSION local function get_now() return ngx_now() * 1000 -- time is kept in seconds with millisecond resolution. @@ -81,9 +72,9 @@ return { if ngx.ctx.KONG_PROXIED then ngx.header[constants.HEADERS.UPSTREAM_LATENCY] = ngx.ctx.KONG_WAITING_TIME ngx.header[constants.HEADERS.PROXY_LATENCY] = ngx.ctx.KONG_PROXY_LATENCY - ngx.header["Via"] = constants.NAME.."/"..constants.VERSION + ngx.header["Via"] = server_header else - ngx.header["Server"] = constants.NAME.."/"..constants.VERSION + ngx.header["Server"] = server_header end end }, diff --git a/kong/kong.lua b/kong/kong.lua index e60377fb9ab..1fbf29634a3 100644 --- a/kong/kong.lua +++ b/kong/kong.lua @@ -24,14 +24,21 @@ -- |[[ ]]| -- ========== +local meta = require "kong.meta" + +_G._KONG = { + _NAME = meta.name, + _VERSION = tostring(meta.version) +} + local core = require "kong.core.handler" -local singletons = require "kong.singletons" +local Serf = require "kong.cli.services.serf" local utils = require "kong.tools.utils" +local Events = require "kong.core.events" +local singletons = require "kong.singletons" local dao_loader = require "kong.tools.dao_loader" local config_loader = require "kong.tools.config_loader" local plugins_iterator = require "kong.core.plugins_iterator" -local Events = require "kong.core.events" -local Serf = require "kong.cli.services.serf" local ipairs = ipairs local table_insert = table.insert diff --git a/kong/meta.lua b/kong/meta.lua new file mode 100644 index 00000000000..fb6eee1d6e7 --- /dev/null +++ b/kong/meta.lua @@ -0,0 +1,16 @@ +local version = setmetatable({ + major = 0, + minor = 7, + patch = 0, + --pre_release = "alpha" +}, { + __tostring = function(t) + return string.format("%d.%d.%d%s", t.major, t.minor, t.patch, + t.pre_release and "-"..t.pre_release or "") + end +}) + +return { + name = "Kong", + version = version +} diff --git a/kong/plugins/basic-auth/access.lua b/kong/plugins/basic-auth/access.lua index 2b0c83bd9ec..7fabd332343 100644 --- a/kong/plugins/basic-auth/access.lua +++ b/kong/plugins/basic-auth/access.lua @@ -1,12 +1,11 @@ -local singletons = require "kong.singletons" local cache = require "kong.tools.database_cache" +local crypto = require "kong.plugins.basic-auth.crypto" local stringy = require "stringy" -local responses = require "kong.tools.responses" +local singletons = require "kong.singletons" local constants = require "kong.constants" -local crypto = require "kong.plugins.basic-auth.crypto" +local responses = require "kong.tools.responses" -local AUTHORIZATION = "authorization" -local PROXY_AUTHORIZATION = "proxy-authorization" +local realm = 'Basic realm="'.._KONG._NAME..'"' local _M = {} @@ -84,20 +83,20 @@ end function _M.execute(conf) -- If both headers are missing, return 401 - if not (ngx.req.get_headers()[AUTHORIZATION] or ngx.req.get_headers()[PROXY_AUTHORIZATION]) then - ngx.header["WWW-Authenticate"] = "Basic realm=\""..constants.NAME.."\"" + if not (ngx.req.get_headers()["authorization"] or ngx.req.get_headers()["proxy-authorization"]) then + ngx.header["WWW-Authenticate"] = realm return responses.send_HTTP_UNAUTHORIZED() end local credential - local given_username, given_password = retrieve_credentials(ngx.req, PROXY_AUTHORIZATION, conf) + local given_username, given_password = retrieve_credentials(ngx.req, "proxy-authorization", conf) if given_username then credential = load_credential_from_db(given_username) end -- Try with the authorization header if not credential then - given_username, given_password = retrieve_credentials(ngx.req, AUTHORIZATION, conf) + given_username, given_password = retrieve_credentials(ngx.req, "authorization", conf) credential = load_credential_from_db(given_username) end diff --git a/kong/plugins/key-auth/handler.lua b/kong/plugins/key-auth/handler.lua index 33a9c873ae5..478a8e5a99b 100644 --- a/kong/plugins/key-auth/handler.lua +++ b/kong/plugins/key-auth/handler.lua @@ -4,6 +4,8 @@ local responses = require "kong.tools.responses" local constants = require "kong.constants" local BasePlugin = require "kong.plugins.base_plugin" +local realm = 'Key realm="'.._KONG._NAME..'"' + local KeyAuthHandler = BasePlugin:extend() KeyAuthHandler.PRIORITY = 1000 @@ -17,7 +19,7 @@ KeyAuthHandler.PRIORITY = 1000 -- @return {string} public_key -- @return {string} private_key local retrieve_credentials = { - [constants.AUTHENTICATION.HEADER] = function(request, conf) + header = function(request, conf) local key local headers = request.get_headers() @@ -35,7 +37,7 @@ local retrieve_credentials = { end end end, - [constants.AUTHENTICATION.QUERY] = function(request, conf) + query = function(request, conf) if conf.key_names then local key local uri_params = request.get_uri_args() @@ -60,7 +62,7 @@ end function KeyAuthHandler:access(conf) KeyAuthHandler.super.access(self) local key, key_found, credential - for _, v in ipairs({ constants.AUTHENTICATION.QUERY, constants.AUTHENTICATION.HEADER }) do + for _, v in ipairs({"query", "header"}) do key = retrieve_credentials[v](ngx.req, conf) if key then key_found = true @@ -80,7 +82,7 @@ function KeyAuthHandler:access(conf) -- No key found in the request's headers or parameters if not key_found then - ngx.header["WWW-Authenticate"] = "Key realm=\""..constants.NAME.."\"" + ngx.header["WWW-Authenticate"] = realm return responses.send_HTTP_UNAUTHORIZED("No API Key found in headers, body or querystring") end diff --git a/kong/tools/responses.lua b/kong/tools/responses.lua index 027d8352c69..ac027d2771b 100644 --- a/kong/tools/responses.lua +++ b/kong/tools/responses.lua @@ -14,9 +14,10 @@ -- -- -- Raw send() helper: -- return responses.send(418, "This is a teapot") -local constants = require "kong.constants" local cjson = require "cjson" +local server_header = _KONG._NAME.."/".._KONG._VERSION + --- Define the most common HTTP status codes for sugar methods. -- Each of those status will generate a helper method (sugar) -- attached to this exported module prefixed with `send_`. @@ -99,7 +100,7 @@ local function send_response(status_code) ngx.status = status_code ngx.header["Content-Type"] = "application/json; charset=utf-8" - ngx.header["Server"] = constants.NAME.."/"..constants.VERSION + ngx.header["Server"] = server_header if headers then for k, v in pairs(headers) do diff --git a/kong/tools/syslog.lua b/kong/tools/syslog.lua index f24f8db939e..8ee470da183 100644 --- a/kong/tools/syslog.lua +++ b/kong/tools/syslog.lua @@ -1,7 +1,9 @@ -local constants = require "kong.constants" local IO = require "kong.tools.io" -local stringy = require "stringy" local cjson = require "cjson" +local stringy = require "stringy" +local constants = require "kong.constants" + +local version = _KONG._VERSION local _M = {} @@ -9,7 +11,7 @@ function _M.log(args) if not args then args = {} end -- Kong Version - args["version"] = constants.VERSION + args["version"] = version -- CPU cores local res, code = IO.os_execute("getconf _NPROCESSORS_ONLN") @@ -58,4 +60,4 @@ function _M.format_entity(t) return t end -return _M \ No newline at end of file +return _M diff --git a/spec/integration/admin_api/kong_routes_spec.lua b/spec/integration/admin_api/kong_routes_spec.lua index 1706c914e90..7d63f337418 100644 --- a/spec/integration/admin_api/kong_routes_spec.lua +++ b/spec/integration/admin_api/kong_routes_spec.lua @@ -1,7 +1,8 @@ local json = require "cjson" +local utils = require "kong.tools.utils" local http_client = require "kong.tools.http_client" local spec_helper = require "spec.spec_helpers" -local utils = require "kong.tools.utils" + local env = spec_helper.get_env() -- test environment local dao_factory = env.dao_factory @@ -18,7 +19,7 @@ describe("Admin API", function() describe("Kong routes", function() describe("/", function() - local constants = require "kong.constants" + local meta = require "kong.meta" it("should return Kong's version and a welcome message", function() local response, status = http_client.get(spec_helper.API_URL) @@ -26,32 +27,32 @@ describe("Admin API", function() local body = json.decode(response) assert.truthy(body.version) assert.truthy(body.tagline) - assert.are.same(constants.VERSION, body.version) + assert.equal(tostring(meta.version), body.version) end) it("should have a Server header", function() local _, status, headers = http_client.get(spec_helper.API_URL) - assert.are.same(200, status) - assert.are.same(string.format("%s/%s", constants.NAME, constants.VERSION), headers.server) + assert.equal(200, status) + assert.equal(string.format("%s/%s", meta.name, tostring(meta.version)), headers.server) assert.falsy(headers.via) -- Via is only set for proxied requests end) it("should return method not allowed", function() local res, status = http_client.post(spec_helper.API_URL) - assert.are.same(405, status) - assert.are.same("Method not allowed", json.decode(res).message) + assert.equal(405, status) + assert.equal("Method not allowed", json.decode(res).message) local res, status = http_client.delete(spec_helper.API_URL) - assert.are.same(405, status) - assert.are.same("Method not allowed", json.decode(res).message) + assert.equal(405, status) + assert.equal("Method not allowed", json.decode(res).message) local res, status = http_client.put(spec_helper.API_URL) - assert.are.same(405, status) - assert.are.same("Method not allowed", json.decode(res).message) + assert.equal(405, status) + assert.equal("Method not allowed", json.decode(res).message) local res, status = http_client.patch(spec_helper.API_URL) - assert.are.same(405, status) - assert.are.same("Method not allowed", json.decode(res).message) + assert.equal(405, status) + assert.equal("Method not allowed", json.decode(res).message) end) end) end) @@ -59,21 +60,21 @@ describe("Admin API", function() describe("/status", function() it("should return status information", function() local response, status = http_client.get(spec_helper.API_URL.."/status") - assert.are.equal(200, status) + assert.equal(200, status) local body = json.decode(response) assert.truthy(body) - assert.are.equal(2, utils.table_size(body)) + assert.equal(2, utils.table_size(body)) -- Database stats -- Removing migrations DAO dao_factory.daos.migrations = nil - assert.are.equal(utils.table_size(dao_factory.daos), utils.table_size(body.database)) + assert.equal(utils.table_size(dao_factory.daos), utils.table_size(body.database)) for k, _ in pairs(dao_factory.daos) do assert.truthy(body.database[k]) end -- Server stats - assert.are.equal(7, utils.table_size(body.server)) + assert.equal(7, utils.table_size(body.server)) assert.truthy(body.server.connections_accepted) assert.truthy(body.server.connections_active) assert.truthy(body.server.connections_handled) diff --git a/spec/integration/cli/cmds/version_spec.lua b/spec/integration/cli/cmds/version_spec.lua index 190fbf8ff8d..f2129a1bb95 100644 --- a/spec/integration/cli/cmds/version_spec.lua +++ b/spec/integration/cli/cmds/version_spec.lua @@ -1,13 +1,11 @@ -local spec_helper = require "spec.spec_helpers" -local constants = require "kong.constants" -local stringy = require "stringy" local IO = require "kong.tools.io" +local meta = require "kong.meta" +local stringy = require "stringy" +local spec_helper = require "spec.spec_helpers" describe("CLI", function() - it("should return the right version", function() local result = IO.os_execute(spec_helper.KONG_BIN.." version") - assert.are.same("Kong version: "..constants.VERSION, stringy.strip(result)) + assert.equal(meta.name.." version: "..tostring(meta.version), stringy.strip(result)) end) - end) diff --git a/spec/integration/proxy/resolver_spec.lua b/spec/integration/proxy/resolver_spec.lua index 76274b4455d..255ecc75c68 100644 --- a/spec/integration/proxy/resolver_spec.lua +++ b/spec/integration/proxy/resolver_spec.lua @@ -1,6 +1,7 @@ local spec_helper = require "spec.spec_helpers" local ssl = require "ssl" local url = require "socket.url" +local meta = require "kong.meta" local cjson = require "cjson" local utils = require "kong.tools.utils" local socket = require "socket" @@ -174,12 +175,12 @@ describe("Resolver", function() local _, status, headers = http_client.get(STUB_GET_URL, nil, {host = "mockbin.com"}) assert.equal(200, status) assert.equal("cloudflare-nginx", headers.server) - assert.equal(constants.NAME.."/"..constants.VERSION, headers.via) + assert.equal(meta.name.."/"..tostring(meta.version), headers.via) end) it("should return the correct Server and no Via header when the request was NOT proxied", function() local _, status, headers = http_client.get(STUB_GET_URL, nil, {host = "mockbin-auth.com"}) assert.equal(401, status) - assert.equal(constants.NAME.."/"..constants.VERSION, headers.server) + assert.equal(meta.name.."/"..tostring(meta.version), headers.server) assert.falsy(headers.via) end) it("should return correct timing headers when the request was proxied", function() diff --git a/spec/plugins/basic-auth/access_spec.lua b/spec/plugins/basic-auth/access_spec.lua index 4872dfa7ceb..ad01ec589b7 100644 --- a/spec/plugins/basic-auth/access_spec.lua +++ b/spec/plugins/basic-auth/access_spec.lua @@ -1,6 +1,6 @@ local spec_helper = require "spec.spec_helpers" local http_client = require "kong.tools.http_client" -local constants = require "kong.constants" +local meta = require "kong.meta" local cjson = require "cjson" local PROXY_URL = spec_helper.PROXY_URL @@ -39,7 +39,7 @@ describe("Authentication Plugin", function() local response, status, headers = http_client.get(PROXY_URL.."/get", {}, {host = "basicauth.com"}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal(headers["www-authenticate"], "Basic realm=\""..constants.NAME.."\"") + assert.equal('Basic realm="'..meta.name..'"', headers["www-authenticate"]) assert.equal("Unauthorized", body.message) end) @@ -75,7 +75,7 @@ describe("Authentication Plugin", function() local response, status, headers = http_client.get(PROXY_URL.."/get", {}, {host = "basicauth.com", authorization123 = "Basic dXNlcm5hbWU6cGFzc3dvcmQ="}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal(headers["www-authenticate"], "Basic realm=\""..constants.NAME.."\"") + assert.equal('Basic realm="'..meta.name..'"', headers["www-authenticate"]) assert.equal("Unauthorized", body.message) end) diff --git a/spec/plugins/key-auth/access_spec.lua b/spec/plugins/key-auth/access_spec.lua index 40375e95b4e..b4acfd338dc 100644 --- a/spec/plugins/key-auth/access_spec.lua +++ b/spec/plugins/key-auth/access_spec.lua @@ -1,7 +1,7 @@ local spec_helper = require "spec.spec_helpers" local http_client = require "kong.tools.http_client" -local constants = require "kong.constants" local cjson = require "cjson" +local meta = require "kong.meta" local STUB_GET_URL = spec_helper.STUB_GET_URL local STUB_POST_URL = spec_helper.STUB_POST_URL @@ -40,7 +40,7 @@ describe("key-auth plugin", function() local response, status, headers = http_client.get(STUB_GET_URL, {}, {host = "keyauth1.com"}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal(headers["www-authenticate"], "Key realm=\""..constants.NAME.."\"") + assert.equal('Key realm="'..meta.name..'"', headers["www-authenticate"]) assert.equal("No API Key found in headers, body or querystring", body.message) end) @@ -55,7 +55,7 @@ describe("key-auth plugin", function() local response, status, headers = http_client.get(STUB_GET_URL, {apikey123 = "apikey123"}, {host = "keyauth1.com"}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal(headers["www-authenticate"], "Key realm=\""..constants.NAME.."\"") + assert.equal('Key realm="'..meta.name..'"', headers["www-authenticate"]) assert.equal("No API Key found in headers, body or querystring", body.message) end) @@ -63,7 +63,7 @@ describe("key-auth plugin", function() local response, status, headers = http_client.get(STUB_GET_URL, {apikey123 = "apikey123"}, {host = "keyauth1.com"}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal(headers["www-authenticate"], "Key realm=\""..constants.NAME.."\"") + assert.equal('Key realm="'..meta.name..'"', headers["www-authenticate"]) assert.equal("No API Key found in headers, body or querystring", body.message) end) @@ -71,7 +71,7 @@ describe("key-auth plugin", function() local response, status, headers = http_client.post(STUB_POST_URL, {apikey123 = "apikey123"}, {host = "keyauth1.com"}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal(headers["www-authenticate"], "Key realm=\""..constants.NAME.."\"") + assert.equal('Key realm="'..meta.name..'"', headers["www-authenticate"]) assert.equal("No API Key found in headers, body or querystring", body.message) end) @@ -86,7 +86,7 @@ describe("key-auth plugin", function() local response, status, headers = http_client.get(STUB_GET_URL, {}, {host = "keyauth1.com", apikey123 = "apikey123"}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal(headers["www-authenticate"], "Key realm=\""..constants.NAME.."\"") + assert.equal('Key realm="'..meta.name..'"', headers["www-authenticate"]) assert.equal("No API Key found in headers, body or querystring", body.message) end) @@ -94,7 +94,7 @@ describe("key-auth plugin", function() local response, status, headers = http_client.post(STUB_POST_URL, {}, {host = "keyauth1.com", apikey123 = "apikey123"}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal(headers["www-authenticate"], "Key realm=\""..constants.NAME.."\"") + assert.equal('Key realm="'..meta.name..'"', headers["www-authenticate"]) assert.equal("No API Key found in headers, body or querystring", body.message) end) diff --git a/spec/unit/statics_spec.lua b/spec/unit/statics_spec.lua index 4a3f5ae9151..92339ed9128 100644 --- a/spec/unit/statics_spec.lua +++ b/spec/unit/statics_spec.lua @@ -1,4 +1,4 @@ -local constants = require "kong.constants" +local meta = require "kong.meta" local stringy = require "stringy" local IO = require "kong.tools.io" local fs = require "luarocks.fs" @@ -21,10 +21,9 @@ describe("Static files", function() local file_content = IO.read_file(rockspec_path) local res = file_content:match("\"+[0-9.-]+[a-z]*[0-9-]*\"+") local extracted_version = res:sub(2, res:len() - 1) - assert.are.same(constants.ROCK_VERSION, extracted_version) local dash = string.find(extracted_version, "-") - assert.are.same(constants.VERSION, dash and extracted_version:sub(1, dash - 1) or extracted_version) + assert.equal(tostring(meta.version), dash and extracted_version:sub(1, dash - 1) or extracted_version) end) end) end) diff --git a/spec/unit/tools/responses_spec.lua b/spec/unit/tools/responses_spec.lua index 6a8af13a913..adbdb966058 100644 --- a/spec/unit/tools/responses_spec.lua +++ b/spec/unit/tools/responses_spec.lua @@ -1,5 +1,5 @@ +local meta = require "kong.meta" local responses = require "kong.tools.responses" -local constants = require "kong.constants" require "kong.tools.ngx_stub" @@ -21,10 +21,8 @@ describe("Responses", function() end) it("should have a list of the main http status codes used in Kong", function() - assert.truthy(responses.status_codes) - assert.are.same("table", type(responses.status_codes)) + assert.is_table(responses.status_codes) end) - it("should be callable via `send_HTTP_STATUS_CODE`", function() for status_code_name, status_code in pairs(responses.status_codes) do assert.has_no.errors(function() @@ -32,30 +30,25 @@ describe("Responses", function() end) end end) - it("should set the correct ngx values and call ngx.say and ngx.exit", function() responses.send_HTTP_OK("OK") - assert.are.same(ngx.status, responses.status_codes.HTTP_OK) - assert.are.same(ngx.header["Server"], constants.NAME.."/"..constants.VERSION) + assert.equal(ngx.status, responses.status_codes.HTTP_OK) + assert.equal(meta.name.."/"..tostring(meta.version), ngx.header["Server"]) assert.stub(ngx.say).was.called() -- set custom content assert.stub(ngx.exit).was.called() -- exit nginx (or continue to the next context if 200) end) - it("should send the content as a JSON string with a `message` property if given a string", function() responses.send_HTTP_OK("OK") assert.stub(ngx.say).was.called_with("{\"message\":\"OK\"}") end) - it("should send the content as a JSON string if given a table", function() responses.send_HTTP_OK({ success = true }) assert.stub(ngx.say).was.called_with("{\"success\":true}") end) - it("should send the content as passed if `raw` is given", function() responses.send_HTTP_OK("OK", true) assert.stub(ngx.say).was.called_with("OK") end) - it("should call `ngx.exit` with the corresponding status_code", function() for status_code_name, status_code in pairs(responses.status_codes) do assert.has_no.errors(function() @@ -64,7 +57,6 @@ describe("Responses", function() end) end end) - it("should call `ngx.log` if and only if a 500 status code range was given", function() responses.send_HTTP_BAD_REQUEST() assert.stub(ngx.log).was_not_called() @@ -77,30 +69,25 @@ describe("Responses", function() end) describe("default content rules for some status codes", function() - it("should apply default content rules for some status codes", function() responses.send_HTTP_NOT_FOUND() assert.stub(ngx.say).was.called_with("{\"message\":\"Not found\"}") responses.send_HTTP_NOT_FOUND("override") assert.stub(ngx.say).was.called_with("{\"message\":\"override\"}") end) - it("should apply default content rules for some status codes", function() responses.send_HTTP_NO_CONTENT("some content") assert.stub(ngx.say).was.not_called() end) - it("should apply default content rules for some status codes", function() responses.send_HTTP_INTERNAL_SERVER_ERROR() assert.stub(ngx.say).was.called_with("{\"message\":\"An unexpected error occurred\"}") responses.send_HTTP_INTERNAL_SERVER_ERROR("override") assert.stub(ngx.say).was.called_with("{\"message\":\"An unexpected error occurred\"}") end) - end) describe("#send()", function() - it("should send a custom status code", function() responses.send(415, "Unsupported media type") assert.stub(ngx.say).was.called_with("{\"message\":\"Unsupported media type\"}") @@ -113,6 +100,5 @@ describe("Responses", function() responses.send(501) assert.stub(ngx.exit).was.called_with(501) end) - end) end) diff --git a/spec/unit/tools/syslog_spec.lua b/spec/unit/tools/syslog_spec.lua index f98f5706f4d..0af0680e7b5 100644 --- a/spec/unit/tools/syslog_spec.lua +++ b/spec/unit/tools/syslog_spec.lua @@ -1,13 +1,13 @@ -local spec_helper = require "spec.spec_helpers" -local constants = require "kong.constants" -local stringy = require "stringy" -local syslog = require "kong.tools.syslog" +local meta = require "kong.meta" local utils = require "kong.tools.utils" +local syslog = require "kong.tools.syslog" +local stringy = require "stringy" +local constants = require "kong.constants" +local spec_helper = require "spec.spec_helpers" local UDP_PORT = 8889 describe("Syslog", function() - it("should log", function() local thread = spec_helper.start_udp_server(UDP_PORT) -- Starting the mock TCP server @@ -47,7 +47,7 @@ describe("Syslog", function() has_hostname = true elseif parts[1] == "hello" and parts[2] and parts[2] == "world" then has_hello = true - elseif parts[1] == "version" and parts[2] and parts[2] == constants.VERSION then + elseif parts[1] == "version" and parts[2] and parts[2] == tostring(meta.version) then has_version = true end end @@ -60,5 +60,4 @@ describe("Syslog", function() thread:join() -- wait til it exists end) - end) From b77dbdab0551632207d0685db98b5d89743ebbb0 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Wed, 23 Mar 2016 14:24:24 -0700 Subject: [PATCH 2/3] refactor(spec) better rockspec tests --- kong-0.7.0-0.rockspec | 32 +++++-------- kong/kong.lua | 4 +- kong/meta.lua | 5 ++- spec/unit/rockspec_spec.lua | 89 +++++++++++++++++-------------------- spec/unit/statics_spec.lua | 29 ------------ 5 files changed, 59 insertions(+), 100 deletions(-) delete mode 100644 spec/unit/statics_spec.lua diff --git a/kong-0.7.0-0.rockspec b/kong-0.7.0-0.rockspec index ed6ccd3c3fe..4a8731b4a7d 100644 --- a/kong-0.7.0-0.rockspec +++ b/kong-0.7.0-0.rockspec @@ -13,6 +13,7 @@ description = { dependencies = { "luasec ~> 0.5-2", + "penlight ~> 1.3.2", "lua_uuid ~> 0.2.0-2", "lua_system_constants ~> 0.1.1-0", "luatz ~> 0.3-1", @@ -44,6 +45,7 @@ build = { ["lapp"] = "kong/vendor/lapp.lua", ["resty_http"] = "kong/vendor/resty_http.lua", + ["kong.meta"] = "kong/meta.lua", ["kong.constants"] = "kong/constants.lua", ["kong.singletons"] = "kong/singletons.lua", @@ -66,6 +68,16 @@ build = { ["kong.cli.services.serf"] = "kong/cli/services/serf.lua", ["kong.cli.services.nginx"] = "kong/cli/services/nginx.lua", + ["kong.api.app"] = "kong/api/app.lua", + ["kong.api.crud_helpers"] = "kong/api/crud_helpers.lua", + ["kong.api.route_helpers"] = "kong/api/route_helpers.lua", + ["kong.api.routes.kong"] = "kong/api/routes/kong.lua", + ["kong.api.routes.apis"] = "kong/api/routes/apis.lua", + ["kong.api.routes.consumers"] = "kong/api/routes/consumers.lua", + ["kong.api.routes.plugins"] = "kong/api/routes/plugins.lua", + ["kong.api.routes.cache"] = "kong/api/routes/cache.lua", + ["kong.api.routes.cluster"] = "kong/api/routes/cluster.lua", + ["kong.tools.io"] = "kong/tools/io.lua", ["kong.tools.utils"] = "kong/tools/utils.lua", ["kong.tools.faker"] = "kong/tools/faker.lua", @@ -106,15 +118,6 @@ build = { ["kong.dao.migrations.cassandra"] = "kong/dao/migrations/cassandra.lua", ["kong.dao.migrations.postgres"] = "kong/dao/migrations/postgres.lua", - ["kong.api.app"] = "kong/api/app.lua", - ["kong.api.crud_helpers"] = "kong/api/crud_helpers.lua", - ["kong.api.route_helpers"] = "kong/api/route_helpers.lua", - ["kong.api.routes.kong"] = "kong/api/routes/kong.lua", - ["kong.api.routes.apis"] = "kong/api/routes/apis.lua", - ["kong.api.routes.consumers"] = "kong/api/routes/consumers.lua", - ["kong.api.routes.plugins"] = "kong/api/routes/plugins.lua", - ["kong.api.routes.plugins"] = "kong/api/routes/plugins.lua", - ["kong.plugins.base_plugin"] = "kong/plugins/base_plugin.lua", ["kong.plugins.basic-auth.migrations.cassandra"] = "kong/plugins/basic-auth/migrations/cassandra.lua", @@ -218,16 +221,6 @@ build = { ["kong.plugins.acl.api"] = "kong/plugins/acl/api.lua", ["kong.plugins.acl.daos"] = "kong/plugins/acl/daos.lua", - ["kong.api.app"] = "kong/api/app.lua", - ["kong.api.crud_helpers"] = "kong/api/crud_helpers.lua", - ["kong.api.route_helpers"] = "kong/api/route_helpers.lua", - ["kong.api.routes.kong"] = "kong/api/routes/kong.lua", - ["kong.api.routes.apis"] = "kong/api/routes/apis.lua", - ["kong.api.routes.consumers"] = "kong/api/routes/consumers.lua", - ["kong.api.routes.plugins"] = "kong/api/routes/plugins.lua", - ["kong.api.routes.cache"] = "kong/api/routes/cache.lua", - ["kong.api.routes.cluster"] = "kong/api/routes/cluster.lua", - ["kong.plugins.jwt.migrations.cassandra"] = "kong/plugins/jwt/migrations/cassandra.lua", ["kong.plugins.jwt.migrations.postgres"] = "kong/plugins/jwt/migrations/postgres.lua", ["kong.plugins.jwt.handler"] = "kong/plugins/jwt/handler.lua", @@ -255,7 +248,6 @@ build = { ["kong.plugins.datadog.handler"] = "kong/plugins/datadog/handler.lua", ["kong.plugins.datadog.schema"] = "kong/plugins/datadog/schema.lua", ["kong.plugins.datadog.statsd_logger"] = "kong/plugins/datadog/statsd_logger.lua" - }, install = { conf = { "kong.yml" }, diff --git a/kong/kong.lua b/kong/kong.lua index 1fbf29634a3..ef612fb701d 100644 --- a/kong/kong.lua +++ b/kong/kong.lua @@ -27,8 +27,8 @@ local meta = require "kong.meta" _G._KONG = { - _NAME = meta.name, - _VERSION = tostring(meta.version) + _NAME = meta._NAME, + _VERSION = meta._VERSION } local core = require "kong.core.handler" diff --git a/kong/meta.lua b/kong/meta.lua index fb6eee1d6e7..5427ff0e5e2 100644 --- a/kong/meta.lua +++ b/kong/meta.lua @@ -11,6 +11,7 @@ local version = setmetatable({ }) return { - name = "Kong", - version = version + _NAME = "kong", + _VERSION = tostring(version), + __VERSION = version } diff --git a/spec/unit/rockspec_spec.lua b/spec/unit/rockspec_spec.lua index 5aa42d156b1..ee3f97d5d02 100644 --- a/spec/unit/rockspec_spec.lua +++ b/spec/unit/rockspec_spec.lua @@ -1,59 +1,54 @@ -local stringy = require "stringy" -local IO = require "kong.tools.io" -local fs = require "luarocks.fs" +local pl_dir = require "pl.dir" +local meta = require "kong.meta" -describe("Rockspec", function() - local rockspec_path, files +describe("rockspec", function() + local rock, lua_srcs = {} + local rock_filename setup(function() - for _, filename in ipairs(fs.list_dir(".")) do - if stringy.endswith(filename, "rockspec") then - rockspec_path = filename - break - end - end - if not rockspec_path then - error("can't find rockspec") - end - - loadfile(rockspec_path)() - - local res = IO.os_execute("find . -type f -name *.lua", true) - if not res or stringy.strip(res) == "" then - error("Error executing the command") - end + lua_srcs = pl_dir.getallfiles("./kong", "*.lua") + assert.True(#lua_srcs > 0) + local res = pl_dir.getfiles(".", "kong-*.rockspec") + assert.equal(1, #res) + rock_filename = res[1] + local f = assert(loadfile(res[1])) + setfenv(f, rock) + f() + end) - files = stringy.split(res, "\n") + it("has same version as meta", function() + assert.matches(meta._VERSION, rock.version:match("(%d.%d.%d)")) + end) + it("has same name as meta", function() + assert.equal(meta._NAME, rock.package) + end) + it("has correct version in filename", function() + local pattern = meta._VERSION:gsub("%.", "%%."):gsub("-", "%%-") + assert.matches(pattern, rock_filename) end) describe("modules", function() - for _, v in ipairs(files) do - it("should include "..v, function() - local path = stringy.strip(v) - if path ~= "" and stringy.startswith(path, "./kong") then - path = string.sub(path, 3) - - local found = false - for mod_name, mod_path in pairs(build.modules) do - if mod_path == path then - found = true - break - end + it("are all included", function() + for _, src in ipairs(lua_srcs) do + src = src:sub(3) -- strip './' + local found + for mod_name, mod_path in pairs(rock.build.modules) do + if mod_path == src then + found = true + break end - - assert.True(found) end - end) - end - - for mod_name, mod_path in pairs(build.modules) do - if mod_name ~= "kong" and mod_name ~= "resty_http" and - mod_name ~= "classic" and mod_name ~= "lapp" then - it(mod_path.." has correct name", function() - mod_path = mod_path:gsub("%.lua", ""):gsub("/", '.') - assert.equal(mod_name, mod_path) - end) + assert(found, "could not find module entry for Lua file: "..src) + end + end) + it("all modules named as their path", function() + for mod_name, mod_path in pairs(rock.build.modules) do + if mod_name ~= "kong" and mod_name ~= "resty_http" and + mod_name ~= "classic" and mod_name ~= "lapp" then + mod_path = mod_path:gsub("%.lua", ""):gsub("/", '.') + assert(mod_name == mod_path, mod_path.." has different name ("..mod_name..")") + end end - end + end) end) end) diff --git a/spec/unit/statics_spec.lua b/spec/unit/statics_spec.lua deleted file mode 100644 index 92339ed9128..00000000000 --- a/spec/unit/statics_spec.lua +++ /dev/null @@ -1,29 +0,0 @@ -local meta = require "kong.meta" -local stringy = require "stringy" -local IO = require "kong.tools.io" -local fs = require "luarocks.fs" - -describe("Static files", function() - describe("Constants", function() - it("version set in constants should match the one in the rockspec", function() - local rockspec_path - for _, filename in ipairs(fs.list_dir(".")) do - if stringy.endswith(filename, "rockspec") then - rockspec_path = filename - break - end - end - - if not rockspec_path then - error("Can't find the rockspec file") - end - - local file_content = IO.read_file(rockspec_path) - local res = file_content:match("\"+[0-9.-]+[a-z]*[0-9-]*\"+") - local extracted_version = res:sub(2, res:len() - 1) - - local dash = string.find(extracted_version, "-") - assert.equal(tostring(meta.version), dash and extracted_version:sub(1, dash - 1) or extracted_version) - end) - end) -end) From c4f4d77c9c0e3115a56c5fdb7364afd98a92c0b9 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Thu, 24 Mar 2016 13:14:28 -0700 Subject: [PATCH 3/3] refactor: introduce meta.lua, penglight dep - start removing constants the unified, global file - introduce meta.lua for nicer package infos (version/name) - start ordering test suites --- bin/kong | 2 +- kong-0.7.0-0.rockspec | 2 +- kong/api/api_helpers.lua | 63 ++++++++++ kong/api/app.lua | 77 ++---------- kong/api/route_helpers.lua | 29 ----- kong/api/routes/kong.lua | 49 +++++--- kong/cli/cmds/start.lua | 2 +- kong/cli/cmds/version.lua | 2 +- kong/constants.lua | 4 +- kong/plugins/rate-limiting/handler.lua | 12 +- .../response-ratelimiting/header_filter.lua | 12 +- kong/tools/config_loader.lua | 8 +- kong/tools/responses.lua | 4 +- kong/tools/syslog.lua | 3 +- .../{dao => 01-dao}/00-unit_error_spec.lua | 0 .../{dao => 01-dao}/01-factory_spec.lua | 0 .../{dao => 01-dao}/02-migrations_spec.lua | 0 .../{dao => 01-dao}/03-crud_spec.lua | 0 .../{dao => 01-dao}/04-constraints_spec.lua | 0 .../{dao => 01-dao}/05-use_cases_spec.lua | 0 .../{dao => 01-dao}/06-plugins_daos_spec.lua | 0 .../{dao => 01-dao}/07-options_spec.lua | 0 ...lient_spec.lua => 01-http_client_spec.lua} | 0 .../{cli => 02-cli}/cmds/quit_spec.lua | 0 .../{cli => 02-cli}/cmds/reload_spec.lua | 0 .../{cli => 02-cli}/cmds/restart_spec.lua | 0 .../{cli => 02-cli}/cmds/start_spec.lua | 0 .../{cli => 02-cli}/cmds/status_spec.lua | 0 .../{cli => 02-cli}/cmds/version_spec.lua | 2 +- .../{cli => 02-cli}/services/dnsmasq_spec.lua | 0 .../{cli => 02-cli}/services/nginx_spec.lua | 0 .../{cli => 02-cli}/services/serf_spec.lua | 0 .../02-syslog_spec.lua} | 2 +- .../{core => 03-core}/hooks_spec.lua | 0 .../apis_routes_spec.lua | 0 .../cache_routes_spec.lua | 0 .../cluster_routes_spec.lua | 0 .../consumers_routes_spec.lua | 0 .../kong_routes_spec.lua | 28 +++-- .../plugins_routes_spec.lua | 0 .../{proxy => 05-proxy}/dns_resolver_spec.lua | 0 .../plugins_triggering_spec.lua | 0 .../{proxy => 05-proxy}/realip_spec.lua | 0 .../{proxy => 05-proxy}/resolver_spec.lua | 4 +- .../{cluster => 06-cluster}/cluster_spec.lua | 0 .../admin_api/route_helpers_spec.lua | 22 ---- spec/integration/cli/utils/luarocks_spec.lua | 21 ---- spec/plugins/basic-auth/access_spec.lua | 4 +- spec/plugins/key-auth/access_spec.lua | 12 +- ...rockspec_spec.lua => 01-rockspec_spec.lua} | 0 .../utils_spec.lua => 02-utils_spec.lua} | 0 ...mestamp_spec.lua => 03-timestamp_spec.lua} | 0 .../{tools/io_spec.lua => 04-io_spec.lua} | 0 .../faker_spec.lua => 05-faker_spec.lua} | 0 ...spec.lua => 10-schema_validation_spec.lua} | 0 ..._spec.lua => 11-entities_schemas_spec.lua} | 0 spec/unit/12-api_helpers_spec.lua | 80 ++++++++++++ ...sponses_spec.lua => 13-responses_spec.lua} | 2 +- ...der_spec.lua => 14-config_loader_spec.lua} | 0 ...he_spec.lua => 15-database_cache_spec.lua} | 0 ...resolver_spec.lua => 16-resolver_spec.lua} | 0 spec/unit/api/app_spec.lua | 115 ------------------ 62 files changed, 244 insertions(+), 317 deletions(-) create mode 100644 kong/api/api_helpers.lua delete mode 100644 kong/api/route_helpers.lua rename spec/integration/{dao => 01-dao}/00-unit_error_spec.lua (100%) rename spec/integration/{dao => 01-dao}/01-factory_spec.lua (100%) rename spec/integration/{dao => 01-dao}/02-migrations_spec.lua (100%) rename spec/integration/{dao => 01-dao}/03-crud_spec.lua (100%) rename spec/integration/{dao => 01-dao}/04-constraints_spec.lua (100%) rename spec/integration/{dao => 01-dao}/05-use_cases_spec.lua (100%) rename spec/integration/{dao => 01-dao}/06-plugins_daos_spec.lua (100%) rename spec/integration/{dao => 01-dao}/07-options_spec.lua (100%) rename spec/integration/{tools/http_client_spec.lua => 01-http_client_spec.lua} (100%) rename spec/integration/{cli => 02-cli}/cmds/quit_spec.lua (100%) rename spec/integration/{cli => 02-cli}/cmds/reload_spec.lua (100%) rename spec/integration/{cli => 02-cli}/cmds/restart_spec.lua (100%) rename spec/integration/{cli => 02-cli}/cmds/start_spec.lua (100%) rename spec/integration/{cli => 02-cli}/cmds/status_spec.lua (100%) rename spec/integration/{cli => 02-cli}/cmds/version_spec.lua (77%) rename spec/integration/{cli => 02-cli}/services/dnsmasq_spec.lua (100%) rename spec/integration/{cli => 02-cli}/services/nginx_spec.lua (100%) rename spec/integration/{cli => 02-cli}/services/serf_spec.lua (100%) rename spec/{unit/tools/syslog_spec.lua => integration/02-syslog_spec.lua} (98%) rename spec/integration/{core => 03-core}/hooks_spec.lua (100%) rename spec/integration/{admin_api => 04-admin_api}/apis_routes_spec.lua (100%) rename spec/integration/{admin_api => 04-admin_api}/cache_routes_spec.lua (100%) rename spec/integration/{admin_api => 04-admin_api}/cluster_routes_spec.lua (100%) rename spec/integration/{admin_api => 04-admin_api}/consumers_routes_spec.lua (100%) rename spec/integration/{admin_api => 04-admin_api}/kong_routes_spec.lua (87%) rename spec/integration/{admin_api => 04-admin_api}/plugins_routes_spec.lua (100%) rename spec/integration/{proxy => 05-proxy}/dns_resolver_spec.lua (100%) rename spec/integration/{proxy => 05-proxy}/plugins_triggering_spec.lua (100%) rename spec/integration/{proxy => 05-proxy}/realip_spec.lua (100%) rename spec/integration/{proxy => 05-proxy}/resolver_spec.lua (98%) rename spec/integration/{cluster => 06-cluster}/cluster_spec.lua (100%) delete mode 100644 spec/integration/admin_api/route_helpers_spec.lua delete mode 100644 spec/integration/cli/utils/luarocks_spec.lua rename spec/unit/{rockspec_spec.lua => 01-rockspec_spec.lua} (100%) rename spec/unit/{tools/utils_spec.lua => 02-utils_spec.lua} (100%) rename spec/unit/{tools/timestamp_spec.lua => 03-timestamp_spec.lua} (100%) rename spec/unit/{tools/io_spec.lua => 04-io_spec.lua} (100%) rename spec/unit/{tools/faker_spec.lua => 05-faker_spec.lua} (100%) rename spec/unit/{schemas_spec.lua => 10-schema_validation_spec.lua} (100%) rename spec/unit/{dao/entities_schemas_spec.lua => 11-entities_schemas_spec.lua} (100%) create mode 100644 spec/unit/12-api_helpers_spec.lua rename spec/unit/{tools/responses_spec.lua => 13-responses_spec.lua} (98%) rename spec/unit/{tools/config_loader_spec.lua => 14-config_loader_spec.lua} (100%) rename spec/unit/{tools/database_cache_spec.lua => 15-database_cache_spec.lua} (100%) rename spec/unit/{core/resolver_spec.lua => 16-resolver_spec.lua} (100%) delete mode 100644 spec/unit/api/app_spec.lua diff --git a/bin/kong b/bin/kong index 0b4e0fce8af..55e12b175a5 100755 --- a/bin/kong +++ b/bin/kong @@ -35,7 +35,7 @@ Usage: kong kong --help print this message kong --help print the help message of a command -%s@%s]], meta.name, tostring(meta.version)) +%s@%s]], meta._NAME, meta._VERSION) -- Determine validity of the given command local cmd = arg[1] diff --git a/kong-0.7.0-0.rockspec b/kong-0.7.0-0.rockspec index 4a8731b4a7d..1db94123fe0 100644 --- a/kong-0.7.0-0.rockspec +++ b/kong-0.7.0-0.rockspec @@ -69,8 +69,8 @@ build = { ["kong.cli.services.nginx"] = "kong/cli/services/nginx.lua", ["kong.api.app"] = "kong/api/app.lua", + ["kong.api.api_helpers"] = "kong/api/api_helpers.lua", ["kong.api.crud_helpers"] = "kong/api/crud_helpers.lua", - ["kong.api.route_helpers"] = "kong/api/route_helpers.lua", ["kong.api.routes.kong"] = "kong/api/routes/kong.lua", ["kong.api.routes.apis"] = "kong/api/routes/apis.lua", ["kong.api.routes.consumers"] = "kong/api/routes/consumers.lua", diff --git a/kong/api/api_helpers.lua b/kong/api/api_helpers.lua new file mode 100644 index 00000000000..b93273b82ee --- /dev/null +++ b/kong/api/api_helpers.lua @@ -0,0 +1,63 @@ +local pl_string = require "pl.stringx" +local utils = require "kong.tools.utils" + +local type = type +local pairs = pairs +local remove = table.remove + +local _M = {} + +-- Parses a form value, handling multipart/data values +-- @param `v` The value object +-- @return The parsed value +local function parse_value(v) + return type(v) == "table" and v.content or v -- Handle multipart +end + +-- Put nested keys in objects: +-- Normalize dotted keys in objects. +-- Example: {["key.value.sub"]=1234} becomes {key = {value = {sub=1234}} +-- @param `obj` Object to normalize +-- @return `normalized_object` +function _M.normalize_nested_params(obj) + local new_obj = {} + + local function attach_dotted_key(keys, attach_to, value) + local current_key = keys[1] + + if #keys > 1 then + if not attach_to[current_key] then + attach_to[current_key] = {} + end + remove(keys, 1) + attach_dotted_key(keys, attach_to[current_key], value) + else + attach_to[current_key] = value + end + end + + for k, v in pairs(obj) do + if type(v) == "table" then + -- normalize arrays since Lapis parses ?key[1]=foo as {["1"]="foo"} instead of {"foo"} + if utils.is_array(v) then + local arr = {} + for _, arr_v in pairs(v) do arr[#arr+1] = arr_v end + v = arr + else + v = _M.normalize_nested_params(v) -- recursive call on other table values + end + end + + -- normalize sub-keys with dot notation + local keys = pl_string.split(k, ".") + if #keys > 1 then -- we have a key containing a dot + attach_dotted_key(keys, new_obj, parse_value(v)) + else + new_obj[k] = parse_value(v) -- nothing special with that key, simply attaching the value + end + end + + return new_obj +end + +return _M diff --git a/kong/api/app.lua b/kong/api/app.lua index dc9713869c5..f6d54497147 100644 --- a/kong/api/app.lua +++ b/kong/api/app.lua @@ -1,62 +1,26 @@ -local singletons = require "kong.singletons" local lapis = require "lapis" local utils = require "kong.tools.utils" local stringy = require "stringy" local responses = require "kong.tools.responses" +local singletons = require "kong.singletons" local app_helpers = require "lapis.application" -local app = lapis.Application() - --- Parses a form value, handling multipart/data values --- @param `v` The value object --- @return The parsed value -local function parse_value(v) - return type(v) == "table" and v.content or v -- Handle multipart -end +local api_helpers = require "kong.api.api_helpers" --- Put nested keys in objects: --- Normalize dotted keys in objects. --- Example: {["key.value.sub"]=1234} becomes {key = {value = {sub=1234}} --- @param `obj` Object to normalize --- @return `normalized_object` -local function normalize_nested_params(obj) - local new_obj = {} +local find = string.find - local function attach_dotted_key(keys, attach_to, value) - local current_key = keys[1] - - if #keys > 1 then - if not attach_to[current_key] then - attach_to[current_key] = {} - end - table.remove(keys, 1) - attach_dotted_key(keys, attach_to[current_key], value) - else - attach_to[current_key] = value - end - end +local app = lapis.Application() - for k, v in pairs(obj) do - if type(v) == "table" then - -- normalize arrays since Lapis parses ?key[1]=foo as {["1"]="foo"} instead of {"foo"} - if utils.is_array(v) then - local arr = {} - for _, arr_v in pairs(v) do table.insert(arr, arr_v) end - v = arr - else - v = normalize_nested_params(v) -- recursive call on other table values +local function parse_params(fn) + return app_helpers.json_params(function(self, ...) + local content_type = self.req.headers["content-type"] + if content_type and find(content_type:lower(), "application/json", nil, true) then + if not self.json then + return responses.send_HTTP_BAD_REQUEST("Cannot parse JSON body") end end - - -- normalize sub-keys with dot notation - local keys = stringy.split(k, ".") - if #keys > 1 then -- we have a key containing a dot - attach_dotted_key(keys, new_obj, parse_value(v)) - else - new_obj[k] = parse_value(v) -- nothing special with that key, simply attaching the value - end - end - - return new_obj + self.params = api_helpers.normalize_nested_params(self.params) + return fn(self, ...) + end) end local function on_error(self) @@ -74,21 +38,6 @@ local function on_error(self) end end -local function parse_params(fn) - return app_helpers.json_params(function(self, ...) - local content_type = self.req.headers["content-type"] - if content_type and string.find(content_type:lower(), "application/json", nil, true) then - if not self.json then - return responses.send_HTTP_BAD_REQUEST("Cannot parse JSON body") - end - end - self.params = normalize_nested_params(self.params) - return fn(self, ...) - end) -end - -app.parse_params = parse_params - app.default_route = function(self) local path = self.req.parsed_url.path:match("^(.*)/$") diff --git a/kong/api/route_helpers.lua b/kong/api/route_helpers.lua deleted file mode 100644 index 420e17651bd..00000000000 --- a/kong/api/route_helpers.lua +++ /dev/null @@ -1,29 +0,0 @@ -local stringy = require "stringy" - -local _M = {} - -function _M.parse_status(value) - local result = {} - local parts = stringy.split(value, "\n") - for i, v in ipairs(parts) do - local part = stringy.strip(v) - if i == 1 then - result["connections_active"] = tonumber(string.sub(part, string.find(part, "%d+"))) - elseif i == 3 then - local counter = 1 - local stat_names = { "connections_accepted", "connections_handled", "total_requests"} - for stat in string.gmatch(part, "%S+") do - result[stat_names[counter]] = tonumber(stat) - counter = counter + 1 - end - elseif i == 4 then - local reading, writing, waiting = string.match(part, "%a+:%s*(%d+)%s*%a+:%s*(%d+)%s*%a+:%s*(%d+)") - result["connections_reading"] = tonumber(reading) - result["connections_writing"] = tonumber(writing) - result["connections_waiting"] = tonumber(waiting) - end - end - return result -end - -return _M \ No newline at end of file diff --git a/kong/api/routes/kong.lua b/kong/api/routes/kong.lua index 79cb7585b58..3b4f0878e39 100644 --- a/kong/api/routes/kong.lua +++ b/kong/api/routes/kong.lua @@ -1,6 +1,11 @@ local utils = require "kong.tools.utils" local singletons = require "kong.singletons" -local route_helpers = require "kong.api.route_helpers" + +local find = string.find +local pairs = pairs +local ipairs = ipairs +local select = select +local tonumber = tonumber local tagline = "Welcome to ".._KONG._NAME local version = _KONG._VERSION @@ -43,26 +48,36 @@ return { }, ["/status"] = { GET = function(self, dao, helpers) - local res = ngx.location.capture("/nginx_status") - if res.status == 200 then + local r = ngx.location.capture "/nginx_status" + if r.status ~= 200 then + return helpers.responses.send_HTTP_INTERNAL_SERVER_ERROR(r.body) + end - local status_response = { - server = route_helpers.parse_status(res.body), - database = {} - } + local var = ngx.var + local accepted, handled, total = select(3, find(r.body, "accepts handled requests\n (%d*) (%d*) (%d*)")) - for k, v in pairs(dao.daos) do - local count, err = v:count() - if err then - return helpers.responses.send_HTTP_INTERNAL_SERVER_ERROR(err) - end - status_response.database[k] = count - end + local status_response = { + server = { + connections_active = tonumber(var.connections_active), + connections_reading = tonumber(var.connections_reading), + connections_writing = tonumber(var.connections_writing), + connections_waiting = tonumber(var.connections_waiting), + connections_accepted = tonumber(accepted), + connections_handled = tonumber(handled), + total_requests = tonumber(total) + }, + database = {} + } - return helpers.responses.send_HTTP_OK(status_response) - else - return helpers.responses.send_HTTP_INTERNAL_SERVER_ERROR(res.body) + for k, v in pairs(dao.daos) do + local count, err = v:count() + if err then + return helpers.responses.send_HTTP_INTERNAL_SERVER_ERROR(err) + end + status_response.database[k] = count end + + return helpers.responses.send_HTTP_OK(status_response) end } } diff --git a/kong/cli/cmds/start.lua b/kong/cli/cmds/start.lua index d9620b3e479..9f10867ff2d 100755 --- a/kong/cli/cmds/start.lua +++ b/kong/cli/cmds/start.lua @@ -15,7 +15,7 @@ Options: -c,--config (default %s) path to configuration file ]], constants.CLI.GLOBAL_KONG_CONF)) -logger:info(meta.name.." "..tostring(meta.version)) +logger:info(meta._NAME.." "..meta._VERSION) local configuration, configuration_path = config_loader.load_default(args.config) diff --git a/kong/cli/cmds/version.lua b/kong/cli/cmds/version.lua index 60fe6c18d70..3744cb8c139 100644 --- a/kong/cli/cmds/version.lua +++ b/kong/cli/cmds/version.lua @@ -3,4 +3,4 @@ local logger = require "kong.cli.utils.logger" local meta = require "kong.meta" -logger:print(string.format("%s version: %s", meta.name, tostring(meta.version))) +logger:print(string.format("%s version: %s", meta._NAME, meta._VERSION)) diff --git a/kong/constants.lua b/kong/constants.lua index dab5a3f0fba..d46b938995f 100644 --- a/kong/constants.lua +++ b/kong/constants.lua @@ -23,9 +23,7 @@ return { CONSUMER_ID = "X-Consumer-ID", CONSUMER_CUSTOM_ID = "X-Consumer-Custom-ID", CONSUMER_USERNAME = "X-Consumer-Username", - CREDENTIAL_USERNAME = "X-Credential-Username", - RATELIMIT_LIMIT = "X-RateLimit-Limit", - RATELIMIT_REMAINING = "X-RateLimit-Remaining" + CREDENTIAL_USERNAME = "X-Credential-Username" }, RATELIMIT = { PERIODS = { diff --git a/kong/plugins/rate-limiting/handler.lua b/kong/plugins/rate-limiting/handler.lua index c39c2a0165c..f51df564e6d 100644 --- a/kong/plugins/rate-limiting/handler.lua +++ b/kong/plugins/rate-limiting/handler.lua @@ -1,10 +1,12 @@ -- Copyright (C) Mashape, Inc. -local singletons = require "kong.singletons" -local BasePlugin = require "kong.plugins.base_plugin" -local constants = require "kong.constants" local timestamp = require "kong.tools.timestamp" local responses = require "kong.tools.responses" +local singletons = require "kong.singletons" +local BasePlugin = require "kong.plugins.base_plugin" + +local RATELIMIT_LIMIT = "X-RateLimit-Limit" +local RATELIMIT_REMAINING = "X-RateLimit-Remaining" local RateLimitingHandler = BasePlugin:extend() @@ -97,8 +99,8 @@ function RateLimitingHandler:access(conf) if usage then -- Adding headers for k, v in pairs(usage) do - ngx.header[constants.HEADERS.RATELIMIT_LIMIT.."-"..k] = v.limit - ngx.header[constants.HEADERS.RATELIMIT_REMAINING.."-"..k] = math.max(0, (stop == nil or stop == k) and v.remaining - 1 or v.remaining) -- -increment_value for this current request + ngx.header[RATELIMIT_LIMIT.."-"..k] = v.limit + ngx.header[RATELIMIT_REMAINING.."-"..k] = math.max(0, (stop == nil or stop == k) and v.remaining - 1 or v.remaining) -- -increment_value for this current request end -- If limit is exceeded, terminate the request diff --git a/kong/plugins/response-ratelimiting/header_filter.lua b/kong/plugins/response-ratelimiting/header_filter.lua index 87c21139a60..83b4251d5cc 100644 --- a/kong/plugins/response-ratelimiting/header_filter.lua +++ b/kong/plugins/response-ratelimiting/header_filter.lua @@ -1,8 +1,10 @@ -local stringy = require "stringy" local utils = require "kong.tools.utils" -local constants = require "kong.constants" +local stringy = require "stringy" local responses = require "kong.tools.responses" +local RATELIMIT_LIMIT = "X-RateLimit-Limit" +local RATELIMIT_REMAINING = "X-RateLimit-Remaining" + local _M = {} local function parse_header(header_value, limits) @@ -33,12 +35,12 @@ function _M.execute(conf) local usage = ngx.ctx.usage -- Load current usage if not usage then return end - + local stop for limit_name, v in pairs(usage) do for period_name, lv in pairs(usage[limit_name]) do - ngx.header[constants.HEADERS.RATELIMIT_LIMIT.."-"..limit_name.."-"..period_name] = lv.limit - ngx.header[constants.HEADERS.RATELIMIT_REMAINING.."-"..limit_name.."-"..period_name] = math.max(0, lv.remaining - (increments[limit_name] and increments[limit_name] or 0)) -- increment_value for this current request + ngx.header[RATELIMIT_LIMIT.."-"..limit_name.."-"..period_name] = lv.limit + ngx.header[RATELIMIT_REMAINING.."-"..limit_name.."-"..period_name] = math.max(0, lv.remaining - (increments[limit_name] and increments[limit_name] or 0)) -- increment_value for this current request if increments[limit_name] and increments[limit_name] > 0 and lv.remaining <= 0 then stop = true -- No more diff --git a/kong/tools/config_loader.lua b/kong/tools/config_loader.lua index 3b75ecab16a..aebccb780a9 100644 --- a/kong/tools/config_loader.lua +++ b/kong/tools/config_loader.lua @@ -2,7 +2,6 @@ local yaml = require "yaml" local IO = require "kong.tools.io" local utils = require "kong.tools.utils" local logger = require "kong.cli.utils.logger" -local luarocks = require "kong.cli.utils.luarocks" local stringy = require "stringy" local constants = require "kong.constants" local config_defaults = require "kong.tools.config_defaults" @@ -28,7 +27,7 @@ local function is_valid_IPv4(ip) if b < 0 or 255 < b then return false end if c < 0 or 255 < c then return false end if d < 0 or 255 < d then return false end - + return true end @@ -202,11 +201,6 @@ function _M.load(config_path) end function _M.load_default(config_path) - if not IO.file_exists(config_path) then - logger:warn("No configuration at: "..config_path.." using default config instead.") - config_path = IO.path:join(luarocks.get_config_dir(), "kong.yml") - end - logger:info("Using configuration: "..config_path) return _M.load(config_path) diff --git a/kong/tools/responses.lua b/kong/tools/responses.lua index ac027d2771b..f6847867f9d 100644 --- a/kong/tools/responses.lua +++ b/kong/tools/responses.lua @@ -15,8 +15,10 @@ -- -- Raw send() helper: -- return responses.send(418, "This is a teapot") local cjson = require "cjson" +local meta = require "kong.meta" -local server_header = _KONG._NAME.."/".._KONG._VERSION +--local server_header = _KONG._NAME.."/".._KONG._VERSION +local server_header = meta._NAME.."/"..meta._VERSION --- Define the most common HTTP status codes for sugar methods. -- Each of those status will generate a helper method (sugar) diff --git a/kong/tools/syslog.lua b/kong/tools/syslog.lua index 8ee470da183..7fc536fa6bd 100644 --- a/kong/tools/syslog.lua +++ b/kong/tools/syslog.lua @@ -1,9 +1,10 @@ local IO = require "kong.tools.io" +local meta = require "kong.meta" local cjson = require "cjson" local stringy = require "stringy" local constants = require "kong.constants" -local version = _KONG._VERSION +local version = meta._VERSION local _M = {} diff --git a/spec/integration/dao/00-unit_error_spec.lua b/spec/integration/01-dao/00-unit_error_spec.lua similarity index 100% rename from spec/integration/dao/00-unit_error_spec.lua rename to spec/integration/01-dao/00-unit_error_spec.lua diff --git a/spec/integration/dao/01-factory_spec.lua b/spec/integration/01-dao/01-factory_spec.lua similarity index 100% rename from spec/integration/dao/01-factory_spec.lua rename to spec/integration/01-dao/01-factory_spec.lua diff --git a/spec/integration/dao/02-migrations_spec.lua b/spec/integration/01-dao/02-migrations_spec.lua similarity index 100% rename from spec/integration/dao/02-migrations_spec.lua rename to spec/integration/01-dao/02-migrations_spec.lua diff --git a/spec/integration/dao/03-crud_spec.lua b/spec/integration/01-dao/03-crud_spec.lua similarity index 100% rename from spec/integration/dao/03-crud_spec.lua rename to spec/integration/01-dao/03-crud_spec.lua diff --git a/spec/integration/dao/04-constraints_spec.lua b/spec/integration/01-dao/04-constraints_spec.lua similarity index 100% rename from spec/integration/dao/04-constraints_spec.lua rename to spec/integration/01-dao/04-constraints_spec.lua diff --git a/spec/integration/dao/05-use_cases_spec.lua b/spec/integration/01-dao/05-use_cases_spec.lua similarity index 100% rename from spec/integration/dao/05-use_cases_spec.lua rename to spec/integration/01-dao/05-use_cases_spec.lua diff --git a/spec/integration/dao/06-plugins_daos_spec.lua b/spec/integration/01-dao/06-plugins_daos_spec.lua similarity index 100% rename from spec/integration/dao/06-plugins_daos_spec.lua rename to spec/integration/01-dao/06-plugins_daos_spec.lua diff --git a/spec/integration/dao/07-options_spec.lua b/spec/integration/01-dao/07-options_spec.lua similarity index 100% rename from spec/integration/dao/07-options_spec.lua rename to spec/integration/01-dao/07-options_spec.lua diff --git a/spec/integration/tools/http_client_spec.lua b/spec/integration/01-http_client_spec.lua similarity index 100% rename from spec/integration/tools/http_client_spec.lua rename to spec/integration/01-http_client_spec.lua diff --git a/spec/integration/cli/cmds/quit_spec.lua b/spec/integration/02-cli/cmds/quit_spec.lua similarity index 100% rename from spec/integration/cli/cmds/quit_spec.lua rename to spec/integration/02-cli/cmds/quit_spec.lua diff --git a/spec/integration/cli/cmds/reload_spec.lua b/spec/integration/02-cli/cmds/reload_spec.lua similarity index 100% rename from spec/integration/cli/cmds/reload_spec.lua rename to spec/integration/02-cli/cmds/reload_spec.lua diff --git a/spec/integration/cli/cmds/restart_spec.lua b/spec/integration/02-cli/cmds/restart_spec.lua similarity index 100% rename from spec/integration/cli/cmds/restart_spec.lua rename to spec/integration/02-cli/cmds/restart_spec.lua diff --git a/spec/integration/cli/cmds/start_spec.lua b/spec/integration/02-cli/cmds/start_spec.lua similarity index 100% rename from spec/integration/cli/cmds/start_spec.lua rename to spec/integration/02-cli/cmds/start_spec.lua diff --git a/spec/integration/cli/cmds/status_spec.lua b/spec/integration/02-cli/cmds/status_spec.lua similarity index 100% rename from spec/integration/cli/cmds/status_spec.lua rename to spec/integration/02-cli/cmds/status_spec.lua diff --git a/spec/integration/cli/cmds/version_spec.lua b/spec/integration/02-cli/cmds/version_spec.lua similarity index 77% rename from spec/integration/cli/cmds/version_spec.lua rename to spec/integration/02-cli/cmds/version_spec.lua index f2129a1bb95..9acf2c46409 100644 --- a/spec/integration/cli/cmds/version_spec.lua +++ b/spec/integration/02-cli/cmds/version_spec.lua @@ -6,6 +6,6 @@ local spec_helper = require "spec.spec_helpers" describe("CLI", function() it("should return the right version", function() local result = IO.os_execute(spec_helper.KONG_BIN.." version") - assert.equal(meta.name.." version: "..tostring(meta.version), stringy.strip(result)) + assert.equal(meta._NAME.." version: "..meta._VERSION, stringy.strip(result)) end) end) diff --git a/spec/integration/cli/services/dnsmasq_spec.lua b/spec/integration/02-cli/services/dnsmasq_spec.lua similarity index 100% rename from spec/integration/cli/services/dnsmasq_spec.lua rename to spec/integration/02-cli/services/dnsmasq_spec.lua diff --git a/spec/integration/cli/services/nginx_spec.lua b/spec/integration/02-cli/services/nginx_spec.lua similarity index 100% rename from spec/integration/cli/services/nginx_spec.lua rename to spec/integration/02-cli/services/nginx_spec.lua diff --git a/spec/integration/cli/services/serf_spec.lua b/spec/integration/02-cli/services/serf_spec.lua similarity index 100% rename from spec/integration/cli/services/serf_spec.lua rename to spec/integration/02-cli/services/serf_spec.lua diff --git a/spec/unit/tools/syslog_spec.lua b/spec/integration/02-syslog_spec.lua similarity index 98% rename from spec/unit/tools/syslog_spec.lua rename to spec/integration/02-syslog_spec.lua index 0af0680e7b5..420e7b0e6d1 100644 --- a/spec/unit/tools/syslog_spec.lua +++ b/spec/integration/02-syslog_spec.lua @@ -47,7 +47,7 @@ describe("Syslog", function() has_hostname = true elseif parts[1] == "hello" and parts[2] and parts[2] == "world" then has_hello = true - elseif parts[1] == "version" and parts[2] and parts[2] == tostring(meta.version) then + elseif parts[1] == "version" and parts[2] and parts[2] == meta._VERSION then has_version = true end end diff --git a/spec/integration/core/hooks_spec.lua b/spec/integration/03-core/hooks_spec.lua similarity index 100% rename from spec/integration/core/hooks_spec.lua rename to spec/integration/03-core/hooks_spec.lua diff --git a/spec/integration/admin_api/apis_routes_spec.lua b/spec/integration/04-admin_api/apis_routes_spec.lua similarity index 100% rename from spec/integration/admin_api/apis_routes_spec.lua rename to spec/integration/04-admin_api/apis_routes_spec.lua diff --git a/spec/integration/admin_api/cache_routes_spec.lua b/spec/integration/04-admin_api/cache_routes_spec.lua similarity index 100% rename from spec/integration/admin_api/cache_routes_spec.lua rename to spec/integration/04-admin_api/cache_routes_spec.lua diff --git a/spec/integration/admin_api/cluster_routes_spec.lua b/spec/integration/04-admin_api/cluster_routes_spec.lua similarity index 100% rename from spec/integration/admin_api/cluster_routes_spec.lua rename to spec/integration/04-admin_api/cluster_routes_spec.lua diff --git a/spec/integration/admin_api/consumers_routes_spec.lua b/spec/integration/04-admin_api/consumers_routes_spec.lua similarity index 100% rename from spec/integration/admin_api/consumers_routes_spec.lua rename to spec/integration/04-admin_api/consumers_routes_spec.lua diff --git a/spec/integration/admin_api/kong_routes_spec.lua b/spec/integration/04-admin_api/kong_routes_spec.lua similarity index 87% rename from spec/integration/admin_api/kong_routes_spec.lua rename to spec/integration/04-admin_api/kong_routes_spec.lua index 7d63f337418..7cc55d70633 100644 --- a/spec/integration/admin_api/kong_routes_spec.lua +++ b/spec/integration/04-admin_api/kong_routes_spec.lua @@ -27,16 +27,14 @@ describe("Admin API", function() local body = json.decode(response) assert.truthy(body.version) assert.truthy(body.tagline) - assert.equal(tostring(meta.version), body.version) + assert.equal(meta._VERSION, body.version) end) - it("should have a Server header", function() local _, status, headers = http_client.get(spec_helper.API_URL) assert.equal(200, status) - assert.equal(string.format("%s/%s", meta.name, tostring(meta.version)), headers.server) + assert.equal(string.format("%s/%s", meta._NAME, meta._VERSION), headers.server) assert.falsy(headers.via) -- Via is only set for proxied requests end) - it("should return method not allowed", function() local res, status = http_client.post(spec_helper.API_URL) assert.equal(405, status) @@ -87,7 +85,10 @@ describe("Admin API", function() describe("Request size", function() it("should properly hanlde big POST bodies < 10MB", function() - local response, status = http_client.post(spec_helper.API_URL.."/apis", {request_host = "hello.com", upstream_url = "http://mockbin.org"}) + local response, status = http_client.post(spec_helper.API_URL.."/apis", { + request_host = "hello.com", + upstream_url = "http://mockbin.org" + }) assert.equal(201, status) local api_id = json.decode(response).id assert.truthy(api_id) @@ -96,12 +97,17 @@ describe("Admin API", function() big_value = string.sub(big_value, 1, string.len(big_value) - 1) assert.truthy(string.len(big_value) > 10000) -- More than 10kb - local _, status = http_client.post(spec_helper.API_URL.."/apis/"..api_id.."/plugins/", { name = "ip-restriction", ["config.blacklist"] = big_value}) + local _, status = http_client.post(spec_helper.API_URL.."/apis/"..api_id.."/plugins/", { + name = "ip-restriction", + ["config.blacklist"] = big_value + }) assert.equal(201, status) end) - it("should fail with requests > 10MB", function() - local response, status = http_client.post(spec_helper.API_URL.."/apis", {request_host = "hello2.com", upstream_url = "http://mockbin.org"}) + local response, status = http_client.post(spec_helper.API_URL.."/apis", { + request_host = "hello2.com", + upstream_url = "http://mockbin.org" + }) assert.equal(201, status) local api_id = json.decode(response).id assert.truthy(api_id) @@ -111,9 +117,11 @@ describe("Admin API", function() big_value = string.sub(big_value, 1, string.len(big_value) - 1) assert.truthy(string.len(big_value) > 10000000) -- More than 10kb - local _, status = http_client.post(spec_helper.API_URL.."/apis/"..api_id.."/plugins/", { name = "ip-restriction", ["config.blacklist"] = big_value}) + local _, status = http_client.post(spec_helper.API_URL.."/apis/"..api_id.."/plugins/", { + name = "ip-restriction", + ["config.blacklist"] = big_value + }) assert.equal(413, status) end) end) - end) diff --git a/spec/integration/admin_api/plugins_routes_spec.lua b/spec/integration/04-admin_api/plugins_routes_spec.lua similarity index 100% rename from spec/integration/admin_api/plugins_routes_spec.lua rename to spec/integration/04-admin_api/plugins_routes_spec.lua diff --git a/spec/integration/proxy/dns_resolver_spec.lua b/spec/integration/05-proxy/dns_resolver_spec.lua similarity index 100% rename from spec/integration/proxy/dns_resolver_spec.lua rename to spec/integration/05-proxy/dns_resolver_spec.lua diff --git a/spec/integration/proxy/plugins_triggering_spec.lua b/spec/integration/05-proxy/plugins_triggering_spec.lua similarity index 100% rename from spec/integration/proxy/plugins_triggering_spec.lua rename to spec/integration/05-proxy/plugins_triggering_spec.lua diff --git a/spec/integration/proxy/realip_spec.lua b/spec/integration/05-proxy/realip_spec.lua similarity index 100% rename from spec/integration/proxy/realip_spec.lua rename to spec/integration/05-proxy/realip_spec.lua diff --git a/spec/integration/proxy/resolver_spec.lua b/spec/integration/05-proxy/resolver_spec.lua similarity index 98% rename from spec/integration/proxy/resolver_spec.lua rename to spec/integration/05-proxy/resolver_spec.lua index 255ecc75c68..b2846160f78 100644 --- a/spec/integration/proxy/resolver_spec.lua +++ b/spec/integration/05-proxy/resolver_spec.lua @@ -175,12 +175,12 @@ describe("Resolver", function() local _, status, headers = http_client.get(STUB_GET_URL, nil, {host = "mockbin.com"}) assert.equal(200, status) assert.equal("cloudflare-nginx", headers.server) - assert.equal(meta.name.."/"..tostring(meta.version), headers.via) + assert.equal(meta._NAME.."/"..meta._VERSION, headers.via) end) it("should return the correct Server and no Via header when the request was NOT proxied", function() local _, status, headers = http_client.get(STUB_GET_URL, nil, {host = "mockbin-auth.com"}) assert.equal(401, status) - assert.equal(meta.name.."/"..tostring(meta.version), headers.server) + assert.equal(meta._NAME.."/"..meta._VERSION, headers.server) assert.falsy(headers.via) end) it("should return correct timing headers when the request was proxied", function() diff --git a/spec/integration/cluster/cluster_spec.lua b/spec/integration/06-cluster/cluster_spec.lua similarity index 100% rename from spec/integration/cluster/cluster_spec.lua rename to spec/integration/06-cluster/cluster_spec.lua diff --git a/spec/integration/admin_api/route_helpers_spec.lua b/spec/integration/admin_api/route_helpers_spec.lua deleted file mode 100644 index e817179b086..00000000000 --- a/spec/integration/admin_api/route_helpers_spec.lua +++ /dev/null @@ -1,22 +0,0 @@ -local route_helpers = require "kong.api.route_helpers" -local utils = require "kong.tools.utils" - -describe("Route Helpers", function() - - it("should return the hostname", function() - assert.truthy(utils.get_hostname()) - end) - - it("should return parse the nginx status", function() - local status = "Active connections: 33 \nserver accepts handled requests\n 3 5 7 \nReading: 314 Writing: 1 Waiting: 2 \n" - local res = route_helpers.parse_status(status) - - assert.are.equal(33, res.connections_active) - assert.are.equal(3, res.connections_accepted) - assert.are.equal(5, res.connections_handled) - assert.are.equal(7, res.total_requests) - assert.are.equal(314, res.connections_reading) - assert.are.equal(1, res.connections_writing) - assert.are.equal(2, res.connections_waiting) - end) -end) diff --git a/spec/integration/cli/utils/luarocks_spec.lua b/spec/integration/cli/utils/luarocks_spec.lua deleted file mode 100644 index 0024cf3731a..00000000000 --- a/spec/integration/cli/utils/luarocks_spec.lua +++ /dev/null @@ -1,21 +0,0 @@ -local luarocks = require "kong.cli.utils.luarocks" - -describe("Luarocks", function() - - it("should get luarocks dir", function() - local res = luarocks.get_dir() - assert.truthy(res.name) - assert.truthy(res.root) - end) - - it("should get luarocks config dir", function() - local res = luarocks.get_config_dir() - assert.truthy(res) - end) - - it("should get luarocks install dir", function() - local res = luarocks.get_install_dir() - assert.truthy(res) - end) - -end) diff --git a/spec/plugins/basic-auth/access_spec.lua b/spec/plugins/basic-auth/access_spec.lua index ad01ec589b7..4edce08ed2b 100644 --- a/spec/plugins/basic-auth/access_spec.lua +++ b/spec/plugins/basic-auth/access_spec.lua @@ -39,7 +39,7 @@ describe("Authentication Plugin", function() local response, status, headers = http_client.get(PROXY_URL.."/get", {}, {host = "basicauth.com"}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal('Basic realm="'..meta.name..'"', headers["www-authenticate"]) + assert.equal('Basic realm="'..meta._NAME..'"', headers["www-authenticate"]) assert.equal("Unauthorized", body.message) end) @@ -75,7 +75,7 @@ describe("Authentication Plugin", function() local response, status, headers = http_client.get(PROXY_URL.."/get", {}, {host = "basicauth.com", authorization123 = "Basic dXNlcm5hbWU6cGFzc3dvcmQ="}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal('Basic realm="'..meta.name..'"', headers["www-authenticate"]) + assert.equal('Basic realm="'..meta._NAME..'"', headers["www-authenticate"]) assert.equal("Unauthorized", body.message) end) diff --git a/spec/plugins/key-auth/access_spec.lua b/spec/plugins/key-auth/access_spec.lua index b4acfd338dc..902ebe6add0 100644 --- a/spec/plugins/key-auth/access_spec.lua +++ b/spec/plugins/key-auth/access_spec.lua @@ -40,7 +40,7 @@ describe("key-auth plugin", function() local response, status, headers = http_client.get(STUB_GET_URL, {}, {host = "keyauth1.com"}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal('Key realm="'..meta.name..'"', headers["www-authenticate"]) + assert.equal('Key realm="'..meta._NAME..'"', headers["www-authenticate"]) assert.equal("No API Key found in headers, body or querystring", body.message) end) @@ -55,7 +55,7 @@ describe("key-auth plugin", function() local response, status, headers = http_client.get(STUB_GET_URL, {apikey123 = "apikey123"}, {host = "keyauth1.com"}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal('Key realm="'..meta.name..'"', headers["www-authenticate"]) + assert.equal('Key realm="'..meta._NAME..'"', headers["www-authenticate"]) assert.equal("No API Key found in headers, body or querystring", body.message) end) @@ -63,7 +63,7 @@ describe("key-auth plugin", function() local response, status, headers = http_client.get(STUB_GET_URL, {apikey123 = "apikey123"}, {host = "keyauth1.com"}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal('Key realm="'..meta.name..'"', headers["www-authenticate"]) + assert.equal('Key realm="'..meta._NAME..'"', headers["www-authenticate"]) assert.equal("No API Key found in headers, body or querystring", body.message) end) @@ -71,7 +71,7 @@ describe("key-auth plugin", function() local response, status, headers = http_client.post(STUB_POST_URL, {apikey123 = "apikey123"}, {host = "keyauth1.com"}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal('Key realm="'..meta.name..'"', headers["www-authenticate"]) + assert.equal('Key realm="'..meta._NAME..'"', headers["www-authenticate"]) assert.equal("No API Key found in headers, body or querystring", body.message) end) @@ -86,7 +86,7 @@ describe("key-auth plugin", function() local response, status, headers = http_client.get(STUB_GET_URL, {}, {host = "keyauth1.com", apikey123 = "apikey123"}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal('Key realm="'..meta.name..'"', headers["www-authenticate"]) + assert.equal('Key realm="'..meta._NAME..'"', headers["www-authenticate"]) assert.equal("No API Key found in headers, body or querystring", body.message) end) @@ -94,7 +94,7 @@ describe("key-auth plugin", function() local response, status, headers = http_client.post(STUB_POST_URL, {}, {host = "keyauth1.com", apikey123 = "apikey123"}) local body = cjson.decode(response) assert.equal(401, status) - assert.equal('Key realm="'..meta.name..'"', headers["www-authenticate"]) + assert.equal('Key realm="'..meta._NAME..'"', headers["www-authenticate"]) assert.equal("No API Key found in headers, body or querystring", body.message) end) diff --git a/spec/unit/rockspec_spec.lua b/spec/unit/01-rockspec_spec.lua similarity index 100% rename from spec/unit/rockspec_spec.lua rename to spec/unit/01-rockspec_spec.lua diff --git a/spec/unit/tools/utils_spec.lua b/spec/unit/02-utils_spec.lua similarity index 100% rename from spec/unit/tools/utils_spec.lua rename to spec/unit/02-utils_spec.lua diff --git a/spec/unit/tools/timestamp_spec.lua b/spec/unit/03-timestamp_spec.lua similarity index 100% rename from spec/unit/tools/timestamp_spec.lua rename to spec/unit/03-timestamp_spec.lua diff --git a/spec/unit/tools/io_spec.lua b/spec/unit/04-io_spec.lua similarity index 100% rename from spec/unit/tools/io_spec.lua rename to spec/unit/04-io_spec.lua diff --git a/spec/unit/tools/faker_spec.lua b/spec/unit/05-faker_spec.lua similarity index 100% rename from spec/unit/tools/faker_spec.lua rename to spec/unit/05-faker_spec.lua diff --git a/spec/unit/schemas_spec.lua b/spec/unit/10-schema_validation_spec.lua similarity index 100% rename from spec/unit/schemas_spec.lua rename to spec/unit/10-schema_validation_spec.lua diff --git a/spec/unit/dao/entities_schemas_spec.lua b/spec/unit/11-entities_schemas_spec.lua similarity index 100% rename from spec/unit/dao/entities_schemas_spec.lua rename to spec/unit/11-entities_schemas_spec.lua diff --git a/spec/unit/12-api_helpers_spec.lua b/spec/unit/12-api_helpers_spec.lua new file mode 100644 index 00000000000..e56bb97c343 --- /dev/null +++ b/spec/unit/12-api_helpers_spec.lua @@ -0,0 +1,80 @@ +local api_helpers = require "kong.api.api_helpers" +local norm = api_helpers.normalize_nested_params + +describe("api_helpers", function() + describe("normalize_nested_params()", function() + it("renders table from dot notation", function() + assert.same({ + foo = "bar", + number = 10, + config = { + nested = 1, + nested_2 = 2 + } + }, norm { + foo = "bar", + number = 10, + ["config.nested"] = 1, + ["config.nested_2"] = 2 + }) + + assert.same({ + foo = 'bar', + number = 10, + config = { + nested = { + ["sub-nested"] = "hi" + }, + nested_1 = 1, + nested_2 = 2 + } + }, norm { + foo = "bar", + number = 10, + ["config.nested_1"] = 1, + ["config.nested_2"] = 2, + ["config.nested.sub-nested"] = "hi" + }) + end) + it("integer indexes arrays with integer strings", function() + assert.same({ + foo = 'bar', + number = 10, + config = { + nested = {"hello", "world"}, + } + }, norm { + foo = "bar", + number = 10, + ["config.nested"] = {["1"]="hello", ["2"]="world"} + }) + end) + it("complete use case", function() + assert.same({ + api_id = 123, + name = "request-transformer", + config = { + add = { + form = "new-form-param:some_value, another-form-param:some_value", + headers = "x-new-header:some_value, x-another-header:some_value", + querystring = "new-param:some_value, another-param:some_value" + }, + remove = { + form = "formparam-toremove", + headers = "x-toremove, x-another-one", + querystring = "param-toremove, param-another-one" + } + } + }, norm { + api_id = 123, + name = "request-transformer", + ["config.add.headers"] = "x-new-header:some_value, x-another-header:some_value", + ["config.add.querystring"] = "new-param:some_value, another-param:some_value", + ["config.add.form"] = "new-form-param:some_value, another-form-param:some_value", + ["config.remove.headers"] = "x-toremove, x-another-one", + ["config.remove.querystring"] = "param-toremove, param-another-one", + ["config.remove.form"] = "formparam-toremove" + }) + end) + end) +end) diff --git a/spec/unit/tools/responses_spec.lua b/spec/unit/13-responses_spec.lua similarity index 98% rename from spec/unit/tools/responses_spec.lua rename to spec/unit/13-responses_spec.lua index adbdb966058..ff31b8c4430 100644 --- a/spec/unit/tools/responses_spec.lua +++ b/spec/unit/13-responses_spec.lua @@ -33,7 +33,7 @@ describe("Responses", function() it("should set the correct ngx values and call ngx.say and ngx.exit", function() responses.send_HTTP_OK("OK") assert.equal(ngx.status, responses.status_codes.HTTP_OK) - assert.equal(meta.name.."/"..tostring(meta.version), ngx.header["Server"]) + assert.equal(meta._NAME.."/"..meta._VERSION, ngx.header["Server"]) assert.stub(ngx.say).was.called() -- set custom content assert.stub(ngx.exit).was.called() -- exit nginx (or continue to the next context if 200) end) diff --git a/spec/unit/tools/config_loader_spec.lua b/spec/unit/14-config_loader_spec.lua similarity index 100% rename from spec/unit/tools/config_loader_spec.lua rename to spec/unit/14-config_loader_spec.lua diff --git a/spec/unit/tools/database_cache_spec.lua b/spec/unit/15-database_cache_spec.lua similarity index 100% rename from spec/unit/tools/database_cache_spec.lua rename to spec/unit/15-database_cache_spec.lua diff --git a/spec/unit/core/resolver_spec.lua b/spec/unit/16-resolver_spec.lua similarity index 100% rename from spec/unit/core/resolver_spec.lua rename to spec/unit/16-resolver_spec.lua diff --git a/spec/unit/api/app_spec.lua b/spec/unit/api/app_spec.lua deleted file mode 100644 index 1fca26d6f2c..00000000000 --- a/spec/unit/api/app_spec.lua +++ /dev/null @@ -1,115 +0,0 @@ -require "kong.tools.ngx_stub" - -local app = require "kong.api.app" - -local stub = { - req = { headers = {} }, - add_params = function() end, - params = { foo = "bar", number = 10, ["config.nested"] = 1, ["config.nested_2"] = 2 } -} - -describe("App", function() - describe("#parse_params()", function() - - it("should normalize nested properties for parsed form-encoded parameters", function() - -- Here Lapis already parsed the form-encoded parameters but we are normalizing - -- the nested ones (with "." keys) - local f = app.parse_params(function(stub) - assert.are.same({ - foo = "bar", - number = 10, - config = { - nested = 1, - nested_2 = 2 - } - }, stub.params) - end) - f(stub) - end) - - it("should parse a JSON body", function() - -- Here we are simply decoding a JSON body (which is a string) - ngx.req.get_body_data = function() return '{"foo":"bar","number":10,"config":{"nested":1,"nested_2":2}}' end - stub.req.headers["Content-Type"] = "application/json; charset=utf-8" - - local f = app.parse_params(function(stub) - assert.are.same({ - foo = "bar", - number = 10, - config = { - nested = 1, - nested_2 = 2 - } - }, stub.params) - end) - f(stub) - end) - - it("should normalize sub-nested properties for parsed form-encoded parameters", function() - stub.params = { foo = "bar", number = 10, ["config.nested_1"] = 1, ["config.nested_2"] = 2, - ["config.nested.sub-nested"] = "hi" - } - local f = app.parse_params(function(stub) - assert.are.same({ - foo = 'bar', - number = 10, - config = { - nested = { - ["sub-nested"] = "hi" - }, - nested_1 = 1, - nested_2 = 2 - } - }, stub.params) - end) - f(stub) - end) - - it("should normalize nested properties when they are plain arrays", function() - stub.params = { foo = "bar", number = 10, ["config.nested"] = {["1"]="hello", ["2"]="world"}} - local f = app.parse_params(function(stub) - assert.are.same({ - foo = 'bar', - number = 10, - config = { - nested = {"hello", "world"}, - }}, stub.params) - end) - f(stub) - end) - - it("should normalize very complex values", function() - stub.params = { - api_id = 123, - name = "request-transformer", - ["config.add.headers"] = "x-new-header:some_value, x-another-header:some_value", - ["config.add.querystring"] = "new-param:some_value, another-param:some_value", - ["config.add.form"] = "new-form-param:some_value, another-form-param:some_value", - ["config.remove.headers"] = "x-toremove, x-another-one", - ["config.remove.querystring"] = "param-toremove, param-another-one", - ["config.remove.form"] = "formparam-toremove" - } - - local f = app.parse_params(function(stub) - assert.are.same({ - api_id = 123, - name = "request-transformer", - config = { - add = { - form = "new-form-param:some_value, another-form-param:some_value", - headers = "x-new-header:some_value, x-another-header:some_value", - querystring = "new-param:some_value, another-param:some_value" - }, - remove = { - form = "formparam-toremove", - headers = "x-toremove, x-another-one", - querystring = "param-toremove, param-another-one" - } - } - }, stub.params) - end) - f(stub) - end) - - end) -end)