-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] bugfix: check plugin schema when sync data #1875
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
553384c
fix: add check plugin's schema in sync data
408ecb9
fix: add check plugin's schema in sync data
45fd6ba
feat: add check plugin's schema test
f695a98
refactor: move config-center-yaml to config-center/yaml
60a7e6c
fix: fix test case of route-plugin
wrl96 b589c64
fix: add check plugin's schema in sync data
bdec513
fix: add check plugin's schema in sync data
3dfbf27
feat: add check plugin's schema test
c5d5a75
refactor: move config-center-yaml to config-center/yaml
026e2bb
fix: fix test case of route-plugin
wrl96 ce93175
Merge branch 'fix-1604' of https://github.com/wrl96/incubator-apisix …
wrl96 022f827
fix: set pairs in local
wrl96 2b5aef7
Merge remote-tracking branch 'origin/fix-1604' into fix-1604
wrl96 48b9c4a
feat: add test casesof etcd
wrl96 2212d9e
feat: add test cases of etcd
wrl96 ee95248
feat: add test cases of etcd
wrl96 9778b7d
fix: spell error
wrl96 b3c1b3d
fix: test case error
wrl96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
BEGIN { | ||
$ENV{"ETCD_ENABLE_AUTH"} = "true" | ||
} | ||
|
||
use t::APISIX 'no_plan'; | ||
|
||
repeat_each(1); | ||
no_long_string(); | ||
no_shuffle(); | ||
no_root_location(); | ||
log_level("info"); | ||
|
||
# Authentication is enabled at etcd and credentials are set | ||
system('etcdctl --endpoints="http://127.0.0.1:2379" -u root:5tHkHhYkjr6cQY user add root:5tHkHhYkjr6cQY'); | ||
system('etcdctl --endpoints="http://127.0.0.1:2379" -u root:5tHkHhYkjr6cQY auth enable'); | ||
system('etcdctl --endpoints="http://127.0.0.1:2379" -u root:5tHkHhYkjr6cQY role revoke --path "/*" -rw guest'); | ||
|
||
run_tests; | ||
|
||
# Authentication is disabled at etcd & guest access is granted | ||
system('etcdctl --endpoints="http://127.0.0.1:2379" -u root:5tHkHhYkjr6cQY auth disable'); | ||
system('etcdctl --endpoints="http://127.0.0.1:2379" -u root:5tHkHhYkjr6cQY role grant --path "/*" -rw guest'); | ||
|
||
__DATA__ | ||
|
||
=== TEST 1: set route with plugin | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local core = require("apisix.core") | ||
local conf = { | ||
["uri"] = "/hello", | ||
["plugins"] = { | ||
["proxy-rewrite"] = { | ||
["uri"] = "/uri/plugin_proxy_rewrite", | ||
["headers"] = { | ||
["X-Api-Version"] = "v2" | ||
} | ||
} | ||
}, | ||
["upstream"] = { | ||
["nodes"] = { | ||
["127.0.0.1:1980"] = 1 | ||
}, | ||
["type"] = "roundrobin" | ||
} | ||
} | ||
local res, err = core.etcd.push("/routes", conf) | ||
if not res then | ||
core.log.error("failed to post route[/routes] to etcd") | ||
ngx.exit(code) | ||
end | ||
ngx.say("done") | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
done | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 2: route with plugin | ||
--- request | ||
GET /hello | ||
--- more_headers | ||
X-Api-Version:v1 | ||
--- response_body | ||
uri: /uri/plugin_proxy_rewrite | ||
host: localhost | ||
x-api-version: v2 | ||
x-real-ip: 127.0.0.1 | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 3: set route with invalid plugin | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local core = require("apisix.core") | ||
local sub_str = string.sub | ||
local res, err = core.etcd.get("/routes") | ||
if not res then | ||
core.log.error("failed to get route[/routes] from etcd: ", err) | ||
end | ||
local key = sub_str(res.body.node.nodes[1].key, 8) | ||
local conf = { | ||
["uri"] = "/hello", | ||
["plugins"] = { | ||
["proxy-rewrite"] = { | ||
["uri"] = "/uri/plugin_proxy_rewrite", | ||
["headers"] = { | ||
[""] = "" | ||
} | ||
} | ||
}, | ||
["upstream"] = { | ||
["nodes"] = { | ||
["127.0.0.1:1980"] = 1 | ||
}, | ||
["type"] = "roundrobin" | ||
} | ||
} | ||
local res, err = core.etcd.set(key, conf) | ||
if not res then | ||
core.log.error("failed to put route[/routes] to etcd") | ||
ngx.exit(code) | ||
end | ||
ngx.say("done") | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
done | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 4: route with invalid plugin | ||
--- request | ||
GET /hello | ||
--- error_code: 404 | ||
--- error_log | ||
failed to check the configuration of plugin proxy-rewrite err: invalid type as header value, context: ngx.timer |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check the plugin
conf
in this way, it is not a good way.config_etcd.lua is a basic component, it should not know the plugin.
I think we can export a new option when creating new
config_etcd
object, then we can add more check logic infilter_func
.Example: