11475Saxel.duch@nginx.com# -*- coding: utf-8 -*- 21596Szelenkov@nginx.comimport pytest 32055Szelenkov@nginx.comfrom unit.applications.lang.python import TestApplicationPython 41730Szelenkov@nginx.comfrom unit.option import option 5972Szelenkov@nginx.com 61017Szelenkov@nginx.com 72055Szelenkov@nginx.comclass TestRouting(TestApplicationPython): 81467Szelenkov@nginx.com prerequisites = {'modules': {'python': 'any'}} 9972Szelenkov@nginx.com 101596Szelenkov@nginx.com def setup_method(self): 111596Szelenkov@nginx.com assert 'success' in self.conf( 121596Szelenkov@nginx.com { 131596Szelenkov@nginx.com "listeners": {"*:7080": {"pass": "routes"}}, 141596Szelenkov@nginx.com "routes": [ 15*2073Szelenkov@nginx.com { 16*2073Szelenkov@nginx.com "match": {"method": "GET"}, 17*2073Szelenkov@nginx.com "action": {"return": 200}, 18*2073Szelenkov@nginx.com } 191596Szelenkov@nginx.com ], 201596Szelenkov@nginx.com "applications": {}, 211596Szelenkov@nginx.com } 221596Szelenkov@nginx.com ), 'routing configure' 23972Szelenkov@nginx.com 241101Szelenkov@nginx.com def route(self, route): 251101Szelenkov@nginx.com return self.conf([route], 'routes') 261101Szelenkov@nginx.com 271308Szelenkov@nginx.com def route_match(self, match): 281596Szelenkov@nginx.com assert 'success' in self.route( 291596Szelenkov@nginx.com {"match": match, "action": {"return": 200}} 301596Szelenkov@nginx.com ), 'route match configure' 311037Szelenkov@nginx.com 321308Szelenkov@nginx.com def route_match_invalid(self, match): 331596Szelenkov@nginx.com assert 'error' in self.route( 341596Szelenkov@nginx.com {"match": match, "action": {"return": 200}} 351596Szelenkov@nginx.com ), 'route match configure invalid' 361037Szelenkov@nginx.com 371308Szelenkov@nginx.com def host(self, host, status): 381596Szelenkov@nginx.com assert ( 391596Szelenkov@nginx.com self.get(headers={'Host': host, 'Connection': 'close'})['status'] 401596Szelenkov@nginx.com == status 411596Szelenkov@nginx.com ), 'match host' 421308Szelenkov@nginx.com 431308Szelenkov@nginx.com def cookie(self, cookie, status): 441596Szelenkov@nginx.com assert ( 451308Szelenkov@nginx.com self.get( 461308Szelenkov@nginx.com headers={ 471308Szelenkov@nginx.com 'Host': 'localhost', 481308Szelenkov@nginx.com 'Cookie': cookie, 491308Szelenkov@nginx.com 'Connection': 'close', 501308Szelenkov@nginx.com }, 511596Szelenkov@nginx.com )['status'] 521596Szelenkov@nginx.com == status 531596Szelenkov@nginx.com ), 'match cookie' 541037Szelenkov@nginx.com 551308Szelenkov@nginx.com def test_routes_match_method_positive(self): 561596Szelenkov@nginx.com assert self.get()['status'] == 200, 'GET' 571596Szelenkov@nginx.com assert self.post()['status'] == 404, 'POST' 581308Szelenkov@nginx.com 591308Szelenkov@nginx.com def test_routes_match_method_positive_many(self): 601308Szelenkov@nginx.com self.route_match({"method": ["GET", "POST"]}) 611308Szelenkov@nginx.com 621596Szelenkov@nginx.com assert self.get()['status'] == 200, 'GET' 631596Szelenkov@nginx.com assert self.post()['status'] == 200, 'POST' 641596Szelenkov@nginx.com assert self.delete()['status'] == 404, 'DELETE' 651308Szelenkov@nginx.com 661308Szelenkov@nginx.com def test_routes_match_method_negative(self): 671308Szelenkov@nginx.com self.route_match({"method": "!GET"}) 681308Szelenkov@nginx.com 691596Szelenkov@nginx.com assert self.get()['status'] == 404, 'GET' 701596Szelenkov@nginx.com assert self.post()['status'] == 200, 'POST' 711308Szelenkov@nginx.com 721308Szelenkov@nginx.com def test_routes_match_method_negative_many(self): 731308Szelenkov@nginx.com self.route_match({"method": ["!GET", "!POST"]}) 741308Szelenkov@nginx.com 751596Szelenkov@nginx.com assert self.get()['status'] == 404, 'GET' 761596Szelenkov@nginx.com assert self.post()['status'] == 404, 'POST' 771596Szelenkov@nginx.com assert self.delete()['status'] == 200, 'DELETE' 781308Szelenkov@nginx.com 791308Szelenkov@nginx.com def test_routes_match_method_wildcard_left(self): 801308Szelenkov@nginx.com self.route_match({"method": "*ET"}) 811308Szelenkov@nginx.com 821596Szelenkov@nginx.com assert self.get()['status'] == 200, 'GET' 831596Szelenkov@nginx.com assert self.post()['status'] == 404, 'POST' 841037Szelenkov@nginx.com 851308Szelenkov@nginx.com def test_routes_match_method_wildcard_right(self): 861308Szelenkov@nginx.com self.route_match({"method": "GE*"}) 871308Szelenkov@nginx.com 881596Szelenkov@nginx.com assert self.get()['status'] == 200, 'GET' 891596Szelenkov@nginx.com assert self.post()['status'] == 404, 'POST' 901308Szelenkov@nginx.com 911308Szelenkov@nginx.com def test_routes_match_method_wildcard_left_right(self): 921308Szelenkov@nginx.com self.route_match({"method": "*GET*"}) 931308Szelenkov@nginx.com 941596Szelenkov@nginx.com assert self.get()['status'] == 200, 'GET' 951596Szelenkov@nginx.com assert self.post()['status'] == 404, 'POST' 961308Szelenkov@nginx.com 971308Szelenkov@nginx.com def test_routes_match_method_wildcard(self): 981308Szelenkov@nginx.com self.route_match({"method": "*"}) 991308Szelenkov@nginx.com 1001596Szelenkov@nginx.com assert self.get()['status'] == 200, 'GET' 1011308Szelenkov@nginx.com 1021308Szelenkov@nginx.com def test_routes_match_invalid(self): 1031308Szelenkov@nginx.com self.route_match_invalid({"method": "**"}) 1041508Saxel.duch@nginx.com 1051508Saxel.duch@nginx.com def test_routes_match_valid(self): 1061508Saxel.duch@nginx.com self.route_match({"method": "blah*"}) 1071508Saxel.duch@nginx.com self.route_match({"host": "*blah*blah"}) 1081508Saxel.duch@nginx.com self.route_match({"host": "blah*blah*blah"}) 1091508Saxel.duch@nginx.com self.route_match({"host": "blah*blah*"}) 1101508Saxel.duch@nginx.com 1111508Saxel.duch@nginx.com def test_routes_match_empty_exact(self): 1121508Saxel.duch@nginx.com self.route_match({"uri": ""}) 1131596Szelenkov@nginx.com assert self.get()['status'] == 404 1141508Saxel.duch@nginx.com 1151508Saxel.duch@nginx.com self.route_match({"uri": "/"}) 1161596Szelenkov@nginx.com assert self.get()['status'] == 200 1171596Szelenkov@nginx.com assert self.get(url='/blah')['status'] == 404 1181508Saxel.duch@nginx.com 1191508Saxel.duch@nginx.com def test_routes_match_negative(self): 1201508Saxel.duch@nginx.com self.route_match({"uri": "!"}) 1211633Svbart@nginx.com assert self.get()['status'] == 200 1221633Svbart@nginx.com 1231633Svbart@nginx.com self.route_match({"uri": "!*"}) 1241596Szelenkov@nginx.com assert self.get()['status'] == 404 1251508Saxel.duch@nginx.com 1261508Saxel.duch@nginx.com self.route_match({"uri": "!/"}) 1271596Szelenkov@nginx.com assert self.get()['status'] == 404 1281596Szelenkov@nginx.com assert self.get(url='/blah')['status'] == 200 1291508Saxel.duch@nginx.com 1301508Saxel.duch@nginx.com self.route_match({"uri": "!*blah"}) 1311596Szelenkov@nginx.com assert self.get()['status'] == 200 1321596Szelenkov@nginx.com assert self.get(url='/bla')['status'] == 200 1331596Szelenkov@nginx.com assert self.get(url='/blah')['status'] == 404 1341596Szelenkov@nginx.com assert self.get(url='/blah1')['status'] == 200 1351508Saxel.duch@nginx.com 1361508Saxel.duch@nginx.com self.route_match({"uri": "!/blah*1*"}) 1371596Szelenkov@nginx.com assert self.get()['status'] == 200 1381596Szelenkov@nginx.com assert self.get(url='/blah')['status'] == 200 1391596Szelenkov@nginx.com assert self.get(url='/blah1')['status'] == 404 1401596Szelenkov@nginx.com assert self.get(url='/blah12')['status'] == 404 1411596Szelenkov@nginx.com assert self.get(url='/blah2')['status'] == 200 1421308Szelenkov@nginx.com 1431308Szelenkov@nginx.com def test_routes_match_wildcard_middle(self): 1441308Szelenkov@nginx.com self.route_match({"host": "ex*le"}) 1451308Szelenkov@nginx.com 1461308Szelenkov@nginx.com self.host('example', 200) 1471308Szelenkov@nginx.com self.host('www.example', 404) 1481308Szelenkov@nginx.com self.host('example.com', 404) 1491308Szelenkov@nginx.com self.host('exampl', 404) 1501037Szelenkov@nginx.com 151972Szelenkov@nginx.com def test_routes_match_method_case_insensitive(self): 1521308Szelenkov@nginx.com self.route_match({"method": "get"}) 153972Szelenkov@nginx.com 1541596Szelenkov@nginx.com assert self.get()['status'] == 200, 'GET' 155972Szelenkov@nginx.com 1561037Szelenkov@nginx.com def test_routes_match_wildcard_left_case_insensitive(self): 1571308Szelenkov@nginx.com self.route_match({"method": "*get"}) 1581596Szelenkov@nginx.com assert self.get()['status'] == 200, 'GET' 1591037Szelenkov@nginx.com 1601308Szelenkov@nginx.com self.route_match({"method": "*et"}) 1611596Szelenkov@nginx.com assert self.get()['status'] == 200, 'GET' 1621037Szelenkov@nginx.com 1631037Szelenkov@nginx.com def test_routes_match_wildcard_middle_case_insensitive(self): 1641308Szelenkov@nginx.com self.route_match({"method": "g*t"}) 1651037Szelenkov@nginx.com 1661596Szelenkov@nginx.com assert self.get()['status'] == 200, 'GET' 1671037Szelenkov@nginx.com 1681037Szelenkov@nginx.com def test_routes_match_wildcard_right_case_insensitive(self): 1691308Szelenkov@nginx.com self.route_match({"method": "get*"}) 1701596Szelenkov@nginx.com assert self.get()['status'] == 200, 'GET' 1711037Szelenkov@nginx.com 1721308Szelenkov@nginx.com self.route_match({"method": "ge*"}) 1731596Szelenkov@nginx.com assert self.get()['status'] == 200, 'GET' 1741037Szelenkov@nginx.com 1751037Szelenkov@nginx.com def test_routes_match_wildcard_substring_case_insensitive(self): 1761308Szelenkov@nginx.com self.route_match({"method": "*et*"}) 1771037Szelenkov@nginx.com 1781596Szelenkov@nginx.com assert self.get()['status'] == 200, 'GET' 1791037Szelenkov@nginx.com 1801037Szelenkov@nginx.com def test_routes_match_wildcard_left_case_sensitive(self): 1811308Szelenkov@nginx.com self.route_match({"uri": "*blah"}) 1821037Szelenkov@nginx.com 1831596Szelenkov@nginx.com assert self.get(url='/blah')['status'] == 200, '/blah' 1841596Szelenkov@nginx.com assert self.get(url='/BLAH')['status'] == 404, '/BLAH' 1851037Szelenkov@nginx.com 1861037Szelenkov@nginx.com def test_routes_match_wildcard_middle_case_sensitive(self): 1871308Szelenkov@nginx.com self.route_match({"uri": "/b*h"}) 1881037Szelenkov@nginx.com 1891596Szelenkov@nginx.com assert self.get(url='/blah')['status'] == 200, '/blah' 1901596Szelenkov@nginx.com assert self.get(url='/BLAH')['status'] == 404, '/BLAH' 1911037Szelenkov@nginx.com 1921510Saxel.duch@nginx.com def test_route_match_wildcards_ordered(self): 1931510Saxel.duch@nginx.com self.route_match({"uri": "/a*x*y*"}) 1941510Saxel.duch@nginx.com 1951596Szelenkov@nginx.com assert self.get(url='/axy')['status'] == 200, '/axy' 1961596Szelenkov@nginx.com assert self.get(url='/ayx')['status'] == 404, '/ayx' 1971510Saxel.duch@nginx.com 1981510Saxel.duch@nginx.com def test_route_match_wildcards_adjust_start(self): 1991510Saxel.duch@nginx.com self.route_match({"uri": "/bla*bla*"}) 2001510Saxel.duch@nginx.com 2011596Szelenkov@nginx.com assert self.get(url='/bla_foo')['status'] == 404, '/bla_foo' 2021510Saxel.duch@nginx.com 2031510Saxel.duch@nginx.com def test_route_match_wildcards_adjust_start_substr(self): 2041510Saxel.duch@nginx.com self.route_match({"uri": "*bla*bla*"}) 2051510Saxel.duch@nginx.com 2061596Szelenkov@nginx.com assert self.get(url='/bla_foo')['status'] == 404, '/bla_foo' 2071510Saxel.duch@nginx.com 2081510Saxel.duch@nginx.com def test_route_match_wildcards_adjust_end(self): 2091510Saxel.duch@nginx.com self.route_match({"uri": "/bla*bla"}) 2101510Saxel.duch@nginx.com 2111596Szelenkov@nginx.com assert self.get(url='/foo_bla')['status'] == 404, '/foo_bla' 2121510Saxel.duch@nginx.com 2131037Szelenkov@nginx.com def test_routes_match_wildcard_right_case_sensitive(self): 2141308Szelenkov@nginx.com self.route_match({"uri": "/bla*"}) 2151037Szelenkov@nginx.com 2161596Szelenkov@nginx.com assert self.get(url='/blah')['status'] == 200, '/blah' 2171596Szelenkov@nginx.com assert self.get(url='/BLAH')['status'] == 404, '/BLAH' 2181037Szelenkov@nginx.com 2191037Szelenkov@nginx.com def test_routes_match_wildcard_substring_case_sensitive(self): 2201308Szelenkov@nginx.com self.route_match({"uri": "*bla*"}) 2211037Szelenkov@nginx.com 2221596Szelenkov@nginx.com assert self.get(url='/blah')['status'] == 200, '/blah' 2231596Szelenkov@nginx.com assert self.get(url='/BLAH')['status'] == 404, '/BLAH' 2241037Szelenkov@nginx.com 2251508Saxel.duch@nginx.com def test_routes_match_many_wildcard_substrings_case_sensitive(self): 2261508Saxel.duch@nginx.com self.route_match({"uri": "*a*B*c*"}) 2271508Saxel.duch@nginx.com 2281596Szelenkov@nginx.com assert self.get(url='/blah-a-B-c-blah')['status'] == 200 2291596Szelenkov@nginx.com assert self.get(url='/a-B-c')['status'] == 200 2301596Szelenkov@nginx.com assert self.get(url='/aBc')['status'] == 200 2311596Szelenkov@nginx.com assert self.get(url='/aBCaBbc')['status'] == 200 2321596Szelenkov@nginx.com assert self.get(url='/ABc')['status'] == 404 2331508Saxel.duch@nginx.com 2341721Saxel.duch@nginx.com def test_routes_empty_regex(self): 2351807Szelenkov@nginx.com if not option.available['modules']['regex']: 2361807Szelenkov@nginx.com pytest.skip('requires regex') 2371807Szelenkov@nginx.com 2381848Szelenkov@nginx.com self.route_match({"uri": "~"}) 2391721Saxel.duch@nginx.com assert self.get(url='/')['status'] == 200, 'empty regexp' 2401721Saxel.duch@nginx.com assert self.get(url='/anything')['status'] == 200, '/anything' 2411721Saxel.duch@nginx.com 2421848Szelenkov@nginx.com self.route_match({"uri": "!~"}) 2431721Saxel.duch@nginx.com assert self.get(url='/')['status'] == 404, 'empty regexp 2' 2441721Saxel.duch@nginx.com assert self.get(url='/nothing')['status'] == 404, '/nothing' 2451721Saxel.duch@nginx.com 2461721Saxel.duch@nginx.com def test_routes_bad_regex(self): 2471807Szelenkov@nginx.com if not option.available['modules']['regex']: 2481807Szelenkov@nginx.com pytest.skip('requires regex') 2491807Szelenkov@nginx.com 2501721Saxel.duch@nginx.com assert 'error' in self.route( 2511721Saxel.duch@nginx.com {"match": {"uri": "~/bl[ah"}, "action": {"return": 200}} 2521721Saxel.duch@nginx.com ), 'bad regex' 2531721Saxel.duch@nginx.com 2541721Saxel.duch@nginx.com status = self.route( 2551721Saxel.duch@nginx.com {"match": {"uri": "~(?R)?z"}, "action": {"return": 200}} 2561721Saxel.duch@nginx.com ) 2571721Saxel.duch@nginx.com if 'error' not in status: 2581721Saxel.duch@nginx.com assert self.get(url='/nothing_z')['status'] == 500, '/nothing_z' 2591721Saxel.duch@nginx.com 2601721Saxel.duch@nginx.com status = self.route( 2611721Saxel.duch@nginx.com {"match": {"uri": "~((?1)?z)"}, "action": {"return": 200}} 2621721Saxel.duch@nginx.com ) 2631721Saxel.duch@nginx.com if 'error' not in status: 2641721Saxel.duch@nginx.com assert self.get(url='/nothing_z')['status'] == 500, '/nothing_z' 2651721Saxel.duch@nginx.com 2661721Saxel.duch@nginx.com def test_routes_match_regex_case_sensitive(self): 2671807Szelenkov@nginx.com if not option.available['modules']['regex']: 2681807Szelenkov@nginx.com pytest.skip('requires regex') 2691807Szelenkov@nginx.com 2701721Saxel.duch@nginx.com self.route_match({"uri": "~/bl[ah]"}) 2711721Saxel.duch@nginx.com 2721721Saxel.duch@nginx.com assert self.get(url='/rlah')['status'] == 404, '/rlah' 2731721Saxel.duch@nginx.com assert self.get(url='/blah')['status'] == 200, '/blah' 2741721Saxel.duch@nginx.com assert self.get(url='/blh')['status'] == 200, '/blh' 2751721Saxel.duch@nginx.com assert self.get(url='/BLAH')['status'] == 404, '/BLAH' 2761721Saxel.duch@nginx.com 2771721Saxel.duch@nginx.com def test_routes_match_regex_negative_case_sensitive(self): 2781807Szelenkov@nginx.com if not option.available['modules']['regex']: 2791807Szelenkov@nginx.com pytest.skip('requires regex') 2801807Szelenkov@nginx.com 2811721Saxel.duch@nginx.com self.route_match({"uri": "!~/bl[ah]"}) 2821721Saxel.duch@nginx.com 2831721Saxel.duch@nginx.com assert self.get(url='/rlah')['status'] == 200, '/rlah' 2841721Saxel.duch@nginx.com assert self.get(url='/blah')['status'] == 404, '/blah' 2851721Saxel.duch@nginx.com assert self.get(url='/blh')['status'] == 404, '/blh' 2861721Saxel.duch@nginx.com assert self.get(url='/BLAH')['status'] == 200, '/BLAH' 2871721Saxel.duch@nginx.com 2881478Szelenkov@nginx.com def test_routes_pass_encode(self): 2891478Szelenkov@nginx.com def check_pass(path, name): 2901596Szelenkov@nginx.com assert 'success' in self.conf( 2911596Szelenkov@nginx.com { 2921596Szelenkov@nginx.com "listeners": {"*:7080": {"pass": "applications/" + path}}, 2931596Szelenkov@nginx.com "applications": { 2941596Szelenkov@nginx.com name: { 2952055Szelenkov@nginx.com "type": self.get_application_type(), 2961596Szelenkov@nginx.com "processes": {"spare": 0}, 2971596Szelenkov@nginx.com "path": option.test_dir + '/python/empty', 2981596Szelenkov@nginx.com "working_directory": option.test_dir 2991596Szelenkov@nginx.com + '/python/empty', 3001596Szelenkov@nginx.com "module": "wsgi", 3011596Szelenkov@nginx.com } 3021596Szelenkov@nginx.com }, 3031596Szelenkov@nginx.com } 3041478Szelenkov@nginx.com ) 3051478Szelenkov@nginx.com 3061596Szelenkov@nginx.com assert self.get()['status'] == 200 3071478Szelenkov@nginx.com 3081478Szelenkov@nginx.com check_pass("%25", "%") 3091478Szelenkov@nginx.com check_pass("blah%2Fblah", "blah/blah") 3101478Szelenkov@nginx.com check_pass("%2Fblah%2F%2Fblah%2F", "/blah//blah/") 3111478Szelenkov@nginx.com check_pass("%20blah%252Fblah%7E", " blah%2Fblah~") 3121478Szelenkov@nginx.com 3131478Szelenkov@nginx.com def check_pass_error(path, name): 3141596Szelenkov@nginx.com assert 'error' in self.conf( 3151596Szelenkov@nginx.com { 3161596Szelenkov@nginx.com "listeners": {"*:7080": {"pass": "applications/" + path}}, 3171596Szelenkov@nginx.com "applications": { 3181596Szelenkov@nginx.com name: { 3192055Szelenkov@nginx.com "type": self.get_application_type(), 3201596Szelenkov@nginx.com "processes": {"spare": 0}, 3211596Szelenkov@nginx.com "path": option.test_dir + '/python/empty', 3221596Szelenkov@nginx.com "working_directory": option.test_dir 3231596Szelenkov@nginx.com + '/python/empty', 3241596Szelenkov@nginx.com "module": "wsgi", 3251596Szelenkov@nginx.com } 3261596Szelenkov@nginx.com }, 3271596Szelenkov@nginx.com } 3281478Szelenkov@nginx.com ) 3291478Szelenkov@nginx.com 3301478Szelenkov@nginx.com check_pass_error("%", "%") 3311478Szelenkov@nginx.com check_pass_error("%1", "%1") 3321478Szelenkov@nginx.com 333972Szelenkov@nginx.com def test_routes_absent(self): 3341775Szelenkov@nginx.com assert 'success' in self.conf( 3351017Szelenkov@nginx.com { 3361017Szelenkov@nginx.com "listeners": {"*:7081": {"pass": "applications/empty"}}, 3371017Szelenkov@nginx.com "applications": { 3381017Szelenkov@nginx.com "empty": { 3392055Szelenkov@nginx.com "type": self.get_application_type(), 3401017Szelenkov@nginx.com "processes": {"spare": 0}, 3411596Szelenkov@nginx.com "path": option.test_dir + '/python/empty', 3421848Szelenkov@nginx.com "working_directory": option.test_dir + '/python/empty', 3431017Szelenkov@nginx.com "module": "wsgi", 3441017Szelenkov@nginx.com } 3451017Szelenkov@nginx.com }, 346972Szelenkov@nginx.com } 3471017Szelenkov@nginx.com ) 348972Szelenkov@nginx.com 3491596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 200, 'routes absent' 350972Szelenkov@nginx.com 351972Szelenkov@nginx.com def test_routes_pass_invalid(self): 3521596Szelenkov@nginx.com assert 'error' in self.conf( 3531596Szelenkov@nginx.com {"pass": "routes/blah"}, 'listeners/*:7080' 3541596Szelenkov@nginx.com ), 'routes invalid' 355972Szelenkov@nginx.com 356972Szelenkov@nginx.com def test_route_empty(self): 3571596Szelenkov@nginx.com assert 'success' in self.conf( 3581596Szelenkov@nginx.com { 3591596Szelenkov@nginx.com "listeners": {"*:7080": {"pass": "routes/main"}}, 3601596Szelenkov@nginx.com "routes": {"main": []}, 3611596Szelenkov@nginx.com "applications": {}, 3621596Szelenkov@nginx.com } 3631596Szelenkov@nginx.com ), 'route empty configure' 364972Szelenkov@nginx.com 3651596Szelenkov@nginx.com assert self.get()['status'] == 404, 'route empty' 366972Szelenkov@nginx.com 367972Szelenkov@nginx.com def test_routes_route_empty(self): 3681596Szelenkov@nginx.com assert 'success' in self.conf( 3691596Szelenkov@nginx.com {}, 'listeners' 3701596Szelenkov@nginx.com ), 'routes empty listeners configure' 371972Szelenkov@nginx.com 3721596Szelenkov@nginx.com assert 'success' in self.conf({}, 'routes'), 'routes empty configure' 373972Szelenkov@nginx.com 374972Szelenkov@nginx.com def test_routes_route_match_absent(self): 3751596Szelenkov@nginx.com assert 'success' in self.conf( 3761596Szelenkov@nginx.com [{"action": {"return": 200}}], 'routes' 3771596Szelenkov@nginx.com ), 'route match absent configure' 378972Szelenkov@nginx.com 3791596Szelenkov@nginx.com assert self.get()['status'] == 200, 'route match absent' 380972Szelenkov@nginx.com 3811736Szelenkov@nginx.com def test_routes_route_action_absent(self, skip_alert): 3821596Szelenkov@nginx.com skip_alert(r'failed to apply new conf') 383972Szelenkov@nginx.com 3841596Szelenkov@nginx.com assert 'error' in self.conf( 3851596Szelenkov@nginx.com [{"match": {"method": "GET"}}], 'routes' 3861596Szelenkov@nginx.com ), 'route pass absent configure' 387972Szelenkov@nginx.com 3881597Shongzhidao@gmail.com def test_routes_route_pass(self): 3891597Shongzhidao@gmail.com assert 'success' in self.conf( 3901597Shongzhidao@gmail.com { 3911597Shongzhidao@gmail.com "applications": { 3921597Shongzhidao@gmail.com "app": { 3932055Szelenkov@nginx.com "type": self.get_application_type(), 3941597Shongzhidao@gmail.com "processes": {"spare": 0}, 3951597Shongzhidao@gmail.com "path": "/app", 3961597Shongzhidao@gmail.com "module": "wsgi", 3971597Shongzhidao@gmail.com } 3981597Shongzhidao@gmail.com }, 3991597Shongzhidao@gmail.com "upstreams": { 4001597Shongzhidao@gmail.com "one": { 4011597Shongzhidao@gmail.com "servers": { 4021597Shongzhidao@gmail.com "127.0.0.1:7081": {}, 4031597Shongzhidao@gmail.com "127.0.0.1:7082": {}, 4041597Shongzhidao@gmail.com }, 4051597Shongzhidao@gmail.com }, 4061597Shongzhidao@gmail.com "two": { 4071597Shongzhidao@gmail.com "servers": { 4081597Shongzhidao@gmail.com "127.0.0.1:7081": {}, 4091597Shongzhidao@gmail.com "127.0.0.1:7082": {}, 4101597Shongzhidao@gmail.com }, 4111597Shongzhidao@gmail.com }, 4121597Shongzhidao@gmail.com }, 4131597Shongzhidao@gmail.com } 4141597Shongzhidao@gmail.com ) 4151597Shongzhidao@gmail.com 4161597Shongzhidao@gmail.com assert 'success' in self.conf( 4171597Shongzhidao@gmail.com [{"action": {"pass": "routes"}}], 'routes' 4181597Shongzhidao@gmail.com ) 4191597Shongzhidao@gmail.com assert 'success' in self.conf( 4201597Shongzhidao@gmail.com [{"action": {"pass": "applications/app"}}], 'routes' 4211597Shongzhidao@gmail.com ) 4221597Shongzhidao@gmail.com assert 'success' in self.conf( 4231597Shongzhidao@gmail.com [{"action": {"pass": "upstreams/one"}}], 'routes' 4241597Shongzhidao@gmail.com ) 4251597Shongzhidao@gmail.com 426972Szelenkov@nginx.com def test_routes_route_pass_absent(self): 4271596Szelenkov@nginx.com assert 'error' in self.conf( 4281596Szelenkov@nginx.com [{"match": {"method": "GET"}, "action": {}}], 'routes' 4291596Szelenkov@nginx.com ), 'route pass absent configure' 430972Szelenkov@nginx.com 4311597Shongzhidao@gmail.com def test_routes_route_pass_invalid(self): 4321597Shongzhidao@gmail.com assert 'success' in self.conf( 4331597Shongzhidao@gmail.com { 4341597Shongzhidao@gmail.com "applications": { 4351597Shongzhidao@gmail.com "app": { 4362055Szelenkov@nginx.com "type": self.get_application_type(), 4371597Shongzhidao@gmail.com "processes": {"spare": 0}, 4381597Shongzhidao@gmail.com "path": "/app", 4391597Shongzhidao@gmail.com "module": "wsgi", 4401597Shongzhidao@gmail.com } 4411597Shongzhidao@gmail.com }, 4421597Shongzhidao@gmail.com "upstreams": { 4431597Shongzhidao@gmail.com "one": { 4441597Shongzhidao@gmail.com "servers": { 4451597Shongzhidao@gmail.com "127.0.0.1:7081": {}, 4461597Shongzhidao@gmail.com "127.0.0.1:7082": {}, 4471597Shongzhidao@gmail.com }, 4481597Shongzhidao@gmail.com }, 4491597Shongzhidao@gmail.com "two": { 4501597Shongzhidao@gmail.com "servers": { 4511597Shongzhidao@gmail.com "127.0.0.1:7081": {}, 4521597Shongzhidao@gmail.com "127.0.0.1:7082": {}, 4531597Shongzhidao@gmail.com }, 4541597Shongzhidao@gmail.com }, 4551597Shongzhidao@gmail.com }, 4561597Shongzhidao@gmail.com } 4571597Shongzhidao@gmail.com ) 4581597Shongzhidao@gmail.com 4591597Shongzhidao@gmail.com assert 'error' in self.conf( 4601597Shongzhidao@gmail.com [{"action": {"pass": "blah"}}], 'routes' 4611597Shongzhidao@gmail.com ), 'route pass invalid' 4621597Shongzhidao@gmail.com assert 'error' in self.conf( 4631597Shongzhidao@gmail.com [{"action": {"pass": "routes/blah"}}], 'routes' 4641597Shongzhidao@gmail.com ), 'route pass routes invalid' 4651597Shongzhidao@gmail.com assert 'error' in self.conf( 4661597Shongzhidao@gmail.com [{"action": {"pass": "applications/blah"}}], 'routes' 4671597Shongzhidao@gmail.com ), 'route pass applications invalid' 4681597Shongzhidao@gmail.com assert 'error' in self.conf( 4691597Shongzhidao@gmail.com [{"action": {"pass": "upstreams/blah"}}], 'routes' 4701597Shongzhidao@gmail.com ), 'route pass upstreams invalid' 4711597Shongzhidao@gmail.com 4721654Szelenkov@nginx.com def test_routes_action_unique(self, temp_dir): 4731596Szelenkov@nginx.com assert 'success' in self.conf( 4741596Szelenkov@nginx.com { 4751596Szelenkov@nginx.com "listeners": { 4761596Szelenkov@nginx.com "*:7080": {"pass": "routes"}, 4771596Szelenkov@nginx.com "*:7081": {"pass": "applications/app"}, 4781596Szelenkov@nginx.com }, 4791596Szelenkov@nginx.com "routes": [{"action": {"proxy": "http://127.0.0.1:7081"}}], 4801596Szelenkov@nginx.com "applications": { 4811596Szelenkov@nginx.com "app": { 4822055Szelenkov@nginx.com "type": self.get_application_type(), 4831596Szelenkov@nginx.com "processes": {"spare": 0}, 4841596Szelenkov@nginx.com "path": "/app", 4851596Szelenkov@nginx.com "module": "wsgi", 4861596Szelenkov@nginx.com } 4871596Szelenkov@nginx.com }, 4881596Szelenkov@nginx.com } 4891379Szelenkov@nginx.com ) 4901379Szelenkov@nginx.com 4911596Szelenkov@nginx.com assert 'error' in self.conf( 4921654Szelenkov@nginx.com {"proxy": "http://127.0.0.1:7081", "share": temp_dir}, 4931596Szelenkov@nginx.com 'routes/0/action', 4941596Szelenkov@nginx.com ), 'proxy share' 4951596Szelenkov@nginx.com assert 'error' in self.conf( 496*2073Szelenkov@nginx.com { 497*2073Szelenkov@nginx.com "proxy": "http://127.0.0.1:7081", 498*2073Szelenkov@nginx.com "pass": "applications/app", 499*2073Szelenkov@nginx.com }, 5001596Szelenkov@nginx.com 'routes/0/action', 5011596Szelenkov@nginx.com ), 'proxy pass' 5021596Szelenkov@nginx.com assert 'error' in self.conf( 503*2073Szelenkov@nginx.com {"share": temp_dir, "pass": "applications/app"}, 504*2073Szelenkov@nginx.com 'routes/0/action', 5051596Szelenkov@nginx.com ), 'share pass' 5061379Szelenkov@nginx.com 507972Szelenkov@nginx.com def test_routes_rules_two(self): 5081596Szelenkov@nginx.com assert 'success' in self.conf( 5091596Szelenkov@nginx.com [ 5101596Szelenkov@nginx.com {"match": {"method": "GET"}, "action": {"return": 200}}, 5111596Szelenkov@nginx.com {"match": {"method": "POST"}, "action": {"return": 201}}, 5121596Szelenkov@nginx.com ], 5131596Szelenkov@nginx.com 'routes', 5141596Szelenkov@nginx.com ), 'rules two configure' 515972Szelenkov@nginx.com 5161596Szelenkov@nginx.com assert self.get()['status'] == 200, 'rules two match first' 5171596Szelenkov@nginx.com assert self.post()['status'] == 201, 'rules two match second' 518972Szelenkov@nginx.com 519972Szelenkov@nginx.com def test_routes_two(self): 5201596Szelenkov@nginx.com assert 'success' in self.conf( 5211596Szelenkov@nginx.com { 5221596Szelenkov@nginx.com "listeners": {"*:7080": {"pass": "routes/first"}}, 5231596Szelenkov@nginx.com "routes": { 5241596Szelenkov@nginx.com "first": [ 5251596Szelenkov@nginx.com { 5261596Szelenkov@nginx.com "match": {"method": "GET"}, 5271596Szelenkov@nginx.com "action": {"pass": "routes/second"}, 5281596Szelenkov@nginx.com } 5291596Szelenkov@nginx.com ], 5301596Szelenkov@nginx.com "second": [ 5311596Szelenkov@nginx.com { 5321596Szelenkov@nginx.com "match": {"host": "localhost"}, 5331596Szelenkov@nginx.com "action": {"return": 200}, 5341596Szelenkov@nginx.com } 5351596Szelenkov@nginx.com ], 5361596Szelenkov@nginx.com }, 5371596Szelenkov@nginx.com "applications": {}, 5381596Szelenkov@nginx.com } 5391596Szelenkov@nginx.com ), 'routes two configure' 540972Szelenkov@nginx.com 5411596Szelenkov@nginx.com assert self.get()['status'] == 200, 'routes two' 542972Szelenkov@nginx.com 543972Szelenkov@nginx.com def test_routes_match_host_positive(self): 5441308Szelenkov@nginx.com self.route_match({"host": "localhost"}) 545972Szelenkov@nginx.com 5461596Szelenkov@nginx.com assert self.get()['status'] == 200, 'localhost' 5471308Szelenkov@nginx.com self.host('localhost.', 200) 5481308Szelenkov@nginx.com self.host('localhost.', 200) 5491308Szelenkov@nginx.com self.host('.localhost', 404) 5501308Szelenkov@nginx.com self.host('www.localhost', 404) 5511308Szelenkov@nginx.com self.host('localhost1', 404) 552972Szelenkov@nginx.com 5531596Szelenkov@nginx.com @pytest.mark.skip('not yet') 5541065Szelenkov@nginx.com def test_routes_match_host_absent(self): 5551308Szelenkov@nginx.com self.route_match({"host": "localhost"}) 5561065Szelenkov@nginx.com 5571596Szelenkov@nginx.com assert ( 5581596Szelenkov@nginx.com self.get(headers={'Connection': 'close'})['status'] == 400 5591596Szelenkov@nginx.com ), 'match host absent' 5601065Szelenkov@nginx.com 561972Szelenkov@nginx.com def test_routes_match_host_ipv4(self): 5621308Szelenkov@nginx.com self.route_match({"host": "127.0.0.1"}) 563972Szelenkov@nginx.com 5641308Szelenkov@nginx.com self.host('127.0.0.1', 200) 5651308Szelenkov@nginx.com self.host('127.0.0.1:7080', 200) 566972Szelenkov@nginx.com 567972Szelenkov@nginx.com def test_routes_match_host_ipv6(self): 5681308Szelenkov@nginx.com self.route_match({"host": "[::1]"}) 569972Szelenkov@nginx.com 5701308Szelenkov@nginx.com self.host('[::1]', 200) 5711308Szelenkov@nginx.com self.host('[::1]:7080', 200) 572972Szelenkov@nginx.com 573972Szelenkov@nginx.com def test_routes_match_host_positive_many(self): 5741308Szelenkov@nginx.com self.route_match({"host": ["localhost", "example.com"]}) 575972Szelenkov@nginx.com 5761596Szelenkov@nginx.com assert self.get()['status'] == 200, 'localhost' 5771308Szelenkov@nginx.com self.host('example.com', 200) 578972Szelenkov@nginx.com 579972Szelenkov@nginx.com def test_routes_match_host_positive_and_negative(self): 5801308Szelenkov@nginx.com self.route_match({"host": ["*example.com", "!www.example.com"]}) 581972Szelenkov@nginx.com 5821596Szelenkov@nginx.com assert self.get()['status'] == 404, 'localhost' 5831308Szelenkov@nginx.com self.host('example.com', 200) 5841308Szelenkov@nginx.com self.host('www.example.com', 404) 5851308Szelenkov@nginx.com self.host('!www.example.com', 200) 586972Szelenkov@nginx.com 587972Szelenkov@nginx.com def test_routes_match_host_positive_and_negative_wildcard(self): 5881308Szelenkov@nginx.com self.route_match({"host": ["*example*", "!www.example*"]}) 589972Szelenkov@nginx.com 5901308Szelenkov@nginx.com self.host('example.com', 200) 5911308Szelenkov@nginx.com self.host('www.example.com', 404) 592972Szelenkov@nginx.com 593972Szelenkov@nginx.com def test_routes_match_host_case_insensitive(self): 5941308Szelenkov@nginx.com self.route_match({"host": "Example.com"}) 595972Szelenkov@nginx.com 5961308Szelenkov@nginx.com self.host('example.com', 200) 5971308Szelenkov@nginx.com self.host('EXAMPLE.COM', 200) 598972Szelenkov@nginx.com 599972Szelenkov@nginx.com def test_routes_match_host_port(self): 6001308Szelenkov@nginx.com self.route_match({"host": "example.com"}) 601972Szelenkov@nginx.com 6021308Szelenkov@nginx.com self.host('example.com:7080', 200) 603972Szelenkov@nginx.com 6041053Szelenkov@nginx.com def test_routes_match_host_empty(self): 6051308Szelenkov@nginx.com self.route_match({"host": ""}) 6061053Szelenkov@nginx.com 6071308Szelenkov@nginx.com self.host('', 200) 6081596Szelenkov@nginx.com assert ( 6091596Szelenkov@nginx.com self.get(http_10=True, headers={})['status'] == 200 6101596Szelenkov@nginx.com ), 'match host empty 2' 6111596Szelenkov@nginx.com assert self.get()['status'] == 404, 'match host empty 3' 6121053Szelenkov@nginx.com 613972Szelenkov@nginx.com def test_routes_match_uri_positive(self): 6141308Szelenkov@nginx.com self.route_match({"uri": ["/blah", "/slash/"]}) 615972Szelenkov@nginx.com 6161596Szelenkov@nginx.com assert self.get()['status'] == 404, '/' 6171596Szelenkov@nginx.com assert self.get(url='/blah')['status'] == 200, '/blah' 6181596Szelenkov@nginx.com assert self.get(url='/blah#foo')['status'] == 200, '/blah#foo' 6191596Szelenkov@nginx.com assert self.get(url='/blah?var')['status'] == 200, '/blah?var' 6201596Szelenkov@nginx.com assert self.get(url='//blah')['status'] == 200, '//blah' 6211596Szelenkov@nginx.com assert self.get(url='/slash/foo/../')['status'] == 200, 'relative' 6221596Szelenkov@nginx.com assert self.get(url='/slash/./')['status'] == 200, '/slash/./' 6231596Szelenkov@nginx.com assert self.get(url='/slash//.//')['status'] == 200, 'adjacent slashes' 6241596Szelenkov@nginx.com assert self.get(url='/%')['status'] == 400, 'percent' 6251596Szelenkov@nginx.com assert self.get(url='/%1')['status'] == 400, 'percent digit' 6261596Szelenkov@nginx.com assert self.get(url='/%A')['status'] == 400, 'percent letter' 6271596Szelenkov@nginx.com assert self.get(url='/slash/.?args')['status'] == 200, 'dot args' 6281596Szelenkov@nginx.com assert self.get(url='/slash/.#frag')['status'] == 200, 'dot frag' 6291596Szelenkov@nginx.com assert ( 6301596Szelenkov@nginx.com self.get(url='/slash/foo/..?args')['status'] == 200 6311596Szelenkov@nginx.com ), 'dot dot args' 6321596Szelenkov@nginx.com assert ( 6331596Szelenkov@nginx.com self.get(url='/slash/foo/..#frag')['status'] == 200 6341596Szelenkov@nginx.com ), 'dot dot frag' 6351596Szelenkov@nginx.com assert self.get(url='/slash/.')['status'] == 200, 'trailing dot' 6361596Szelenkov@nginx.com assert ( 6371596Szelenkov@nginx.com self.get(url='/slash/foo/..')['status'] == 200 6381596Szelenkov@nginx.com ), 'trailing dot dot' 639972Szelenkov@nginx.com 640972Szelenkov@nginx.com def test_routes_match_uri_case_sensitive(self): 6411308Szelenkov@nginx.com self.route_match({"uri": "/BLAH"}) 6421308Szelenkov@nginx.com 6431596Szelenkov@nginx.com assert self.get(url='/blah')['status'] == 404, '/blah' 6441596Szelenkov@nginx.com assert self.get(url='/BlaH')['status'] == 404, '/BlaH' 6451596Szelenkov@nginx.com assert self.get(url='/BLAH')['status'] == 200, '/BLAH' 6461308Szelenkov@nginx.com 6471308Szelenkov@nginx.com def test_routes_match_uri_normalize(self): 6481308Szelenkov@nginx.com self.route_match({"uri": "/blah"}) 649972Szelenkov@nginx.com 6501596Szelenkov@nginx.com assert self.get(url='/%62%6c%61%68')['status'] == 200, 'normalize' 651972Szelenkov@nginx.com 6521053Szelenkov@nginx.com def test_routes_match_empty_array(self): 6531308Szelenkov@nginx.com self.route_match({"uri": []}) 6541053Szelenkov@nginx.com 6551596Szelenkov@nginx.com assert self.get(url='/blah')['status'] == 200, 'empty array' 6561053Szelenkov@nginx.com 6571053Szelenkov@nginx.com def test_routes_reconfigure(self): 6581596Szelenkov@nginx.com assert 'success' in self.conf([], 'routes'), 'redefine' 6591596Szelenkov@nginx.com assert self.get()['status'] == 404, 'redefine request' 6601053Szelenkov@nginx.com 6611596Szelenkov@nginx.com assert 'success' in self.conf( 6621596Szelenkov@nginx.com [{"action": {"return": 200}}], 'routes' 6631596Szelenkov@nginx.com ), 'redefine 2' 6641596Szelenkov@nginx.com assert self.get()['status'] == 200, 'redefine request 2' 6651596Szelenkov@nginx.com 6661596Szelenkov@nginx.com assert 'success' in self.conf([], 'routes'), 'redefine 3' 6671596Szelenkov@nginx.com assert self.get()['status'] == 404, 'redefine request 3' 6681053Szelenkov@nginx.com 6691596Szelenkov@nginx.com assert 'success' in self.conf( 6701596Szelenkov@nginx.com { 6711596Szelenkov@nginx.com "listeners": {"*:7080": {"pass": "routes/main"}}, 6721596Szelenkov@nginx.com "routes": {"main": [{"action": {"return": 200}}]}, 6731596Szelenkov@nginx.com "applications": {}, 6741596Szelenkov@nginx.com } 6751596Szelenkov@nginx.com ), 'redefine 4' 6761596Szelenkov@nginx.com assert self.get()['status'] == 200, 'redefine request 4' 6771053Szelenkov@nginx.com 6781596Szelenkov@nginx.com assert 'success' in self.conf_delete('routes/main/0'), 'redefine 5' 6791596Szelenkov@nginx.com assert self.get()['status'] == 404, 'redefine request 5' 6801053Szelenkov@nginx.com 6811596Szelenkov@nginx.com assert 'success' in self.conf_post( 6821596Szelenkov@nginx.com {"action": {"return": 200}}, 'routes/main' 6831596Szelenkov@nginx.com ), 'redefine 6' 6841596Szelenkov@nginx.com assert self.get()['status'] == 200, 'redefine request 6' 6851063Szelenkov@nginx.com 6861596Szelenkov@nginx.com assert 'error' in self.conf( 6871596Szelenkov@nginx.com {"action": {"return": 200}}, 'routes/main/2' 6881596Szelenkov@nginx.com ), 'redefine 7' 6891596Szelenkov@nginx.com assert 'success' in self.conf( 6901596Szelenkov@nginx.com {"action": {"return": 201}}, 'routes/main/1' 6911596Szelenkov@nginx.com ), 'redefine 8' 6921596Szelenkov@nginx.com 6931596Szelenkov@nginx.com assert len(self.conf_get('routes/main')) == 2, 'redefine conf 8' 6941596Szelenkov@nginx.com assert self.get()['status'] == 200, 'redefine request 8' 6951063Szelenkov@nginx.com 6961053Szelenkov@nginx.com def test_routes_edit(self): 6971308Szelenkov@nginx.com self.route_match({"method": "GET"}) 6981053Szelenkov@nginx.com 6991596Szelenkov@nginx.com assert self.get()['status'] == 200, 'routes edit GET' 7001596Szelenkov@nginx.com assert self.post()['status'] == 404, 'routes edit POST' 7011053Szelenkov@nginx.com 7021596Szelenkov@nginx.com assert 'success' in self.conf_post( 703*2073Szelenkov@nginx.com {"match": {"method": "POST"}, "action": {"return": 200}}, 704*2073Szelenkov@nginx.com 'routes', 7051596Szelenkov@nginx.com ), 'routes edit configure 2' 7061596Szelenkov@nginx.com assert 'GET' == self.conf_get( 7071596Szelenkov@nginx.com 'routes/0/match/method' 7081596Szelenkov@nginx.com ), 'routes edit configure 2 check' 7091596Szelenkov@nginx.com assert 'POST' == self.conf_get( 7101596Szelenkov@nginx.com 'routes/1/match/method' 7111596Szelenkov@nginx.com ), 'routes edit configure 2 check 2' 7121053Szelenkov@nginx.com 7131596Szelenkov@nginx.com assert self.get()['status'] == 200, 'routes edit GET 2' 7141596Szelenkov@nginx.com assert self.post()['status'] == 200, 'routes edit POST 2' 7151053Szelenkov@nginx.com 7161596Szelenkov@nginx.com assert 'success' in self.conf_delete( 7171596Szelenkov@nginx.com 'routes/0' 7181596Szelenkov@nginx.com ), 'routes edit configure 3' 7191053Szelenkov@nginx.com 7201596Szelenkov@nginx.com assert self.get()['status'] == 404, 'routes edit GET 3' 7211596Szelenkov@nginx.com assert self.post()['status'] == 200, 'routes edit POST 3' 7221053Szelenkov@nginx.com 7231596Szelenkov@nginx.com assert 'error' in self.conf_delete( 7241596Szelenkov@nginx.com 'routes/1' 7251596Szelenkov@nginx.com ), 'routes edit configure invalid' 7261596Szelenkov@nginx.com assert 'error' in self.conf_delete( 7271596Szelenkov@nginx.com 'routes/-1' 7281596Szelenkov@nginx.com ), 'routes edit configure invalid 2' 7291596Szelenkov@nginx.com assert 'error' in self.conf_delete( 7301596Szelenkov@nginx.com 'routes/blah' 7311596Szelenkov@nginx.com ), 'routes edit configure invalid 3' 7321053Szelenkov@nginx.com 7331596Szelenkov@nginx.com assert self.get()['status'] == 404, 'routes edit GET 4' 7341596Szelenkov@nginx.com assert self.post()['status'] == 200, 'routes edit POST 4' 7351053Szelenkov@nginx.com 7361596Szelenkov@nginx.com assert 'success' in self.conf_delete( 7371596Szelenkov@nginx.com 'routes/0' 7381596Szelenkov@nginx.com ), 'routes edit configure 5' 7391053Szelenkov@nginx.com 7401596Szelenkov@nginx.com assert self.get()['status'] == 404, 'routes edit GET 5' 7411596Szelenkov@nginx.com assert self.post()['status'] == 404, 'routes edit POST 5' 7421053Szelenkov@nginx.com 7431596Szelenkov@nginx.com assert 'success' in self.conf_post( 744*2073Szelenkov@nginx.com {"match": {"method": "POST"}, "action": {"return": 200}}, 745*2073Szelenkov@nginx.com 'routes', 7461596Szelenkov@nginx.com ), 'routes edit configure 6' 7471053Szelenkov@nginx.com 7481596Szelenkov@nginx.com assert self.get()['status'] == 404, 'routes edit GET 6' 7491596Szelenkov@nginx.com assert self.post()['status'] == 200, 'routes edit POST 6' 7501053Szelenkov@nginx.com 7511596Szelenkov@nginx.com assert 'success' in self.conf( 7521596Szelenkov@nginx.com { 7531596Szelenkov@nginx.com "listeners": {"*:7080": {"pass": "routes/main"}}, 7541596Szelenkov@nginx.com "routes": {"main": [{"action": {"return": 200}}]}, 7551596Szelenkov@nginx.com "applications": {}, 7561596Szelenkov@nginx.com } 7571596Szelenkov@nginx.com ), 'route edit configure 7' 7581053Szelenkov@nginx.com 7591596Szelenkov@nginx.com assert 'error' in self.conf_delete( 7601596Szelenkov@nginx.com 'routes/0' 7611596Szelenkov@nginx.com ), 'routes edit configure invalid 4' 7621596Szelenkov@nginx.com assert 'error' in self.conf_delete( 7631596Szelenkov@nginx.com 'routes/main' 7641596Szelenkov@nginx.com ), 'routes edit configure invalid 5' 7651053Szelenkov@nginx.com 7661596Szelenkov@nginx.com assert self.get()['status'] == 200, 'routes edit GET 7' 7671053Szelenkov@nginx.com 7681596Szelenkov@nginx.com assert 'success' in self.conf_delete( 7691596Szelenkov@nginx.com 'listeners/*:7080' 7701596Szelenkov@nginx.com ), 'route edit configure 8' 7711596Szelenkov@nginx.com assert 'success' in self.conf_delete( 7721596Szelenkov@nginx.com 'routes/main' 7731596Szelenkov@nginx.com ), 'route edit configure 9' 7741053Szelenkov@nginx.com 7751736Szelenkov@nginx.com def test_match_edit(self, skip_alert): 7761596Szelenkov@nginx.com skip_alert(r'failed to apply new conf') 7771053Szelenkov@nginx.com 7781308Szelenkov@nginx.com self.route_match({"method": ["GET", "POST"]}) 7791053Szelenkov@nginx.com 7801596Szelenkov@nginx.com assert self.get()['status'] == 200, 'match edit GET' 7811596Szelenkov@nginx.com assert self.post()['status'] == 200, 'match edit POST' 7821596Szelenkov@nginx.com assert self.put()['status'] == 404, 'match edit PUT' 7831053Szelenkov@nginx.com 7841596Szelenkov@nginx.com assert 'success' in self.conf_post( 7851596Szelenkov@nginx.com '\"PUT\"', 'routes/0/match/method' 7861596Szelenkov@nginx.com ), 'match edit configure 2' 7871596Szelenkov@nginx.com assert ['GET', 'POST', 'PUT'] == self.conf_get( 7881596Szelenkov@nginx.com 'routes/0/match/method' 7891596Szelenkov@nginx.com ), 'match edit configure 2 check' 7901053Szelenkov@nginx.com 7911596Szelenkov@nginx.com assert self.get()['status'] == 200, 'match edit GET 2' 7921596Szelenkov@nginx.com assert self.post()['status'] == 200, 'match edit POST 2' 7931596Szelenkov@nginx.com assert self.put()['status'] == 200, 'match edit PUT 2' 7941053Szelenkov@nginx.com 7951596Szelenkov@nginx.com assert 'success' in self.conf_delete( 7961596Szelenkov@nginx.com 'routes/0/match/method/1' 7971596Szelenkov@nginx.com ), 'match edit configure 3' 7981596Szelenkov@nginx.com assert ['GET', 'PUT'] == self.conf_get( 7991596Szelenkov@nginx.com 'routes/0/match/method' 8001596Szelenkov@nginx.com ), 'match edit configure 3 check' 8011053Szelenkov@nginx.com 8021596Szelenkov@nginx.com assert self.get()['status'] == 200, 'match edit GET 3' 8031596Szelenkov@nginx.com assert self.post()['status'] == 404, 'match edit POST 3' 8041596Szelenkov@nginx.com assert self.put()['status'] == 200, 'match edit PUT 3' 8051053Szelenkov@nginx.com 8061596Szelenkov@nginx.com assert 'success' in self.conf_delete( 8071596Szelenkov@nginx.com 'routes/0/match/method/1' 8081596Szelenkov@nginx.com ), 'match edit configure 4' 8091596Szelenkov@nginx.com assert ['GET'] == self.conf_get( 8101596Szelenkov@nginx.com 'routes/0/match/method' 8111596Szelenkov@nginx.com ), 'match edit configure 4 check' 8121053Szelenkov@nginx.com 8131596Szelenkov@nginx.com assert self.get()['status'] == 200, 'match edit GET 4' 8141596Szelenkov@nginx.com assert self.post()['status'] == 404, 'match edit POST 4' 8151596Szelenkov@nginx.com assert self.put()['status'] == 404, 'match edit PUT 4' 8161053Szelenkov@nginx.com 8171596Szelenkov@nginx.com assert 'error' in self.conf_delete( 8181596Szelenkov@nginx.com 'routes/0/match/method/1' 8191596Szelenkov@nginx.com ), 'match edit configure invalid' 8201596Szelenkov@nginx.com assert 'error' in self.conf_delete( 8211596Szelenkov@nginx.com 'routes/0/match/method/-1' 8221596Szelenkov@nginx.com ), 'match edit configure invalid 2' 8231596Szelenkov@nginx.com assert 'error' in self.conf_delete( 8241596Szelenkov@nginx.com 'routes/0/match/method/blah' 8251596Szelenkov@nginx.com ), 'match edit configure invalid 3' 8261596Szelenkov@nginx.com assert ['GET'] == self.conf_get( 8271596Szelenkov@nginx.com 'routes/0/match/method' 8281596Szelenkov@nginx.com ), 'match edit configure 5 check' 8291053Szelenkov@nginx.com 8301596Szelenkov@nginx.com assert self.get()['status'] == 200, 'match edit GET 5' 8311596Szelenkov@nginx.com assert self.post()['status'] == 404, 'match edit POST 5' 8321596Szelenkov@nginx.com assert self.put()['status'] == 404, 'match edit PUT 5' 8331596Szelenkov@nginx.com 8341596Szelenkov@nginx.com assert 'success' in self.conf_delete( 8351596Szelenkov@nginx.com 'routes/0/match/method/0' 8361596Szelenkov@nginx.com ), 'match edit configure 6' 8371596Szelenkov@nginx.com assert [] == self.conf_get( 8381596Szelenkov@nginx.com 'routes/0/match/method' 8391596Szelenkov@nginx.com ), 'match edit configure 6 check' 8401053Szelenkov@nginx.com 8411596Szelenkov@nginx.com assert self.get()['status'] == 200, 'match edit GET 6' 8421596Szelenkov@nginx.com assert self.post()['status'] == 200, 'match edit POST 6' 8431596Szelenkov@nginx.com assert self.put()['status'] == 200, 'match edit PUT 6' 8441053Szelenkov@nginx.com 8451596Szelenkov@nginx.com assert 'success' in self.conf( 8461596Szelenkov@nginx.com '"GET"', 'routes/0/match/method' 8471596Szelenkov@nginx.com ), 'match edit configure 7' 8481053Szelenkov@nginx.com 8491596Szelenkov@nginx.com assert self.get()['status'] == 200, 'match edit GET 7' 8501596Szelenkov@nginx.com assert self.post()['status'] == 404, 'match edit POST 7' 8511596Szelenkov@nginx.com assert self.put()['status'] == 404, 'match edit PUT 7' 8521053Szelenkov@nginx.com 8531596Szelenkov@nginx.com assert 'error' in self.conf_delete( 8541596Szelenkov@nginx.com 'routes/0/match/method/0' 8551596Szelenkov@nginx.com ), 'match edit configure invalid 5' 8561596Szelenkov@nginx.com assert 'error' in self.conf( 8571596Szelenkov@nginx.com {}, 'routes/0/action' 8581596Szelenkov@nginx.com ), 'match edit configure invalid 6' 8591053Szelenkov@nginx.com 8601596Szelenkov@nginx.com assert 'success' in self.conf( 8611596Szelenkov@nginx.com {}, 'routes/0/match' 8621596Szelenkov@nginx.com ), 'match edit configure 8' 8631053Szelenkov@nginx.com 8641596Szelenkov@nginx.com assert self.get()['status'] == 200, 'match edit GET 8' 8651053Szelenkov@nginx.com 866972Szelenkov@nginx.com def test_routes_match_rules(self): 8671308Szelenkov@nginx.com self.route_match({"method": "GET", "host": "localhost", "uri": "/"}) 868972Szelenkov@nginx.com 8691596Szelenkov@nginx.com assert self.get()['status'] == 200, 'routes match rules' 870972Szelenkov@nginx.com 871972Szelenkov@nginx.com def test_routes_loop(self): 8721596Szelenkov@nginx.com assert 'success' in self.route( 8731596Szelenkov@nginx.com {"match": {"uri": "/"}, "action": {"pass": "routes"}} 8741596Szelenkov@nginx.com ), 'routes loop configure' 875972Szelenkov@nginx.com 8761596Szelenkov@nginx.com assert self.get()['status'] == 500, 'routes loop' 877972Szelenkov@nginx.com 8781066Szelenkov@nginx.com def test_routes_match_headers(self): 8791308Szelenkov@nginx.com self.route_match({"headers": {"host": "localhost"}}) 8801066Szelenkov@nginx.com 8811596Szelenkov@nginx.com assert self.get()['status'] == 200, 'match headers' 8821308Szelenkov@nginx.com self.host('Localhost', 200) 8831308Szelenkov@nginx.com self.host('localhost.com', 404) 8841308Szelenkov@nginx.com self.host('llocalhost', 404) 8851308Szelenkov@nginx.com self.host('host', 404) 8861066Szelenkov@nginx.com 8871066Szelenkov@nginx.com def test_routes_match_headers_multiple(self): 8881308Szelenkov@nginx.com self.route_match({"headers": {"host": "localhost", "x-blah": "test"}}) 8891066Szelenkov@nginx.com 8901596Szelenkov@nginx.com assert self.get()['status'] == 404, 'match headers multiple' 8911596Szelenkov@nginx.com assert ( 8921066Szelenkov@nginx.com self.get( 8931066Szelenkov@nginx.com headers={ 8941066Szelenkov@nginx.com "Host": "localhost", 8951066Szelenkov@nginx.com "X-blah": "test", 8961066Szelenkov@nginx.com "Connection": "close", 8971066Szelenkov@nginx.com } 8981596Szelenkov@nginx.com )['status'] 8991596Szelenkov@nginx.com == 200 9001596Szelenkov@nginx.com ), 'match headers multiple 2' 9011066Szelenkov@nginx.com 9021596Szelenkov@nginx.com assert ( 9031066Szelenkov@nginx.com self.get( 9041066Szelenkov@nginx.com headers={ 9051066Szelenkov@nginx.com "Host": "localhost", 9061066Szelenkov@nginx.com "X-blah": "", 9071066Szelenkov@nginx.com "Connection": "close", 9081066Szelenkov@nginx.com } 9091596Szelenkov@nginx.com )['status'] 9101596Szelenkov@nginx.com == 404 9111596Szelenkov@nginx.com ), 'match headers multiple 3' 9121066Szelenkov@nginx.com 9131066Szelenkov@nginx.com def test_routes_match_headers_multiple_values(self): 9141308Szelenkov@nginx.com self.route_match({"headers": {"x-blah": "test"}}) 9151066Szelenkov@nginx.com 9161596Szelenkov@nginx.com assert ( 9171066Szelenkov@nginx.com self.get( 9181066Szelenkov@nginx.com headers={ 9191066Szelenkov@nginx.com "Host": "localhost", 9201066Szelenkov@nginx.com "X-blah": ["test", "test", "test"], 9211066Szelenkov@nginx.com "Connection": "close", 9221066Szelenkov@nginx.com } 9231596Szelenkov@nginx.com )['status'] 9241596Szelenkov@nginx.com == 200 9251596Szelenkov@nginx.com ), 'match headers multiple values' 9261596Szelenkov@nginx.com assert ( 9271066Szelenkov@nginx.com self.get( 9281066Szelenkov@nginx.com headers={ 9291066Szelenkov@nginx.com "Host": "localhost", 9301066Szelenkov@nginx.com "X-blah": ["test", "blah", "test"], 9311066Szelenkov@nginx.com "Connection": "close", 9321066Szelenkov@nginx.com } 9331596Szelenkov@nginx.com )['status'] 9341596Szelenkov@nginx.com == 404 9351596Szelenkov@nginx.com ), 'match headers multiple values 2' 9361596Szelenkov@nginx.com assert ( 9371066Szelenkov@nginx.com self.get( 9381066Szelenkov@nginx.com headers={ 9391066Szelenkov@nginx.com "Host": "localhost", 9401066Szelenkov@nginx.com "X-blah": ["test", "", "test"], 9411066Szelenkov@nginx.com "Connection": "close", 9421066Szelenkov@nginx.com } 9431596Szelenkov@nginx.com )['status'] 9441596Szelenkov@nginx.com == 404 9451596Szelenkov@nginx.com ), 'match headers multiple values 3' 9461066Szelenkov@nginx.com 9471066Szelenkov@nginx.com def test_routes_match_headers_multiple_rules(self): 9481308Szelenkov@nginx.com self.route_match({"headers": {"x-blah": ["test", "blah"]}}) 9491066Szelenkov@nginx.com 9501596Szelenkov@nginx.com assert self.get()['status'] == 404, 'match headers multiple rules' 9511596Szelenkov@nginx.com assert ( 9521066Szelenkov@nginx.com self.get( 9531066Szelenkov@nginx.com headers={ 9541066Szelenkov@nginx.com "Host": "localhost", 9551066Szelenkov@nginx.com "X-blah": "test", 9561066Szelenkov@nginx.com "Connection": "close", 9571066Szelenkov@nginx.com } 9581596Szelenkov@nginx.com )['status'] 9591596Szelenkov@nginx.com == 200 9601596Szelenkov@nginx.com ), 'match headers multiple rules 2' 9611596Szelenkov@nginx.com assert ( 9621066Szelenkov@nginx.com self.get( 9631066Szelenkov@nginx.com headers={ 9641066Szelenkov@nginx.com "Host": "localhost", 9651066Szelenkov@nginx.com "X-blah": "blah", 9661066Szelenkov@nginx.com "Connection": "close", 9671066Szelenkov@nginx.com } 9681596Szelenkov@nginx.com )['status'] 9691596Szelenkov@nginx.com == 200 9701596Szelenkov@nginx.com ), 'match headers multiple rules 3' 9711596Szelenkov@nginx.com assert ( 9721066Szelenkov@nginx.com self.get( 9731066Szelenkov@nginx.com headers={ 9741066Szelenkov@nginx.com "Host": "localhost", 9751066Szelenkov@nginx.com "X-blah": ["test", "blah", "test"], 9761066Szelenkov@nginx.com "Connection": "close", 9771066Szelenkov@nginx.com } 9781596Szelenkov@nginx.com )['status'] 9791596Szelenkov@nginx.com == 200 9801596Szelenkov@nginx.com ), 'match headers multiple rules 4' 9811066Szelenkov@nginx.com 9821596Szelenkov@nginx.com assert ( 9831066Szelenkov@nginx.com self.get( 9841066Szelenkov@nginx.com headers={ 9851066Szelenkov@nginx.com "Host": "localhost", 9861066Szelenkov@nginx.com "X-blah": ["blah", ""], 9871066Szelenkov@nginx.com "Connection": "close", 9881066Szelenkov@nginx.com } 9891596Szelenkov@nginx.com )['status'] 9901596Szelenkov@nginx.com == 404 9911596Szelenkov@nginx.com ), 'match headers multiple rules 5' 9921066Szelenkov@nginx.com 9931066Szelenkov@nginx.com def test_routes_match_headers_case_insensitive(self): 9941308Szelenkov@nginx.com self.route_match({"headers": {"X-BLAH": "TEST"}}) 9951066Szelenkov@nginx.com 9961596Szelenkov@nginx.com assert ( 9971066Szelenkov@nginx.com self.get( 9981066Szelenkov@nginx.com headers={ 9991066Szelenkov@nginx.com "Host": "localhost", 10001066Szelenkov@nginx.com "x-blah": "test", 10011066Szelenkov@nginx.com "Connection": "close", 10021066Szelenkov@nginx.com } 10031596Szelenkov@nginx.com )['status'] 10041596Szelenkov@nginx.com == 200 10051596Szelenkov@nginx.com ), 'match headers case insensitive' 10061066Szelenkov@nginx.com 10071066Szelenkov@nginx.com def test_routes_match_headers_invalid(self): 10081308Szelenkov@nginx.com self.route_match_invalid({"headers": ["blah"]}) 10091308Szelenkov@nginx.com self.route_match_invalid({"headers": {"foo": ["bar", {}]}}) 10101308Szelenkov@nginx.com self.route_match_invalid({"headers": {"": "blah"}}) 10111066Szelenkov@nginx.com 10121066Szelenkov@nginx.com def test_routes_match_headers_empty_rule(self): 10131308Szelenkov@nginx.com self.route_match({"headers": {"host": ""}}) 10141066Szelenkov@nginx.com 10151596Szelenkov@nginx.com assert self.get()['status'] == 404, 'localhost' 10161308Szelenkov@nginx.com self.host('', 200) 10171066Szelenkov@nginx.com 10181066Szelenkov@nginx.com def test_routes_match_headers_empty(self): 10191308Szelenkov@nginx.com self.route_match({"headers": {}}) 10201596Szelenkov@nginx.com assert self.get()['status'] == 200, 'empty' 10211066Szelenkov@nginx.com 10221308Szelenkov@nginx.com self.route_match({"headers": []}) 10231596Szelenkov@nginx.com assert self.get()['status'] == 200, 'empty 2' 10241066Szelenkov@nginx.com 10251066Szelenkov@nginx.com def test_routes_match_headers_rule_array_empty(self): 10261308Szelenkov@nginx.com self.route_match({"headers": {"blah": []}}) 10271066Szelenkov@nginx.com 10281596Szelenkov@nginx.com assert self.get()['status'] == 404, 'array empty' 10291596Szelenkov@nginx.com assert ( 10301066Szelenkov@nginx.com self.get( 10311066Szelenkov@nginx.com headers={ 10321066Szelenkov@nginx.com "Host": "localhost", 10331066Szelenkov@nginx.com "blah": "foo", 10341066Szelenkov@nginx.com "Connection": "close", 10351066Szelenkov@nginx.com } 10361596Szelenkov@nginx.com )['status'] 10371596Szelenkov@nginx.com == 200 10381596Szelenkov@nginx.com ), 'match headers rule array empty 2' 10391066Szelenkov@nginx.com 10401066Szelenkov@nginx.com def test_routes_match_headers_array(self): 10411308Szelenkov@nginx.com self.route_match( 10421308Szelenkov@nginx.com { 10431308Szelenkov@nginx.com "headers": [ 10441308Szelenkov@nginx.com {"x-header1": "foo*"}, 10451308Szelenkov@nginx.com {"x-header2": "bar"}, 10461308Szelenkov@nginx.com {"x-header3": ["foo", "bar"]}, 10471308Szelenkov@nginx.com {"x-header1": "bar", "x-header4": "foo"}, 10481308Szelenkov@nginx.com ] 10491308Szelenkov@nginx.com } 10501066Szelenkov@nginx.com ) 10511066Szelenkov@nginx.com 10521875Szelenkov@nginx.com def check_headers(hds): 10531875Szelenkov@nginx.com hds = dict({"Host": "localhost", "Connection": "close"}, **hds) 1054*2073Szelenkov@nginx.com assert self.get(headers=hds)['status'] == 200, 'headers array match' 10551875Szelenkov@nginx.com 10561875Szelenkov@nginx.com def check_headers_404(hds): 10571875Szelenkov@nginx.com hds = dict({"Host": "localhost", "Connection": "close"}, **hds) 10581875Szelenkov@nginx.com assert ( 10591875Szelenkov@nginx.com self.get(headers=hds)['status'] == 404 10601875Szelenkov@nginx.com ), 'headers array no match' 10611875Szelenkov@nginx.com 10621596Szelenkov@nginx.com assert self.get()['status'] == 404, 'match headers array' 10631875Szelenkov@nginx.com check_headers({"x-header1": "foo123"}) 10641875Szelenkov@nginx.com check_headers({"x-header2": "bar"}) 10651875Szelenkov@nginx.com check_headers({"x-header3": "bar"}) 10661875Szelenkov@nginx.com check_headers_404({"x-header1": "bar"}) 10671875Szelenkov@nginx.com check_headers({"x-header1": "bar", "x-header4": "foo"}) 10681066Szelenkov@nginx.com 10691596Szelenkov@nginx.com assert 'success' in self.conf_delete( 10701596Szelenkov@nginx.com 'routes/0/match/headers/1' 10711596Szelenkov@nginx.com ), 'match headers array configure 2' 10721066Szelenkov@nginx.com 10731875Szelenkov@nginx.com check_headers_404({"x-header2": "bar"}) 10741875Szelenkov@nginx.com check_headers({"x-header3": "foo"}) 10751017Szelenkov@nginx.com 10761067Szelenkov@nginx.com def test_routes_match_arguments(self): 10771308Szelenkov@nginx.com self.route_match({"arguments": {"foo": "bar"}}) 10781067Szelenkov@nginx.com 10791596Szelenkov@nginx.com assert self.get()['status'] == 404, 'args' 10801596Szelenkov@nginx.com assert self.get(url='/?foo=bar')['status'] == 200, 'args 2' 10811596Szelenkov@nginx.com assert self.get(url='/?foo=bar1')['status'] == 404, 'args 3' 10821596Szelenkov@nginx.com assert self.get(url='/?1foo=bar')['status'] == 404, 'args 4' 10831596Szelenkov@nginx.com assert self.get(url='/?Foo=bar')['status'] == 404, 'case' 10841596Szelenkov@nginx.com assert self.get(url='/?foo=Bar')['status'] == 404, 'case 2' 10851067Szelenkov@nginx.com 10861475Saxel.duch@nginx.com def test_routes_match_arguments_chars(self): 10871475Saxel.duch@nginx.com chars = ( 10881475Saxel.duch@nginx.com " !\"%23$%25%26'()*%2B,-./0123456789:;<%3D>?@" 10891475Saxel.duch@nginx.com "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" 10901475Saxel.duch@nginx.com ) 10911475Saxel.duch@nginx.com 10921475Saxel.duch@nginx.com chars_enc = "" 10931475Saxel.duch@nginx.com for h1 in ["2", "3", "4", "5", "6", "7"]: 10941596Szelenkov@nginx.com for h2 in [ 10951596Szelenkov@nginx.com "0", 10961596Szelenkov@nginx.com "1", 10971596Szelenkov@nginx.com "2", 10981596Szelenkov@nginx.com "3", 10991596Szelenkov@nginx.com "4", 11001596Szelenkov@nginx.com "5", 11011596Szelenkov@nginx.com "6", 11021596Szelenkov@nginx.com "7", 11031596Szelenkov@nginx.com "8", 11041596Szelenkov@nginx.com "9", 11051596Szelenkov@nginx.com "A", 11061596Szelenkov@nginx.com "B", 11071596Szelenkov@nginx.com "C", 11081596Szelenkov@nginx.com "D", 11091596Szelenkov@nginx.com "E", 11101596Szelenkov@nginx.com "F", 11111475Saxel.duch@nginx.com ]: 11121475Saxel.duch@nginx.com chars_enc += "%" + h1 + h2 11131475Saxel.duch@nginx.com chars_enc = chars_enc[:-3] 11141475Saxel.duch@nginx.com 11151475Saxel.duch@nginx.com def check_args(args, query): 11161475Saxel.duch@nginx.com self.route_match({"arguments": args}) 11171596Szelenkov@nginx.com assert self.get(url='/?' + query)['status'] == 200 11181475Saxel.duch@nginx.com 11191475Saxel.duch@nginx.com check_args({chars: chars}, chars + '=' + chars) 11201475Saxel.duch@nginx.com check_args({chars: chars}, chars + '=' + chars_enc) 11211475Saxel.duch@nginx.com check_args({chars: chars}, chars_enc + '=' + chars) 11221475Saxel.duch@nginx.com check_args({chars: chars}, chars_enc + '=' + chars_enc) 11231475Saxel.duch@nginx.com check_args({chars_enc: chars_enc}, chars + '=' + chars) 11241475Saxel.duch@nginx.com check_args({chars_enc: chars_enc}, chars + '=' + chars_enc) 11251475Saxel.duch@nginx.com check_args({chars_enc: chars_enc}, chars_enc + '=' + chars) 11261475Saxel.duch@nginx.com check_args({chars_enc: chars_enc}, chars_enc + '=' + chars_enc) 11271475Saxel.duch@nginx.com 11281067Szelenkov@nginx.com def test_routes_match_arguments_empty(self): 11291308Szelenkov@nginx.com self.route_match({"arguments": {}}) 11301596Szelenkov@nginx.com assert self.get()['status'] == 200, 'arguments empty' 11311067Szelenkov@nginx.com 11321308Szelenkov@nginx.com self.route_match({"arguments": []}) 11331596Szelenkov@nginx.com assert self.get()['status'] == 200, 'arguments empty 2' 11341067Szelenkov@nginx.com 11351067Szelenkov@nginx.com def test_routes_match_arguments_space(self): 11361475Saxel.duch@nginx.com self.route_match({"arguments": {"+fo o%20": "%20b+a r"}}) 11371596Szelenkov@nginx.com assert self.get(url='/? fo o = b a r&')['status'] == 200 11381596Szelenkov@nginx.com assert self.get(url='/?+fo+o+=+b+a+r&')['status'] == 200 11391596Szelenkov@nginx.com assert self.get(url='/?%20fo%20o%20=%20b%20a%20r&')['status'] == 200 11401067Szelenkov@nginx.com 11411475Saxel.duch@nginx.com self.route_match({"arguments": {"%20foo": " bar"}}) 11421596Szelenkov@nginx.com assert self.get(url='/? foo= bar')['status'] == 200 11431596Szelenkov@nginx.com assert self.get(url='/?+foo=+bar')['status'] == 200 11441596Szelenkov@nginx.com assert self.get(url='/?%20foo=%20bar')['status'] == 200 11451596Szelenkov@nginx.com assert self.get(url='/?+foo= bar')['status'] == 200 11461596Szelenkov@nginx.com assert self.get(url='/?%20foo=+bar')['status'] == 200 11471475Saxel.duch@nginx.com 11481475Saxel.duch@nginx.com def test_routes_match_arguments_equal(self): 11491475Saxel.duch@nginx.com self.route_match({"arguments": {"=": "="}}) 11501596Szelenkov@nginx.com assert self.get(url='/?%3D=%3D')['status'] == 200 11511596Szelenkov@nginx.com assert self.get(url='/?%3D==')['status'] == 200 11521596Szelenkov@nginx.com assert self.get(url='/?===')['status'] == 404 11531596Szelenkov@nginx.com assert self.get(url='/?%3D%3D%3D')['status'] == 404 11541596Szelenkov@nginx.com assert self.get(url='/?==%3D')['status'] == 404 11551475Saxel.duch@nginx.com 11561475Saxel.duch@nginx.com def test_routes_match_arguments_enc(self): 11571475Saxel.duch@nginx.com self.route_match({"arguments": {"Ю": "н"}}) 11581596Szelenkov@nginx.com assert self.get(url='/?%D0%AE=%D0%BD')['status'] == 200 11591596Szelenkov@nginx.com assert self.get(url='/?%d0%ae=%d0%Bd')['status'] == 200 11601475Saxel.duch@nginx.com 11611475Saxel.duch@nginx.com def test_routes_match_arguments_hash(self): 11621475Saxel.duch@nginx.com self.route_match({"arguments": {"#": "#"}}) 11631596Szelenkov@nginx.com assert self.get(url='/?%23=%23')['status'] == 200 11641596Szelenkov@nginx.com assert self.get(url='/?%23=%23#')['status'] == 200 11651596Szelenkov@nginx.com assert self.get(url='/?#=#')['status'] == 404 11661596Szelenkov@nginx.com assert self.get(url='/?%23=#')['status'] == 404 11671475Saxel.duch@nginx.com 11681475Saxel.duch@nginx.com def test_routes_match_arguments_wildcard(self): 11691475Saxel.duch@nginx.com self.route_match({"arguments": {"foo": "*"}}) 11701596Szelenkov@nginx.com assert self.get(url='/?foo')['status'] == 200 11711596Szelenkov@nginx.com assert self.get(url='/?foo=')['status'] == 200 11721596Szelenkov@nginx.com assert self.get(url='/?foo=blah')['status'] == 200 11731596Szelenkov@nginx.com assert self.get(url='/?blah=foo')['status'] == 404 11741475Saxel.duch@nginx.com 11751475Saxel.duch@nginx.com self.route_match({"arguments": {"foo": "%25*"}}) 11761596Szelenkov@nginx.com assert self.get(url='/?foo=%xx')['status'] == 200 11771475Saxel.duch@nginx.com 11781475Saxel.duch@nginx.com self.route_match({"arguments": {"foo": "%2A*"}}) 11791596Szelenkov@nginx.com assert self.get(url='/?foo=*xx')['status'] == 200 11801596Szelenkov@nginx.com assert self.get(url='/?foo=xx')['status'] == 404 11811475Saxel.duch@nginx.com 11821475Saxel.duch@nginx.com self.route_match({"arguments": {"foo": "*%2A"}}) 11831596Szelenkov@nginx.com assert self.get(url='/?foo=xx*')['status'] == 200 11841596Szelenkov@nginx.com assert self.get(url='/?foo=xx*x')['status'] == 404 11851067Szelenkov@nginx.com 11861475Saxel.duch@nginx.com self.route_match({"arguments": {"foo": "1*2"}}) 11871596Szelenkov@nginx.com assert self.get(url='/?foo=12')['status'] == 200 11881596Szelenkov@nginx.com assert self.get(url='/?foo=1blah2')['status'] == 200 11891596Szelenkov@nginx.com assert self.get(url='/?foo=1%2A2')['status'] == 200 11901596Szelenkov@nginx.com assert self.get(url='/?foo=x12')['status'] == 404 11911475Saxel.duch@nginx.com 11921475Saxel.duch@nginx.com self.route_match({"arguments": {"foo": "bar*", "%25": "%25"}}) 11931596Szelenkov@nginx.com assert self.get(url='/?foo=barxx&%=%')['status'] == 200 11941596Szelenkov@nginx.com assert self.get(url='/?foo=barxx&x%=%')['status'] == 404 11951475Saxel.duch@nginx.com 11961475Saxel.duch@nginx.com def test_routes_match_arguments_negative(self): 11971633Svbart@nginx.com self.route_match({"arguments": {"foo": "!"}}) 11981633Svbart@nginx.com assert self.get(url='/?bar')['status'] == 404 11991633Svbart@nginx.com assert self.get(url='/?foo')['status'] == 404 12001633Svbart@nginx.com assert self.get(url='/?foo=')['status'] == 404 12011633Svbart@nginx.com assert self.get(url='/?foo=%25')['status'] == 200 12021633Svbart@nginx.com 12031633Svbart@nginx.com self.route_match({"arguments": {"foo": "!*"}}) 12041633Svbart@nginx.com assert self.get(url='/?bar')['status'] == 404 12051633Svbart@nginx.com assert self.get(url='/?foo')['status'] == 404 12061633Svbart@nginx.com assert self.get(url='/?foo=')['status'] == 404 12071633Svbart@nginx.com assert self.get(url='/?foo=blah')['status'] == 404 12081633Svbart@nginx.com 12091475Saxel.duch@nginx.com self.route_match({"arguments": {"foo": "!%25"}}) 12101596Szelenkov@nginx.com assert self.get(url='/?foo=blah')['status'] == 200 12111596Szelenkov@nginx.com assert self.get(url='/?foo=%')['status'] == 404 12121475Saxel.duch@nginx.com 12131475Saxel.duch@nginx.com self.route_match({"arguments": {"foo": "%21blah"}}) 12141596Szelenkov@nginx.com assert self.get(url='/?foo=%21blah')['status'] == 200 12151596Szelenkov@nginx.com assert self.get(url='/?foo=!blah')['status'] == 200 12161596Szelenkov@nginx.com assert self.get(url='/?foo=bar')['status'] == 404 12171475Saxel.duch@nginx.com 12181475Saxel.duch@nginx.com self.route_match({"arguments": {"foo": "!!%21*a"}}) 12191596Szelenkov@nginx.com assert self.get(url='/?foo=blah')['status'] == 200 12201596Szelenkov@nginx.com assert self.get(url='/?foo=!blah')['status'] == 200 12211596Szelenkov@nginx.com assert self.get(url='/?foo=!!a')['status'] == 404 12221596Szelenkov@nginx.com assert self.get(url='/?foo=!!bla')['status'] == 404 12231067Szelenkov@nginx.com 12241475Saxel.duch@nginx.com def test_routes_match_arguments_percent(self): 12251475Saxel.duch@nginx.com self.route_match({"arguments": {"%25": "%25"}}) 12261596Szelenkov@nginx.com assert self.get(url='/?%=%')['status'] == 200 12271596Szelenkov@nginx.com assert self.get(url='/?%25=%25')['status'] == 200 12281596Szelenkov@nginx.com assert self.get(url='/?%25=%')['status'] == 200 12291475Saxel.duch@nginx.com 12301475Saxel.duch@nginx.com self.route_match({"arguments": {"%251": "%252"}}) 12311596Szelenkov@nginx.com assert self.get(url='/?%1=%2')['status'] == 200 12321596Szelenkov@nginx.com assert self.get(url='/?%251=%252')['status'] == 200 12331596Szelenkov@nginx.com assert self.get(url='/?%251=%2')['status'] == 200 12341067Szelenkov@nginx.com 12351475Saxel.duch@nginx.com self.route_match({"arguments": {"%25%21%251": "%25%24%252"}}) 12361596Szelenkov@nginx.com assert self.get(url='/?%!%1=%$%2')['status'] == 200 12371596Szelenkov@nginx.com assert self.get(url='/?%25!%251=%25$%252')['status'] == 200 12381596Szelenkov@nginx.com assert self.get(url='/?%25!%1=%$%2')['status'] == 200 12391475Saxel.duch@nginx.com 12401475Saxel.duch@nginx.com def test_routes_match_arguments_ampersand(self): 12411475Saxel.duch@nginx.com self.route_match({"arguments": {"foo": "&"}}) 12421596Szelenkov@nginx.com assert self.get(url='/?foo=%26')['status'] == 200 12431596Szelenkov@nginx.com assert self.get(url='/?foo=%26&')['status'] == 200 12441596Szelenkov@nginx.com assert self.get(url='/?foo=%26%26')['status'] == 404 12451596Szelenkov@nginx.com assert self.get(url='/?foo=&')['status'] == 404 12461475Saxel.duch@nginx.com 12471475Saxel.duch@nginx.com self.route_match({"arguments": {"&": ""}}) 12481596Szelenkov@nginx.com assert self.get(url='/?%26=')['status'] == 200 12491596Szelenkov@nginx.com assert self.get(url='/?%26=&')['status'] == 200 12501596Szelenkov@nginx.com assert self.get(url='/?%26=%26')['status'] == 404 12511596Szelenkov@nginx.com assert self.get(url='/?&=')['status'] == 404 12521067Szelenkov@nginx.com 12531067Szelenkov@nginx.com def test_routes_match_arguments_complex(self): 12541308Szelenkov@nginx.com self.route_match({"arguments": {"foo": ""}}) 12551067Szelenkov@nginx.com 12561596Szelenkov@nginx.com assert self.get(url='/?foo')['status'] == 200, 'complex' 12571596Szelenkov@nginx.com assert self.get(url='/?blah=blah&foo=')['status'] == 200, 'complex 2' 12581596Szelenkov@nginx.com assert self.get(url='/?&&&foo&&&')['status'] == 200, 'complex 3' 12591596Szelenkov@nginx.com assert self.get(url='/?foo&foo=bar&foo')['status'] == 404, 'complex 4' 12601596Szelenkov@nginx.com assert self.get(url='/?foo=&foo')['status'] == 200, 'complex 5' 12611596Szelenkov@nginx.com assert self.get(url='/?&=&foo&==&')['status'] == 200, 'complex 6' 12621596Szelenkov@nginx.com assert self.get(url='/?&=&bar&==&')['status'] == 404, 'complex 7' 12631067Szelenkov@nginx.com 12641067Szelenkov@nginx.com def test_routes_match_arguments_multiple(self): 12651308Szelenkov@nginx.com self.route_match({"arguments": {"foo": "bar", "blah": "test"}}) 12661067Szelenkov@nginx.com 12671596Szelenkov@nginx.com assert self.get()['status'] == 404, 'multiple' 12681596Szelenkov@nginx.com assert ( 12691596Szelenkov@nginx.com self.get(url='/?foo=bar&blah=test')['status'] == 200 12701596Szelenkov@nginx.com ), 'multiple 2' 12711596Szelenkov@nginx.com assert self.get(url='/?foo=bar&blah')['status'] == 404, 'multiple 3' 1272*2073Szelenkov@nginx.com assert self.get(url='/?foo=bar&blah=tes')['status'] == 404, 'multiple 4' 12731596Szelenkov@nginx.com assert ( 12741596Szelenkov@nginx.com self.get(url='/?foo=b%61r&bl%61h=t%65st')['status'] == 200 12751596Szelenkov@nginx.com ), 'multiple 5' 12761067Szelenkov@nginx.com 12771067Szelenkov@nginx.com def test_routes_match_arguments_multiple_rules(self): 12781308Szelenkov@nginx.com self.route_match({"arguments": {"foo": ["bar", "blah"]}}) 12791067Szelenkov@nginx.com 12801596Szelenkov@nginx.com assert self.get()['status'] == 404, 'rules' 12811596Szelenkov@nginx.com assert self.get(url='/?foo=bar')['status'] == 200, 'rules 2' 12821596Szelenkov@nginx.com assert self.get(url='/?foo=blah')['status'] == 200, 'rules 3' 12831596Szelenkov@nginx.com assert ( 12841596Szelenkov@nginx.com self.get(url='/?foo=blah&foo=bar&foo=blah')['status'] == 200 12851596Szelenkov@nginx.com ), 'rules 4' 12861596Szelenkov@nginx.com assert ( 12871596Szelenkov@nginx.com self.get(url='/?foo=blah&foo=bar&foo=')['status'] == 404 12881596Szelenkov@nginx.com ), 'rules 5' 12891067Szelenkov@nginx.com 12901067Szelenkov@nginx.com def test_routes_match_arguments_array(self): 12911308Szelenkov@nginx.com self.route_match( 12921308Szelenkov@nginx.com { 12931308Szelenkov@nginx.com "arguments": [ 12941308Szelenkov@nginx.com {"var1": "val1*"}, 12951308Szelenkov@nginx.com {"var2": "val2"}, 12961308Szelenkov@nginx.com {"var3": ["foo", "bar"]}, 12971308Szelenkov@nginx.com {"var1": "bar", "var4": "foo"}, 12981308Szelenkov@nginx.com ] 12991308Szelenkov@nginx.com } 13001067Szelenkov@nginx.com ) 13011067Szelenkov@nginx.com 13021596Szelenkov@nginx.com assert self.get()['status'] == 404, 'arr' 13031596Szelenkov@nginx.com assert self.get(url='/?var1=val123')['status'] == 200, 'arr 2' 13041596Szelenkov@nginx.com assert self.get(url='/?var2=val2')['status'] == 200, 'arr 3' 13051596Szelenkov@nginx.com assert self.get(url='/?var3=bar')['status'] == 200, 'arr 4' 13061596Szelenkov@nginx.com assert self.get(url='/?var1=bar')['status'] == 404, 'arr 5' 13071596Szelenkov@nginx.com assert self.get(url='/?var1=bar&var4=foo')['status'] == 200, 'arr 6' 13081067Szelenkov@nginx.com 13091596Szelenkov@nginx.com assert 'success' in self.conf_delete( 13101596Szelenkov@nginx.com 'routes/0/match/arguments/1' 13111596Szelenkov@nginx.com ), 'match arguments array configure 2' 13121067Szelenkov@nginx.com 13131596Szelenkov@nginx.com assert self.get(url='/?var2=val2')['status'] == 404, 'arr 7' 13141596Szelenkov@nginx.com assert self.get(url='/?var3=foo')['status'] == 200, 'arr 8' 13151067Szelenkov@nginx.com 13161846Szelenkov@nginx.com def test_routes_match_arguments_invalid(self): 13171475Saxel.duch@nginx.com self.route_match_invalid({"arguments": ["var"]}) 13181475Saxel.duch@nginx.com self.route_match_invalid({"arguments": [{"var1": {}}]}) 13191475Saxel.duch@nginx.com self.route_match_invalid({"arguments": {"": "bar"}}) 13201475Saxel.duch@nginx.com self.route_match_invalid({"arguments": {"foo": "%"}}) 13211475Saxel.duch@nginx.com self.route_match_invalid({"arguments": {"foo": "%1G"}}) 13221475Saxel.duch@nginx.com self.route_match_invalid({"arguments": {"%": "bar"}}) 13231475Saxel.duch@nginx.com self.route_match_invalid({"arguments": {"foo": "%0"}}) 13241475Saxel.duch@nginx.com self.route_match_invalid({"arguments": {"foo": "%%1F"}}) 13251475Saxel.duch@nginx.com self.route_match_invalid({"arguments": {"%%1F": ""}}) 13261475Saxel.duch@nginx.com self.route_match_invalid({"arguments": {"%7%F": ""}}) 13271475Saxel.duch@nginx.com 13281991Sz.hong@f5.com def test_routes_match_query(self): 13291991Sz.hong@f5.com self.route_match({"query": "!"}) 13301991Sz.hong@f5.com assert self.get(url='/')['status'] == 404 13311991Sz.hong@f5.com assert self.get(url='/?')['status'] == 404 13321991Sz.hong@f5.com assert self.get(url='/?foo')['status'] == 200 13331991Sz.hong@f5.com assert self.get(url='/?foo=')['status'] == 200 13341991Sz.hong@f5.com assert self.get(url='/?foo=baz')['status'] == 200 13351991Sz.hong@f5.com 13361991Sz.hong@f5.com self.route_match({"query": "foo=%26"}) 13371991Sz.hong@f5.com assert self.get(url='/?foo=&')['status'] == 200 13381991Sz.hong@f5.com 13391991Sz.hong@f5.com self.route_match({"query": "a=b&c=d"}) 13401991Sz.hong@f5.com assert self.get(url='/?a=b&c=d')['status'] == 200 13411991Sz.hong@f5.com 13421991Sz.hong@f5.com self.route_match({"query": "a=b%26c%3Dd"}) 13431991Sz.hong@f5.com assert self.get(url='/?a=b%26c%3Dd')['status'] == 200 13441991Sz.hong@f5.com assert self.get(url='/?a=b&c=d')['status'] == 200 13451991Sz.hong@f5.com 13461991Sz.hong@f5.com self.route_match({"query": "a=b%26c%3Dd+e"}) 13471991Sz.hong@f5.com assert self.get(url='/?a=b&c=d e')['status'] == 200 13481991Sz.hong@f5.com 13491991Sz.hong@f5.com def test_routes_match_query_array(self): 13502001Szelenkov@nginx.com self.route_match({"query": ["foo", "bar"]}) 13511991Sz.hong@f5.com 13522001Szelenkov@nginx.com assert self.get()['status'] == 404, 'no args' 13532001Szelenkov@nginx.com assert self.get(url='/?foo')['status'] == 200, 'arg first' 13542001Szelenkov@nginx.com assert self.get(url='/?bar')['status'] == 200, 'arg second' 13551991Sz.hong@f5.com 13561991Sz.hong@f5.com assert 'success' in self.conf_delete( 13571991Sz.hong@f5.com 'routes/0/match/query/1' 13582001Szelenkov@nginx.com ), 'query array remove second' 13592001Szelenkov@nginx.com 13602001Szelenkov@nginx.com assert self.get(url='/?foo')['status'] == 200, 'still arg first' 13612001Szelenkov@nginx.com assert self.get(url='/?bar')['status'] == 404, 'no arg second' 13622001Szelenkov@nginx.com 13632001Szelenkov@nginx.com self.route_match({"query": ["!f", "foo"]}) 13641991Sz.hong@f5.com 13652001Szelenkov@nginx.com assert self.get(url='/?f')['status'] == 404, 'negative arg' 13662001Szelenkov@nginx.com assert self.get(url='/?fo')['status'] == 404, 'negative arg 2' 13672001Szelenkov@nginx.com assert self.get(url='/?foo')['status'] == 200, 'negative arg 3' 13682001Szelenkov@nginx.com 13692001Szelenkov@nginx.com self.route_match({"query": []}) 13702001Szelenkov@nginx.com assert self.get()['status'] == 200, 'empty array' 13711991Sz.hong@f5.com 13721991Sz.hong@f5.com def test_routes_match_query_invalid(self): 13731991Sz.hong@f5.com self.route_match_invalid({"query": [1]}) 13741991Sz.hong@f5.com self.route_match_invalid({"query": "%"}) 13751991Sz.hong@f5.com self.route_match_invalid({"query": "%1G"}) 13761991Sz.hong@f5.com self.route_match_invalid({"query": "%0"}) 13771991Sz.hong@f5.com self.route_match_invalid({"query": "%%1F"}) 13781991Sz.hong@f5.com self.route_match_invalid({"query": ["foo", "%3D", "%%1F"]}) 13791991Sz.hong@f5.com 13801068Szelenkov@nginx.com def test_routes_match_cookies(self): 13811308Szelenkov@nginx.com self.route_match({"cookies": {"foO": "bar"}}) 13821068Szelenkov@nginx.com 13831596Szelenkov@nginx.com assert self.get()['status'] == 404, 'cookie' 13841308Szelenkov@nginx.com self.cookie('foO=bar', 200) 13851308Szelenkov@nginx.com self.cookie('foO=bar;1', 200) 13861308Szelenkov@nginx.com self.cookie(['foO=bar', 'blah=blah'], 200) 13871308Szelenkov@nginx.com self.cookie('foO=bar; blah=blah', 200) 13881308Szelenkov@nginx.com self.cookie('Foo=bar', 404) 13891308Szelenkov@nginx.com self.cookie('foO=Bar', 404) 13901308Szelenkov@nginx.com self.cookie('foO=bar1', 404) 13911308Szelenkov@nginx.com self.cookie('1foO=bar;', 404) 13921068Szelenkov@nginx.com 13931068Szelenkov@nginx.com def test_routes_match_cookies_empty(self): 13941308Szelenkov@nginx.com self.route_match({"cookies": {}}) 13951596Szelenkov@nginx.com assert self.get()['status'] == 200, 'cookies empty' 13961068Szelenkov@nginx.com 13971308Szelenkov@nginx.com self.route_match({"cookies": []}) 13981596Szelenkov@nginx.com assert self.get()['status'] == 200, 'cookies empty 2' 13991068Szelenkov@nginx.com 14001068Szelenkov@nginx.com def test_routes_match_cookies_invalid(self): 14011308Szelenkov@nginx.com self.route_match_invalid({"cookies": ["var"]}) 14021308Szelenkov@nginx.com self.route_match_invalid({"cookies": [{"foo": {}}]}) 14031068Szelenkov@nginx.com 14041068Szelenkov@nginx.com def test_routes_match_cookies_multiple(self): 14051308Szelenkov@nginx.com self.route_match({"cookies": {"foo": "bar", "blah": "blah"}}) 14061308Szelenkov@nginx.com 14071596Szelenkov@nginx.com assert self.get()['status'] == 404, 'multiple' 14081308Szelenkov@nginx.com self.cookie('foo=bar; blah=blah', 200) 14091308Szelenkov@nginx.com self.cookie(['foo=bar', 'blah=blah'], 200) 14101308Szelenkov@nginx.com self.cookie(['foo=bar; blah', 'blah'], 404) 14111308Szelenkov@nginx.com self.cookie(['foo=bar; blah=test', 'blah=blah'], 404) 14121068Szelenkov@nginx.com 14131308Szelenkov@nginx.com def test_routes_match_cookies_multiple_values(self): 14141308Szelenkov@nginx.com self.route_match({"cookies": {"blah": "blah"}}) 14151308Szelenkov@nginx.com 14161308Szelenkov@nginx.com self.cookie(['blah=blah', 'blah=blah', 'blah=blah'], 200) 14171308Szelenkov@nginx.com self.cookie(['blah=blah', 'blah=test', 'blah=blah'], 404) 14181308Szelenkov@nginx.com self.cookie(['blah=blah; blah=', 'blah=blah'], 404) 14191308Szelenkov@nginx.com 14201308Szelenkov@nginx.com def test_routes_match_cookies_multiple_rules(self): 14211308Szelenkov@nginx.com self.route_match({"cookies": {"blah": ["test", "blah"]}}) 14221068Szelenkov@nginx.com 14231596Szelenkov@nginx.com assert self.get()['status'] == 404, 'multiple rules' 14241308Szelenkov@nginx.com self.cookie('blah=test', 200) 14251308Szelenkov@nginx.com self.cookie('blah=blah', 200) 14261308Szelenkov@nginx.com self.cookie(['blah=blah', 'blah=test', 'blah=blah'], 200) 14271308Szelenkov@nginx.com self.cookie(['blah=blah; blah=test', 'blah=blah'], 200) 14281596Szelenkov@nginx.com self.cookie(['blah=blah', 'blah'], 200) # invalid cookie 14291068Szelenkov@nginx.com 14301308Szelenkov@nginx.com def test_routes_match_cookies_array(self): 14311308Szelenkov@nginx.com self.route_match( 14321308Szelenkov@nginx.com { 14331308Szelenkov@nginx.com "cookies": [ 14341308Szelenkov@nginx.com {"var1": "val1*"}, 14351308Szelenkov@nginx.com {"var2": "val2"}, 14361308Szelenkov@nginx.com {"var3": ["foo", "bar"]}, 14371308Szelenkov@nginx.com {"var1": "bar", "var4": "foo"}, 14381308Szelenkov@nginx.com ] 14391308Szelenkov@nginx.com } 14401068Szelenkov@nginx.com ) 14411068Szelenkov@nginx.com 14421596Szelenkov@nginx.com assert self.get()['status'] == 404, 'cookies array' 14431308Szelenkov@nginx.com self.cookie('var1=val123', 200) 14441308Szelenkov@nginx.com self.cookie('var2=val2', 200) 14451308Szelenkov@nginx.com self.cookie(' var2=val2 ', 200) 14461308Szelenkov@nginx.com self.cookie('var3=bar', 200) 14471308Szelenkov@nginx.com self.cookie('var3=bar;', 200) 14481308Szelenkov@nginx.com self.cookie('var1=bar', 404) 14491308Szelenkov@nginx.com self.cookie('var1=bar; var4=foo;', 200) 14501308Szelenkov@nginx.com self.cookie(['var1=bar', 'var4=foo'], 200) 14511068Szelenkov@nginx.com 14521596Szelenkov@nginx.com assert 'success' in self.conf_delete( 14531596Szelenkov@nginx.com 'routes/0/match/cookies/1' 14541596Szelenkov@nginx.com ), 'match cookies array configure 2' 14551068Szelenkov@nginx.com 14561308Szelenkov@nginx.com self.cookie('var2=val2', 404) 14571308Szelenkov@nginx.com self.cookie('var3=foo', 200) 14581068Szelenkov@nginx.com 14591110Saxel.duch@nginx.com def test_routes_match_scheme(self): 14601308Szelenkov@nginx.com self.route_match({"scheme": "http"}) 14611308Szelenkov@nginx.com self.route_match({"scheme": "https"}) 14621308Szelenkov@nginx.com self.route_match({"scheme": "HtTp"}) 14631308Szelenkov@nginx.com self.route_match({"scheme": "HtTpS"}) 14641110Saxel.duch@nginx.com 14651110Saxel.duch@nginx.com def test_routes_match_scheme_invalid(self): 14661308Szelenkov@nginx.com self.route_match_invalid({"scheme": ["http"]}) 14671308Szelenkov@nginx.com self.route_match_invalid({"scheme": "ftp"}) 14681308Szelenkov@nginx.com self.route_match_invalid({"scheme": "ws"}) 14691308Szelenkov@nginx.com self.route_match_invalid({"scheme": "*"}) 14701308Szelenkov@nginx.com self.route_match_invalid({"scheme": ""}) 14711308Szelenkov@nginx.com 14721325Saxel.duch@nginx.com def test_routes_source_port(self): 14731325Saxel.duch@nginx.com def sock_port(): 14741325Saxel.duch@nginx.com _, sock = self.http(b'', start=True, raw=True, no_recv=True) 14751325Saxel.duch@nginx.com port = sock.getsockname()[1] 14761325Saxel.duch@nginx.com return (sock, port) 14771325Saxel.duch@nginx.com 14781325Saxel.duch@nginx.com sock, port = sock_port() 14791325Saxel.duch@nginx.com sock2, port2 = sock_port() 14801325Saxel.duch@nginx.com 14811325Saxel.duch@nginx.com self.route_match({"source": "127.0.0.1:" + str(port)}) 14821596Szelenkov@nginx.com assert self.get(sock=sock)['status'] == 200, 'exact' 14831596Szelenkov@nginx.com assert self.get(sock=sock2)['status'] == 404, 'exact 2' 14841325Saxel.duch@nginx.com 14851325Saxel.duch@nginx.com sock, port = sock_port() 14861325Saxel.duch@nginx.com sock2, port2 = sock_port() 14871325Saxel.duch@nginx.com 14881325Saxel.duch@nginx.com self.route_match({"source": "!127.0.0.1:" + str(port)}) 14891596Szelenkov@nginx.com assert self.get(sock=sock)['status'] == 404, 'negative' 14901596Szelenkov@nginx.com assert self.get(sock=sock2)['status'] == 200, 'negative 2' 14911325Saxel.duch@nginx.com 14921325Saxel.duch@nginx.com sock, port = sock_port() 14931325Saxel.duch@nginx.com sock2, port2 = sock_port() 14941325Saxel.duch@nginx.com 14951391Szelenkov@nginx.com self.route_match({"source": ["*:" + str(port), "!127.0.0.1"]}) 14961596Szelenkov@nginx.com assert self.get(sock=sock)['status'] == 404, 'negative 3' 14971596Szelenkov@nginx.com assert self.get(sock=sock2)['status'] == 404, 'negative 4' 14981391Szelenkov@nginx.com 14991391Szelenkov@nginx.com sock, port = sock_port() 15001391Szelenkov@nginx.com sock2, port2 = sock_port() 15011391Szelenkov@nginx.com 1502*2073Szelenkov@nginx.com self.route_match({"source": "127.0.0.1:" + str(port) + "-" + str(port)}) 15031596Szelenkov@nginx.com assert self.get(sock=sock)['status'] == 200, 'range single' 15041596Szelenkov@nginx.com assert self.get(sock=sock2)['status'] == 404, 'range single 2' 15051325Saxel.duch@nginx.com 15061325Saxel.duch@nginx.com socks = [ 15071325Saxel.duch@nginx.com sock_port(), 15081325Saxel.duch@nginx.com sock_port(), 15091325Saxel.duch@nginx.com sock_port(), 15101325Saxel.duch@nginx.com sock_port(), 15111325Saxel.duch@nginx.com sock_port(), 15121325Saxel.duch@nginx.com ] 15131325Saxel.duch@nginx.com socks.sort(key=lambda sock: sock[1]) 15141325Saxel.duch@nginx.com 15151325Saxel.duch@nginx.com self.route_match( 15161325Saxel.duch@nginx.com { 15171325Saxel.duch@nginx.com "source": "127.0.0.1:" 15181325Saxel.duch@nginx.com + str(socks[1][1]) # second port number 15191325Saxel.duch@nginx.com + "-" 15201325Saxel.duch@nginx.com + str(socks[3][1]) # fourth port number 15211325Saxel.duch@nginx.com } 15221325Saxel.duch@nginx.com ) 15231596Szelenkov@nginx.com assert self.get(sock=socks[0][0])['status'] == 404, 'range' 15241596Szelenkov@nginx.com assert self.get(sock=socks[1][0])['status'] == 200, 'range 2' 15251596Szelenkov@nginx.com assert self.get(sock=socks[2][0])['status'] == 200, 'range 3' 15261596Szelenkov@nginx.com assert self.get(sock=socks[3][0])['status'] == 200, 'range 4' 15271596Szelenkov@nginx.com assert self.get(sock=socks[4][0])['status'] == 404, 'range 5' 15281325Saxel.duch@nginx.com 15291325Saxel.duch@nginx.com socks = [ 15301325Saxel.duch@nginx.com sock_port(), 15311325Saxel.duch@nginx.com sock_port(), 15321325Saxel.duch@nginx.com sock_port(), 15331325Saxel.duch@nginx.com ] 15341325Saxel.duch@nginx.com socks.sort(key=lambda sock: sock[1]) 15351325Saxel.duch@nginx.com 15361325Saxel.duch@nginx.com self.route_match( 15371325Saxel.duch@nginx.com { 15381325Saxel.duch@nginx.com "source": [ 15391325Saxel.duch@nginx.com "127.0.0.1:" + str(socks[0][1]), 15401325Saxel.duch@nginx.com "127.0.0.1:" + str(socks[2][1]), 15411325Saxel.duch@nginx.com ] 15421325Saxel.duch@nginx.com } 15431325Saxel.duch@nginx.com ) 15441596Szelenkov@nginx.com assert self.get(sock=socks[0][0])['status'] == 200, 'array' 15451596Szelenkov@nginx.com assert self.get(sock=socks[1][0])['status'] == 404, 'array 2' 15461596Szelenkov@nginx.com assert self.get(sock=socks[2][0])['status'] == 200, 'array 3' 15471325Saxel.duch@nginx.com 15481325Saxel.duch@nginx.com def test_routes_source_addr(self): 15491596Szelenkov@nginx.com assert 'success' in self.conf( 1550*2073Szelenkov@nginx.com { 1551*2073Szelenkov@nginx.com "*:7080": {"pass": "routes"}, 1552*2073Szelenkov@nginx.com "[::1]:7081": {"pass": "routes"}, 1553*2073Szelenkov@nginx.com }, 15541596Szelenkov@nginx.com 'listeners', 15551596Szelenkov@nginx.com ), 'source listeners configure' 15561325Saxel.duch@nginx.com 15571325Saxel.duch@nginx.com def get_ipv6(): 15581325Saxel.duch@nginx.com return self.get(sock_type='ipv6', port=7081) 15591325Saxel.duch@nginx.com 15601325Saxel.duch@nginx.com self.route_match({"source": "127.0.0.1"}) 15611596Szelenkov@nginx.com assert self.get()['status'] == 200, 'exact' 15621596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, 'exact ipv6' 15631325Saxel.duch@nginx.com 15641325Saxel.duch@nginx.com self.route_match({"source": ["127.0.0.1"]}) 15651596Szelenkov@nginx.com assert self.get()['status'] == 200, 'exact 2' 15661596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, 'exact 2 ipv6' 15671325Saxel.duch@nginx.com 15681325Saxel.duch@nginx.com self.route_match({"source": "!127.0.0.1"}) 15691596Szelenkov@nginx.com assert self.get()['status'] == 404, 'exact neg' 15701596Szelenkov@nginx.com assert get_ipv6()['status'] == 200, 'exact neg ipv6' 15711325Saxel.duch@nginx.com 15721325Saxel.duch@nginx.com self.route_match({"source": "127.0.0.2"}) 15731596Szelenkov@nginx.com assert self.get()['status'] == 404, 'exact 3' 15741596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, 'exact 3 ipv6' 15751325Saxel.duch@nginx.com 15761325Saxel.duch@nginx.com self.route_match({"source": "127.0.0.1-127.0.0.1"}) 15771596Szelenkov@nginx.com assert self.get()['status'] == 200, 'range single' 15781596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, 'range single ipv6' 15791325Saxel.duch@nginx.com 15801325Saxel.duch@nginx.com self.route_match({"source": "127.0.0.2-127.0.0.2"}) 15811596Szelenkov@nginx.com assert self.get()['status'] == 404, 'range single 2' 15821596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, 'range single 2 ipv6' 15831325Saxel.duch@nginx.com 15841325Saxel.duch@nginx.com self.route_match({"source": "127.0.0.2-127.0.0.3"}) 15851596Szelenkov@nginx.com assert self.get()['status'] == 404, 'range' 15861596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, 'range ipv6' 15871325Saxel.duch@nginx.com 15881325Saxel.duch@nginx.com self.route_match({"source": "127.0.0.1-127.0.0.2"}) 15891596Szelenkov@nginx.com assert self.get()['status'] == 200, 'range 2' 15901596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, 'range 2 ipv6' 15911325Saxel.duch@nginx.com 15921325Saxel.duch@nginx.com self.route_match({"source": "127.0.0.0-127.0.0.2"}) 15931596Szelenkov@nginx.com assert self.get()['status'] == 200, 'range 3' 15941596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, 'range 3 ipv6' 15951325Saxel.duch@nginx.com 15961325Saxel.duch@nginx.com self.route_match({"source": "127.0.0.0-127.0.0.1"}) 15971596Szelenkov@nginx.com assert self.get()['status'] == 200, 'range 4' 15981596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, 'range 4 ipv6' 15991325Saxel.duch@nginx.com 16001325Saxel.duch@nginx.com self.route_match({"source": "126.0.0.0-127.0.0.0"}) 16011596Szelenkov@nginx.com assert self.get()['status'] == 404, 'range 5' 16021596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, 'range 5 ipv6' 16031325Saxel.duch@nginx.com 16041325Saxel.duch@nginx.com self.route_match({"source": "126.126.126.126-127.0.0.2"}) 16051596Szelenkov@nginx.com assert self.get()['status'] == 200, 'range 6' 16061596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, 'range 6 ipv6' 16071325Saxel.duch@nginx.com 16081325Saxel.duch@nginx.com def test_routes_source_ipv6(self): 16091596Szelenkov@nginx.com assert 'success' in self.conf( 16101596Szelenkov@nginx.com { 16111596Szelenkov@nginx.com "[::1]:7080": {"pass": "routes"}, 16121596Szelenkov@nginx.com "127.0.0.1:7081": {"pass": "routes"}, 16131596Szelenkov@nginx.com }, 16141596Szelenkov@nginx.com 'listeners', 16151596Szelenkov@nginx.com ), 'source listeners configure' 16161325Saxel.duch@nginx.com 16171325Saxel.duch@nginx.com self.route_match({"source": "::1"}) 16181596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 200, 'exact' 16191596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, 'exact ipv4' 16201325Saxel.duch@nginx.com 16211325Saxel.duch@nginx.com self.route_match({"source": ["::1"]}) 16221596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 200, 'exact 2' 16231596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, 'exact 2 ipv4' 16241325Saxel.duch@nginx.com 16251325Saxel.duch@nginx.com self.route_match({"source": "!::1"}) 16261596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 404, 'exact neg' 16271596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 200, 'exact neg ipv4' 16281325Saxel.duch@nginx.com 16291325Saxel.duch@nginx.com self.route_match({"source": "::2"}) 16301596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 404, 'exact 3' 16311596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, 'exact 3 ipv4' 16321325Saxel.duch@nginx.com 16331325Saxel.duch@nginx.com self.route_match({"source": "::1-::1"}) 16341596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 200, 'range' 16351596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, 'range ipv4' 16361325Saxel.duch@nginx.com 16371325Saxel.duch@nginx.com self.route_match({"source": "::2-::2"}) 16381596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 404, 'range 2' 16391596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, 'range 2 ipv4' 16401325Saxel.duch@nginx.com 16411325Saxel.duch@nginx.com self.route_match({"source": "::2-::3"}) 16421596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 404, 'range 3' 16431596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, 'range 3 ipv4' 16441325Saxel.duch@nginx.com 16451325Saxel.duch@nginx.com self.route_match({"source": "::1-::2"}) 16461596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 200, 'range 4' 16471596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, 'range 4 ipv4' 16481325Saxel.duch@nginx.com 16491325Saxel.duch@nginx.com self.route_match({"source": "::0-::2"}) 16501596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 200, 'range 5' 16511596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, 'range 5 ipv4' 16521325Saxel.duch@nginx.com 16531325Saxel.duch@nginx.com self.route_match({"source": "::0-::1"}) 16541596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 200, 'range 6' 16551596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, 'range 6 ipv4' 16561325Saxel.duch@nginx.com 16571325Saxel.duch@nginx.com def test_routes_source_cidr(self): 16581596Szelenkov@nginx.com assert 'success' in self.conf( 1659*2073Szelenkov@nginx.com { 1660*2073Szelenkov@nginx.com "*:7080": {"pass": "routes"}, 1661*2073Szelenkov@nginx.com "[::1]:7081": {"pass": "routes"}, 1662*2073Szelenkov@nginx.com }, 16631596Szelenkov@nginx.com 'listeners', 16641596Szelenkov@nginx.com ), 'source listeners configure' 16651325Saxel.duch@nginx.com 16661325Saxel.duch@nginx.com def get_ipv6(): 16671325Saxel.duch@nginx.com return self.get(sock_type='ipv6', port=7081) 16681325Saxel.duch@nginx.com 16691325Saxel.duch@nginx.com self.route_match({"source": "127.0.0.1/32"}) 16701596Szelenkov@nginx.com assert self.get()['status'] == 200, '32' 16711596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, '32 ipv6' 16721325Saxel.duch@nginx.com 16731325Saxel.duch@nginx.com self.route_match({"source": "127.0.0.0/32"}) 16741596Szelenkov@nginx.com assert self.get()['status'] == 404, '32 2' 16751596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, '32 2 ipv6' 16761325Saxel.duch@nginx.com 16771325Saxel.duch@nginx.com self.route_match({"source": "127.0.0.0/31"}) 16781596Szelenkov@nginx.com assert self.get()['status'] == 200, '31' 16791596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, '31 ipv6' 16801325Saxel.duch@nginx.com 16811325Saxel.duch@nginx.com self.route_match({"source": "0.0.0.0/1"}) 16821596Szelenkov@nginx.com assert self.get()['status'] == 200, '1' 16831596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, '1 ipv6' 16841325Saxel.duch@nginx.com 16851325Saxel.duch@nginx.com self.route_match({"source": "0.0.0.0/0"}) 16861596Szelenkov@nginx.com assert self.get()['status'] == 200, '0' 16871596Szelenkov@nginx.com assert get_ipv6()['status'] == 404, '0 ipv6' 16881325Saxel.duch@nginx.com 16891325Saxel.duch@nginx.com def test_routes_source_cidr_ipv6(self): 16901596Szelenkov@nginx.com assert 'success' in self.conf( 16911596Szelenkov@nginx.com { 16921596Szelenkov@nginx.com "[::1]:7080": {"pass": "routes"}, 16931596Szelenkov@nginx.com "127.0.0.1:7081": {"pass": "routes"}, 16941596Szelenkov@nginx.com }, 16951596Szelenkov@nginx.com 'listeners', 16961596Szelenkov@nginx.com ), 'source listeners configure' 16971325Saxel.duch@nginx.com 16981325Saxel.duch@nginx.com self.route_match({"source": "::1/128"}) 16991596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 200, '128' 17001596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, '128 ipv4' 17011325Saxel.duch@nginx.com 17021325Saxel.duch@nginx.com self.route_match({"source": "::0/128"}) 17031596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 404, '128 2' 17041596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, '128 ipv4' 17051325Saxel.duch@nginx.com 17061325Saxel.duch@nginx.com self.route_match({"source": "::0/127"}) 17071596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 200, '127' 17081596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, '127 ipv4' 17091325Saxel.duch@nginx.com 17101325Saxel.duch@nginx.com self.route_match({"source": "::0/32"}) 17111596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 200, '32' 17121596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, '32 ipv4' 17131325Saxel.duch@nginx.com 17141325Saxel.duch@nginx.com self.route_match({"source": "::0/1"}) 17151596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 200, '1' 17161596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, '1 ipv4' 17171325Saxel.duch@nginx.com 17181325Saxel.duch@nginx.com self.route_match({"source": "::/0"}) 17191596Szelenkov@nginx.com assert self.get(sock_type='ipv6')['status'] == 200, '0' 17201596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, '0 ipv4' 17211325Saxel.duch@nginx.com 17221654Szelenkov@nginx.com def test_routes_source_unix(self, temp_dir): 17231654Szelenkov@nginx.com addr = temp_dir + '/sock' 17241325Saxel.duch@nginx.com 17251596Szelenkov@nginx.com assert 'success' in self.conf( 17261596Szelenkov@nginx.com {"unix:" + addr: {"pass": "routes"}}, 'listeners' 17271596Szelenkov@nginx.com ), 'source listeners configure' 17281325Saxel.duch@nginx.com 17291325Saxel.duch@nginx.com self.route_match({"source": "!0.0.0.0/0"}) 17301596Szelenkov@nginx.com assert ( 17311596Szelenkov@nginx.com self.get(sock_type='unix', addr=addr)['status'] == 200 17321596Szelenkov@nginx.com ), 'unix ipv4' 17331325Saxel.duch@nginx.com 17341325Saxel.duch@nginx.com self.route_match({"source": "!::/0"}) 17351596Szelenkov@nginx.com assert ( 17361596Szelenkov@nginx.com self.get(sock_type='unix', addr=addr)['status'] == 200 17371596Szelenkov@nginx.com ), 'unix ipv6' 17381325Saxel.duch@nginx.com 17391325Saxel.duch@nginx.com def test_routes_match_source(self): 17401325Saxel.duch@nginx.com self.route_match({"source": "::"}) 17411325Saxel.duch@nginx.com self.route_match( 17421325Saxel.duch@nginx.com { 17431325Saxel.duch@nginx.com "source": [ 17441325Saxel.duch@nginx.com "127.0.0.1", 17451325Saxel.duch@nginx.com "192.168.0.10:8080", 17461325Saxel.duch@nginx.com "192.168.0.11:8080-8090", 17471325Saxel.duch@nginx.com ] 17481325Saxel.duch@nginx.com } 17491325Saxel.duch@nginx.com ) 17501325Saxel.duch@nginx.com self.route_match( 17511325Saxel.duch@nginx.com { 17521325Saxel.duch@nginx.com "source": [ 17531325Saxel.duch@nginx.com "10.0.0.0/8", 17541325Saxel.duch@nginx.com "10.0.0.0/7:1000", 17551325Saxel.duch@nginx.com "10.0.0.0/32:8080-8090", 17561325Saxel.duch@nginx.com ] 17571325Saxel.duch@nginx.com } 17581325Saxel.duch@nginx.com ) 17591325Saxel.duch@nginx.com self.route_match( 17601325Saxel.duch@nginx.com { 17611325Saxel.duch@nginx.com "source": [ 17621325Saxel.duch@nginx.com "10.0.0.0-10.0.0.1", 17631325Saxel.duch@nginx.com "10.0.0.0-11.0.0.0:1000", 17641325Saxel.duch@nginx.com "127.0.0.0-127.0.0.255:8080-8090", 17651325Saxel.duch@nginx.com ] 17661325Saxel.duch@nginx.com } 17671325Saxel.duch@nginx.com ) 17681325Saxel.duch@nginx.com self.route_match( 17691325Saxel.duch@nginx.com {"source": ["2001::", "[2002::]:8000", "[2003::]:8080-8090"]} 17701325Saxel.duch@nginx.com ) 17711325Saxel.duch@nginx.com self.route_match( 17721325Saxel.duch@nginx.com { 17731325Saxel.duch@nginx.com "source": [ 17741325Saxel.duch@nginx.com "2001::-200f:ffff:ffff:ffff:ffff:ffff:ffff:ffff", 17751325Saxel.duch@nginx.com "[fe08::-feff::]:8000", 17761325Saxel.duch@nginx.com "[fff0::-fff0::10]:8080-8090", 17771325Saxel.duch@nginx.com ] 17781325Saxel.duch@nginx.com } 17791325Saxel.duch@nginx.com ) 17801325Saxel.duch@nginx.com self.route_match( 17811325Saxel.duch@nginx.com { 17821325Saxel.duch@nginx.com "source": [ 17831325Saxel.duch@nginx.com "2001::/16", 17841325Saxel.duch@nginx.com "[0ff::/64]:8000", 17851325Saxel.duch@nginx.com "[fff0:abcd:ffff:ffff:ffff::/128]:8080-8090", 17861325Saxel.duch@nginx.com ] 17871325Saxel.duch@nginx.com } 17881325Saxel.duch@nginx.com ) 17891325Saxel.duch@nginx.com self.route_match({"source": "*:0-65535"}) 17901596Szelenkov@nginx.com assert self.get()['status'] == 200, 'source any' 17911325Saxel.duch@nginx.com 17921325Saxel.duch@nginx.com def test_routes_match_source_invalid(self): 17931325Saxel.duch@nginx.com self.route_match_invalid({"source": "127"}) 17941325Saxel.duch@nginx.com self.route_match_invalid({"source": "256.0.0.1"}) 17951325Saxel.duch@nginx.com self.route_match_invalid({"source": "127.0.0."}) 17961391Szelenkov@nginx.com self.route_match_invalid({"source": " 127.0.0.1"}) 17971325Saxel.duch@nginx.com self.route_match_invalid({"source": "127.0.0.1:"}) 17981325Saxel.duch@nginx.com self.route_match_invalid({"source": "127.0.0.1/"}) 17991325Saxel.duch@nginx.com self.route_match_invalid({"source": "11.0.0.0/33"}) 18001325Saxel.duch@nginx.com self.route_match_invalid({"source": "11.0.0.0/65536"}) 18011325Saxel.duch@nginx.com self.route_match_invalid({"source": "11.0.0.0-10.0.0.0"}) 18021325Saxel.duch@nginx.com self.route_match_invalid({"source": "11.0.0.0:3000-2000"}) 18031325Saxel.duch@nginx.com self.route_match_invalid({"source": ["11.0.0.0:3000-2000"]}) 18041325Saxel.duch@nginx.com self.route_match_invalid({"source": "[2001::]:3000-2000"}) 18051325Saxel.duch@nginx.com self.route_match_invalid({"source": "2001::-2000::"}) 18061325Saxel.duch@nginx.com self.route_match_invalid({"source": "2001::/129"}) 18071325Saxel.duch@nginx.com self.route_match_invalid({"source": "::FFFFF"}) 18081325Saxel.duch@nginx.com self.route_match_invalid({"source": "[::1]:"}) 18091370Szelenkov@nginx.com self.route_match_invalid({"source": "[:::]:7080"}) 18101325Saxel.duch@nginx.com self.route_match_invalid({"source": "*:"}) 18111325Saxel.duch@nginx.com self.route_match_invalid({"source": "*:1-a"}) 18121325Saxel.duch@nginx.com self.route_match_invalid({"source": "*:65536"}) 18131325Saxel.duch@nginx.com 18141930So.canty@f5.com def test_routes_match_source_none(self): 18151930So.canty@f5.com self.route_match({"source": []}) 18161930So.canty@f5.com assert self.get()['status'] == 404, 'source none' 18171930So.canty@f5.com 18181327Saxel.duch@nginx.com def test_routes_match_destination(self): 18191596Szelenkov@nginx.com assert 'success' in self.conf( 18201596Szelenkov@nginx.com {"*:7080": {"pass": "routes"}, "*:7081": {"pass": "routes"}}, 18211596Szelenkov@nginx.com 'listeners', 18221596Szelenkov@nginx.com ), 'listeners configure' 18231327Saxel.duch@nginx.com 18241327Saxel.duch@nginx.com self.route_match({"destination": "*:7080"}) 18251596Szelenkov@nginx.com assert self.get()['status'] == 200, 'dest' 18261596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, 'dest 2' 18271327Saxel.duch@nginx.com 18281327Saxel.duch@nginx.com self.route_match({"destination": ["127.0.0.1:7080"]}) 18291596Szelenkov@nginx.com assert self.get()['status'] == 200, 'dest 3' 18301596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, 'dest 4' 18311327Saxel.duch@nginx.com 18321327Saxel.duch@nginx.com self.route_match({"destination": "!*:7080"}) 18331596Szelenkov@nginx.com assert self.get()['status'] == 404, 'dest neg' 18341596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 200, 'dest neg 2' 18351327Saxel.duch@nginx.com 18361391Szelenkov@nginx.com self.route_match({"destination": ['!*:7080', '!*:7081']}) 18371596Szelenkov@nginx.com assert self.get()['status'] == 404, 'dest neg 3' 18381596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, 'dest neg 4' 18391391Szelenkov@nginx.com 18401391Szelenkov@nginx.com self.route_match({"destination": ['!*:7081', '!*:7082']}) 18411596Szelenkov@nginx.com assert self.get()['status'] == 200, 'dest neg 5' 18421391Szelenkov@nginx.com 18431391Szelenkov@nginx.com self.route_match({"destination": ['*:7080', '!*:7080']}) 18441596Szelenkov@nginx.com assert self.get()['status'] == 404, 'dest neg 6' 18451391Szelenkov@nginx.com 18461391Szelenkov@nginx.com self.route_match( 18471391Szelenkov@nginx.com {"destination": ['127.0.0.1:7080', '*:7081', '!*:7080']} 18481391Szelenkov@nginx.com ) 18491596Szelenkov@nginx.com assert self.get()['status'] == 404, 'dest neg 7' 18501596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 200, 'dest neg 8' 18511391Szelenkov@nginx.com 18521391Szelenkov@nginx.com self.route_match({"destination": ['!*:7081', '!*:7082', '*:7083']}) 18531596Szelenkov@nginx.com assert self.get()['status'] == 404, 'dest neg 9' 18541391Szelenkov@nginx.com 18551391Szelenkov@nginx.com self.route_match( 18561391Szelenkov@nginx.com {"destination": ['*:7081', '!127.0.0.1:7080', '*:7080']} 18571391Szelenkov@nginx.com ) 18581596Szelenkov@nginx.com assert self.get()['status'] == 404, 'dest neg 10' 18591596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 200, 'dest neg 11' 18601391Szelenkov@nginx.com 18611596Szelenkov@nginx.com assert 'success' in self.conf_delete( 18621596Szelenkov@nginx.com 'routes/0/match/destination/0' 18631596Szelenkov@nginx.com ), 'remove destination rule' 18641596Szelenkov@nginx.com assert self.get()['status'] == 404, 'dest neg 12' 18651596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, 'dest neg 13' 18661391Szelenkov@nginx.com 18671596Szelenkov@nginx.com assert 'success' in self.conf_delete( 18681596Szelenkov@nginx.com 'routes/0/match/destination/0' 18691596Szelenkov@nginx.com ), 'remove destination rule 2' 18701596Szelenkov@nginx.com assert self.get()['status'] == 200, 'dest neg 14' 18711596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, 'dest neg 15' 18721391Szelenkov@nginx.com 18731596Szelenkov@nginx.com assert 'success' in self.conf_post( 18741596Szelenkov@nginx.com "\"!127.0.0.1\"", 'routes/0/match/destination' 18751596Szelenkov@nginx.com ), 'add destination rule' 18761596Szelenkov@nginx.com assert self.get()['status'] == 404, 'dest neg 16' 18771596Szelenkov@nginx.com assert self.get(port=7081)['status'] == 404, 'dest neg 17' 18781391Szelenkov@nginx.com 18791327Saxel.duch@nginx.com def test_routes_match_destination_proxy(self): 18801596Szelenkov@nginx.com assert 'success' in self.conf( 18811596Szelenkov@nginx.com { 18821596Szelenkov@nginx.com "listeners": { 18831596Szelenkov@nginx.com "*:7080": {"pass": "routes/first"}, 18841596Szelenkov@nginx.com "*:7081": {"pass": "routes/second"}, 18851596Szelenkov@nginx.com }, 18861596Szelenkov@nginx.com "routes": { 18871596Szelenkov@nginx.com "first": [{"action": {"proxy": "http://127.0.0.1:7081"}}], 18881596Szelenkov@nginx.com "second": [ 18891596Szelenkov@nginx.com { 18901596Szelenkov@nginx.com "match": {"destination": ["127.0.0.1:7081"]}, 18911596Szelenkov@nginx.com "action": {"return": 200}, 18921596Szelenkov@nginx.com } 18931596Szelenkov@nginx.com ], 18941596Szelenkov@nginx.com }, 18951596Szelenkov@nginx.com "applications": {}, 18961596Szelenkov@nginx.com } 18971596Szelenkov@nginx.com ), 'proxy configure' 18981327Saxel.duch@nginx.com 18991596Szelenkov@nginx.com assert self.get()['status'] == 200, 'proxy' 1900