-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: create test for multivar on keyval command
- Loading branch information
Showing
1 changed file
with
186 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
use Test::Nginx::Socket 'no_plan'; | ||
|
||
no_root_location(); | ||
no_shuffle(); | ||
|
||
run_tests(); | ||
|
||
__DATA__ | ||
=== Same host but different UA | ||
--- http_config | ||
keyval_zone zone=test:1M; | ||
keyval $remote_addr:$http_user_agent $keyval_data zone=test; | ||
--- config | ||
location = /get { | ||
return 200 "get($http_user_agent): $keyval_data\n"; | ||
} | ||
location = /set { | ||
set $keyval_data "test $http_user_agent"; | ||
return 200 "$keyval_data\n"; | ||
} | ||
--- request eval | ||
[ | ||
"GET /get", | ||
"GET /get", | ||
"GET /set", | ||
"GET /set", | ||
"GET /get", | ||
"GET /get" | ||
] | ||
--- more_headers eval | ||
[ | ||
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0", | ||
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", | ||
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0", | ||
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", | ||
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0", | ||
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36" | ||
] | ||
--- response_body eval | ||
[ | ||
"get(Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0): \n", | ||
"get(Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36): \n", | ||
"test Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0\n", | ||
"test Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36\n", | ||
"get(Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0): test Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0\n", | ||
"get(Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36): test Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36\n" | ||
] | ||
=== Two vars with different UAs | ||
--- http_config | ||
keyval_zone zone=test:5M; | ||
keyval "$remote_addr:$http_user_agent" $keyval_data1 zone=test; | ||
keyval "$remote_addr:$http_user_agent" $keyval_data2 zone=test; | ||
--- config | ||
location = /get { | ||
return 200 "get($http_user_agent): $keyval_data1 $keyval_data2\n"; | ||
} | ||
location = /set1 { | ||
set $keyval_data1 "test1 $http_user_agent"; | ||
return 200 "$keyval_data1\n"; | ||
} | ||
location = /set2 { | ||
set $keyval_data2 "test2 $http_user_agent"; | ||
return 200 "$keyval_data2\n"; | ||
} | ||
--- request eval | ||
[ | ||
"GET /get", | ||
"GET /get", | ||
"GET /set1", | ||
"GET /set1", | ||
"GET /set2", | ||
"GET /set2", | ||
"GET /get", | ||
"GET /get" | ||
] | ||
--- more_headers eval | ||
[ | ||
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0", | ||
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", | ||
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0", | ||
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", | ||
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0", | ||
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", | ||
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0", | ||
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36" | ||
] | ||
--- response_body eval | ||
[ | ||
"get(Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0): \n", | ||
"get(Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36): \n", | ||
"test1 Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0\n", | ||
"test1 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36\n", | ||
"test2 Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0\n", | ||
"test2 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36\n", | ||
"get(Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0): test2 Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0 test2 Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0\n", | ||
"get(Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36): test2 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 test2 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36\n" | ||
] | ||
=== Same host but different UA and other chars in string | ||
--- http_config | ||
keyval_zone zone=test:1M; | ||
keyval "$remote_addr $http_user_agent random string random number 123456 test" $keyval_data zone=test; | ||
--- config | ||
location = /get { | ||
return 200 "get($http_user_agent): $keyval_data\n"; | ||
} | ||
location = /set { | ||
set $keyval_data "test $http_user_agent"; | ||
return 200 "$keyval_data\n"; | ||
} | ||
--- request eval | ||
[ | ||
"GET /get", | ||
"GET /get", | ||
"GET /set", | ||
"GET /set", | ||
"GET /get", | ||
"GET /get" | ||
] | ||
--- more_headers eval | ||
[ | ||
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0", | ||
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", | ||
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0", | ||
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", | ||
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0", | ||
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36" | ||
] | ||
--- response_body eval | ||
[ | ||
"get(Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0): \n", | ||
"get(Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36): \n", | ||
"test Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0\n", | ||
"test Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36\n", | ||
"get(Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0): test Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0\n", | ||
"get(Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36): test Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36\n" | ||
] | ||
=== Variables that exist and one that doesn't | ||
--- http_config | ||
keyval_zone zone=test:1M; | ||
keyval "$remote_addr $http_user_agent random string random number 123456 $hosst $request" $keyval_data zone=test; | ||
--- config | ||
--- must_die | ||
=== Pure text is still functional | ||
--- http_config | ||
keyval_zone zone=test:1M; | ||
keyval "text1 text2" $keyval_data zone=test; | ||
--- config | ||
location = /get { | ||
return 200 "get($http_user_agent): $keyval_data\n"; | ||
} | ||
location = /set { | ||
set $keyval_data "test $http_user_agent"; | ||
return 200 "$keyval_data\n"; | ||
} | ||
--- request eval | ||
[ | ||
"GET /get", | ||
"GET /get", | ||
"GET /set", | ||
"GET /set", | ||
"GET /get", | ||
"GET /get" | ||
] | ||
--- more_headers eval | ||
[ | ||
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0", | ||
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", | ||
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0", | ||
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36", | ||
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0", | ||
"User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36" | ||
] | ||
--- response_body eval | ||
[ | ||
"get(Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0): \n", | ||
"get(Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36): \n", | ||
"test Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0\n", | ||
"test Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36\n", | ||
"get(Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:123.0) Gecko/20100101 Firefox/123.0): test Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36\n", | ||
"get(Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36): test Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36\n" | ||
] |