Skip to content
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

change(echo): remove odd auth_value #4055

Merged
merged 2 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions apisix/plugins/echo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ local schema = {
type = "object",
minProperties = 1,
},
auth_value = {
description = "auth value",
type = "string"
},
},
anyOf = {
{required = {"before_body"}},
Expand Down Expand Up @@ -91,16 +87,6 @@ function _M.body_filter(conf, ctx)
end


function _M.access(conf, ctx)
local value = core.request.header(ctx, "Authorization")

if value ~= conf.auth_value then
return 401, "unauthorized body"
end

end


function _M.header_filter(conf, ctx)
if conf.body or conf.before_body or conf.after_body then
core.response.clear_header_as_body_modified()
Expand Down
1 change: 0 additions & 1 deletion docs/en/latest/plugins/echo.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ This plugin addresses the corresponding functionality in the common phases such
| body | string | optional | | | Body to replace upstream response. |
| after_body | string | optional | | | Body after the modification of filter phase. |
| headers | object | optional | | | New headers for response |
| auth_value | string | optional | | | Auth value |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to remove it from the source & test too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


At least one of `before_body`, `body`, and `after_body` must be specified.

Expand Down
1 change: 0 additions & 1 deletion docs/zh/latest/plugins/echo.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ echo 可以帮助用户尽可能全面地了解如何开发APISIX插件。
| body | string | 可选 | | | 返回给客户端的响应内容,它将覆盖 upstream 返回的响应 body。 |
| after_body | string | 可选 | | | 在 body 属性之后添加的内容,如果 body 属性没有指定将在 upstream 响应 body 之后添加。 |
| headers | object | 可选 | | | 返回值的 headers |
| auth_value | string | 可选 | | | |

参数 before_body,body 和 after_body 至少要存在一个

Expand Down
258 changes: 8 additions & 250 deletions t/plugin/echo.t
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ done
"headers": {
"Location":"https://www.iresty.com",
"Authorization": "userpass"
},
"auth_value" : "userpass"
}
}
},
"upstream": {
Expand All @@ -108,7 +107,6 @@ done
"headers": {
"Location":"https://www.iresty.com"
},
"auth_value" : "userpass"
}
},
"upstream": {
Expand Down Expand Up @@ -143,8 +141,6 @@ passed
=== TEST 4: access
--- request
GET /hello
--- more_headers
Authorization: userpass
--- response_body chomp
before the body modification hello upstream after the body modification.
--- response_headers
Expand All @@ -167,7 +163,6 @@ Authorization: userpass
"plugins": {
"echo": {
"before_body": "before the body modification ",
"auth_value" : "userpass",
"headers": {
"Location":"https://www.iresty.com"
}
Expand All @@ -187,7 +182,6 @@ Authorization: userpass
"plugins": {
"echo": {
"before_body": "before the body modification ",
"auth_value" : "userpass",
"headers": {
"Location":"https://www.iresty.com"
}
Expand Down Expand Up @@ -225,8 +219,6 @@ passed
=== TEST 6: access without upstream body change
--- request
GET /hello
--- more_headers
Authorization: userpass
--- response_body
before the body modification hello world
--- response_headers
Expand All @@ -238,240 +230,7 @@ Location: https://www.iresty.com



=== TEST 7: update plugin back
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"echo": {
"before_body": "before the body modification ",
"auth_value" : "userpassword",
"headers": {
"Location":"https://www.iresty.com"
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]],
[[{
"node": {
"value": {
"plugins": {
"echo": {
"before_body": "before the body modification ",
"auth_value" : "userpassword",
"headers": {
"Location":"https://www.iresty.com"
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
},
"key": "/apisix/routes/1"
},
"action": "set"
}]]
)

if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]



=== TEST 8: access with wrong value in auth header value throws 401
--- request
GET /hello
--- more_headers
Authorization: userpass
--- error_code: 401
--- response_body chomp
before the body modification unauthorized body
--- response_headers
Location: https://www.iresty.com



=== TEST 9: update plugin back
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"echo": {
"before_body": "before the body modification ",
"headers": {
"Location":"https://www.iresty.com"
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]],
[[{
"node": {
"value": {
"plugins": {
"echo": {
"before_body": "before the body modification ",
"headers": {
"Location":"https://www.iresty.com"
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
},
"key": "/apisix/routes/1"
},
"action": "set"
}]]
)

if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]



=== TEST 10: access with no auth header and value throws 401
--- request
GET /hello
--- more_headers
Authorization: userpass
--- error_code: 401
--- response_body chomp
before the body modification unauthorized body
--- response_headers
Location: https://www.iresty.com



=== TEST 11: update plugin
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"echo": {
"before_body": "before the body modification ",
"auth_value" : "userpass",
"headers": {
"Location":"https://www.iresty.com"
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]],
[[{
"node": {
"value": {
"plugins": {
"echo": {
"before_body": "before the body modification ",
"auth_value" : "userpass",
"headers": {
"Location":"https://www.iresty.com"
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
},
"key": "/apisix/routes/1"
},
"action": "set"
}]]
)

if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]



=== TEST 12: access without authorization as a header should throws 401
--- request
GET /hello
--- error_code: 401
--- response_body chomp
before the body modification unauthorized body
--- response_headers
Location: https://www.iresty.com



=== TEST 13: print the `conf` in etcd, no dirty data
=== TEST 7: print the `conf` in etcd, no dirty data
--- config
location /t {
content_by_lua_block {
Expand All @@ -485,7 +244,6 @@ Location: https://www.iresty.com
"plugins": {
"echo": {
"before_body": "before the body modification ",
"auth_value" : "userpass",
"headers": {
"Location":"https://www.iresty.com"
}
Expand All @@ -506,13 +264,13 @@ Location: https://www.iresty.com
--- request
GET /t
--- response_body
{"echo":{"auth_value":"userpass","before_body":"before the body modification ","headers":{"Location":"https://www.iresty.com"}}}
{"echo":{"before_body":"before the body modification ","headers":{"Location":"https://www.iresty.com"}}}
--- no_error_log
[error]



=== TEST 14: additional property
=== TEST 8: additional property
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -540,7 +298,7 @@ additional properties forbidden, found invalid_att



=== TEST 15: set body with chunked upstream
=== TEST 9: set body with chunked upstream
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -578,7 +336,7 @@ passed



=== TEST 16: access
=== TEST 10: access
--- request
GET /hello_chunked
--- response_body chomp
Expand All @@ -588,7 +346,7 @@ hello upstream



=== TEST 17: add before/after body with chunked upstream
=== TEST 11: add before/after body with chunked upstream
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -627,7 +385,7 @@ passed



=== TEST 18: access
=== TEST 12: access
--- request
GET /hello_chunked
--- response_body chomp
Expand Down