-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(redis): add default port for standardized redis config
The default port should be 6379. This was how RateLimiting and Response-RateLimiting worked before redis config standardization. KAG-3618
- Loading branch information
Showing
7 changed files
with
198 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
local schema_def = require "spec.fixtures.custom_plugins.kong.plugins.redis-dummy.schema" | ||
local v = require("spec.helpers").validate_plugin_config_schema | ||
|
||
|
||
describe("Validate standardized redis config schema", function() | ||
describe("valid config", function() | ||
it("accepts minimal redis config (populates defaults)", function() | ||
local config = { | ||
redis = { | ||
host = "localhost" | ||
} | ||
} | ||
local ok, err = v(config, schema_def) | ||
assert.truthy(ok) | ||
assert.same({ | ||
host = "localhost", | ||
port = 6379, | ||
timeout = 2000, | ||
username = ngx.null, | ||
password = ngx.null, | ||
database = 0, | ||
ssl = false, | ||
ssl_verify = false, | ||
server_name = ngx.null, | ||
}, ok.config.redis) | ||
assert.is_nil(err) | ||
end) | ||
|
||
it("full redis config", function() | ||
local config = { | ||
redis = { | ||
host = "localhost", | ||
port = 9900, | ||
timeout = 3333, | ||
username = "test", | ||
password = "testXXX", | ||
database = 5, | ||
ssl = true, | ||
ssl_verify = true, | ||
server_name = "example.test" | ||
} | ||
} | ||
local ok, err = v(config, schema_def) | ||
assert.truthy(ok) | ||
assert.same(config.redis, ok.config.redis) | ||
assert.is_nil(err) | ||
end) | ||
|
||
it("allows empty strings on password", function() | ||
local config = { | ||
redis = { | ||
host = "localhost", | ||
password = "", | ||
} | ||
} | ||
local ok, err = v(config, schema_def) | ||
assert.truthy(ok) | ||
assert.same({ | ||
host = "localhost", | ||
port = 6379, | ||
timeout = 2000, | ||
username = ngx.null, | ||
password = "", | ||
database = 0, | ||
ssl = false, | ||
ssl_verify = false, | ||
server_name = ngx.null, | ||
}, ok.config.redis) | ||
assert.is_nil(err) | ||
end) | ||
end) | ||
|
||
describe("invalid config", function() | ||
it("rejects invalid config", function() | ||
local config = { | ||
redis = { | ||
host = "", | ||
port = -5, | ||
timeout = -5, | ||
username = 1, | ||
password = 4, | ||
database = "abc", | ||
ssl = "abc", | ||
ssl_verify = "xyz", | ||
server_name = "test-test" | ||
} | ||
} | ||
local ok, err = v(config, schema_def) | ||
assert.falsy(ok) | ||
assert.same({ | ||
config = { | ||
redis = { | ||
database = 'expected an integer', | ||
host = 'length must be at least 1', | ||
password = 'expected a string', | ||
port = 'value should be between 0 and 65535', | ||
ssl = 'expected a boolean', | ||
ssl_verify = 'expected a boolean', | ||
timeout = 'value should be between 0 and 2147483646', | ||
username = 'expected a string', | ||
} | ||
} | ||
}, err) | ||
end) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,40 @@ describe("Plugin: acme (schema)", function() | |
} | ||
}, | ||
}, | ||
---------------------------------------- | ||
{ | ||
name = "accepts valid redis config", | ||
input = { | ||
account_email = "[email protected]", | ||
storage = "redis", | ||
storage_config = { | ||
redis = { | ||
host = "localhost" | ||
}, | ||
} | ||
}, | ||
}, | ||
---------------------------------------- | ||
{ | ||
name = "rejects invalid redis config", | ||
input = { | ||
account_email = "[email protected]", | ||
storage = "redis", | ||
storage_config = { | ||
redis = { }, | ||
} | ||
}, | ||
error = { | ||
["@entity"] = { "failed conditional validation given value of field 'config.storage'" }, | ||
config = { | ||
storage_config = { | ||
redis = { | ||
host = "required field missing", | ||
} | ||
} | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, t in ipairs(tests) do | ||
|
12 changes: 12 additions & 0 deletions
12
spec/fixtures/custom_plugins/kong/plugins/redis-dummy/handler.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
local kong = kong | ||
|
||
local RedisDummy = { | ||
PRIORITY = 1000, | ||
VERSION = "0.1.0", | ||
} | ||
|
||
function RedisDummy:access(conf) | ||
kong.log("access phase") | ||
end | ||
|
||
return RedisDummy |
15 changes: 15 additions & 0 deletions
15
spec/fixtures/custom_plugins/kong/plugins/redis-dummy/schema.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
local redis_schema = require "kong.tools.redis.schema" | ||
|
||
return { | ||
name = "redis-dummy", | ||
fields = { | ||
{ | ||
config = { | ||
type = "record", | ||
fields = { | ||
{ redis = redis_schema.config_schema }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} |