-
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.
tests(plugins) fix plugins after moving all plugin schemas to new DAO
- Loading branch information
Showing
21 changed files
with
347 additions
and
301 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
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
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 |
---|---|---|
@@ -1,36 +1,36 @@ | ||
local validate_entity = require("kong.dao.schemas_validation").validate_entity | ||
local cors_schema = require "kong.plugins.cors.schema" | ||
|
||
local schema_def = require "kong.plugins.cors.schema" | ||
local v = require("spec.helpers").validate_plugin_config_schema | ||
|
||
describe("cors schema", function() | ||
it("validates '*'", function() | ||
local ok, err = validate_entity({ origins = { "*" } }, cors_schema) | ||
local ok, err = v({ origins = { "*" } }, schema_def) | ||
|
||
assert.True(ok) | ||
assert.is_nil(err) | ||
assert.truthy(ok) | ||
assert.falsy(err) | ||
end) | ||
|
||
it("validates what looks like a domain", function() | ||
local ok, err = validate_entity({ origins = { "example.com" } }, cors_schema) | ||
local ok, err = v({ origins = { "example.com" } }, schema_def) | ||
|
||
assert.True(ok) | ||
assert.is_nil(err) | ||
assert.truthy(ok) | ||
assert.falsy(err) | ||
end) | ||
|
||
it("validates what looks like a regex", function() | ||
local ok, err = validate_entity({ origins = { [[.*\.example(?:-foo)?\.com]] } }, cors_schema) | ||
local ok, err = v({ origins = { [[.*\.example(?:-foo)?\.com]] } }, schema_def) | ||
|
||
assert.True(ok) | ||
assert.is_nil(err) | ||
assert.truthy(ok) | ||
assert.falsy(err) | ||
end) | ||
|
||
describe("errors", function() | ||
it("with invalid regex in origins", function() | ||
local mock_origins = { [[.*.example.com]], [[invalid_**regex]] } | ||
local ok, err = validate_entity({ origins = mock_origins }, cors_schema) | ||
local ok, err = v({ origins = mock_origins }, schema_def) | ||
|
||
assert.False(ok) | ||
assert.equals("origin '" .. mock_origins[2] .. "' is not a valid regex", err.origins) | ||
assert.falsy(ok) | ||
assert.equals("'invalid_**regex' is not a valid regex", | ||
err.config.origins) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
local schemas = require "kong.dao.schemas_validation" | ||
local request_transformer_schema = require "kong.plugins.request-transformer.schema" | ||
|
||
|
||
local validate_entity = schemas.validate_entity | ||
local schema_def = require "kong.plugins.request-transformer.schema" | ||
local v = require("spec.helpers").validate_plugin_config_schema | ||
|
||
|
||
describe("Plugin: request-transformer (schema)", function() | ||
it("validates http_method", function() | ||
local ok, err = validate_entity({http_method = "GET"}, request_transformer_schema) | ||
assert.is_nil(err) | ||
local ok, err = v({ http_method = "GET" }, schema_def) | ||
assert.True(ok) | ||
assert.is_nil(err) | ||
end) | ||
it("errors invalid http_method", function() | ||
local ok, err = validate_entity({http_method = "HELLO"}, request_transformer_schema) | ||
assert.equal("HELLO is not supported", err.http_method) | ||
assert.False(ok) | ||
local ok, err = v({ http_method = "HELLO!" }, schema_def) | ||
assert.Falsy(ok) | ||
assert.equal("invalid value: HELLO!", err.config.http_method) | ||
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 |
---|---|---|
@@ -1,53 +1,49 @@ | ||
local validate_entity = require("kong.dao.schemas_validation").validate_entity | ||
local jwt_schema = require "kong.plugins.jwt.schema" | ||
local schema_def = require "kong.plugins.jwt.schema" | ||
local v = require("spec.helpers").validate_plugin_config_schema | ||
|
||
|
||
describe("Plugin: jwt (schema)", function() | ||
it("validates 'maximum_expiration'", function() | ||
local ok, err = validate_entity({ | ||
local ok, err = v({ | ||
maximum_expiration = 60, | ||
claims_to_verify = { "exp", "nbf" }, | ||
}, jwt_schema) | ||
}, schema_def) | ||
|
||
assert.is_nil(err) | ||
assert.is_true(ok) | ||
assert.is_truthy(ok) | ||
end) | ||
|
||
describe("errors", function() | ||
it("when 'maximum_expiration' is negative", function() | ||
local ok, err = validate_entity({ | ||
local ok, err = v({ | ||
maximum_expiration = -1, | ||
claims_to_verify = { "exp", "nbf" }, | ||
}, jwt_schema) | ||
}, schema_def) | ||
|
||
assert.is_false(ok) | ||
assert.is_falsy(ok) | ||
assert.same({ | ||
maximum_expiration = "should be 0 or greater" | ||
}, err) | ||
maximum_expiration = "value should be between 0 and 31536000" | ||
}, err.config) | ||
|
||
local ok, err = validate_entity({ | ||
local ok, err = v({ | ||
maximum_expiration = -1, | ||
claims_to_verify = { "nbf" }, | ||
}, jwt_schema) | ||
}, schema_def) | ||
|
||
assert.is_false(ok) | ||
assert.is_falsy(ok) | ||
assert.same({ | ||
maximum_expiration = "should be 0 or greater" | ||
}, err) | ||
maximum_expiration = "value should be between 0 and 31536000" | ||
}, err.config) | ||
end) | ||
|
||
it("when 'maximum_expiration' is specified without 'exp' in 'claims_to_verify'", function() | ||
local ok, err, self_err = validate_entity({ | ||
local ok, err = v({ | ||
maximum_expiration = 60, | ||
claims_to_verify = { "nbf" }, | ||
}, jwt_schema) | ||
}, schema_def) | ||
|
||
assert.is_false(ok) | ||
assert.is_nil(err) | ||
assert.same({ | ||
message = "claims_to_verify must contain 'exp' when specifying maximum_expiration", | ||
schema = true, | ||
}, self_err) | ||
assert.is_falsy(ok) | ||
assert.equals("expected to contain: exp", err.config.claims_to_verify) | ||
end) | ||
end) | ||
end) |
Oops, something went wrong.