Skip to content

Commit

Permalink
feat: plugin limit-count move unit tests again
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-flury committed Apr 18, 2023
1 parent 7159de9 commit 2dbfb68
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 167 deletions.
64 changes: 62 additions & 2 deletions t/plugin/limit-count-redis.t
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ passed
=== TEST 16: request for TEST 17
=== TEST 16: request for TEST 15
--- request
GET /hello
--- error_code eval
Expand All @@ -452,7 +452,67 @@ failed to limit count: WRONGPASS invalid username-password pair or user is disab
=== TEST 17: restore redis password to ''
=== TEST 17: set route, with redis host, port and right username and password
--- 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,
[[{
"uri": "/hello",
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr",
"policy": "redis",
"redis_host": "127.0.0.1",
"redis_port": 6379,
"redis_timeout": 1001,
"redis_username": "alice",
"redis_password": "somepassword"
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- response_body
passed
=== TEST 18: up the limit
--- pipelined_requests eval
["GET /hello", "GET /hello", "GET /hello", "GET /hello"]
--- error_code eval
[200, 200, 503, 503]
=== TEST 19: up the limit
--- pipelined_requests eval
["GET /hello1", "GET /hello", "GET /hello2", "GET /hello", "GET /hello"]
--- error_code eval
[404, 503, 404, 503, 503]
=== TEST 20: restore redis password to ''
--- config
location /t {
content_by_lua_block {
Expand Down
63 changes: 59 additions & 4 deletions t/plugin/limit-count-redis3.t
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ passed
=== TEST 5: set route, with redis host, port and right username and password
=== TEST 5: set route, with redis host, port and SSL
--- config
location /t {
content_by_lua_block {
Expand All @@ -207,10 +207,10 @@ passed
"key": "remote_addr",
"policy": "redis",
"redis_host": "127.0.0.1",
"redis_port": 6379,
"redis_port": 6380,
"redis_timeout": 1001,
"redis_username": "alice",
"redis_password": "somepassword"
"redis_ssl": true,
"redis_ssl_verify": false
}
},
"upstream": {
Expand Down Expand Up @@ -246,3 +246,58 @@ passed
["GET /hello1", "GET /hello", "GET /hello2", "GET /hello", "GET /hello"]
--- error_code eval
[404, 503, 404, 503, 503]
=== TEST 8: set route, with redis host, port, SSL and SSL verify is true(will cause ssl handshake err), with enable degradation switch
--- 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,
[[{
"uri": "/hello",
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr",
"allow_degradation": true,
"policy": "redis",
"redis_host": "127.0.0.1",
"redis_port": 6380,
"redis_timeout": 1001,
"redis_ssl": true,
"redis_ssl_verify": true
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- response_body
passed
=== TEST 9: enable degradation switch for TEST 8
--- request
GET /hello
--- response_body
hello world
--- error_log
failed to do ssl handshake
161 changes: 0 additions & 161 deletions t/plugin/limit-count-redis4.t

This file was deleted.

0 comments on commit 2dbfb68

Please sign in to comment.