diff options
author | hongzhidao <hongzhidao@gmail.com> | 2020-08-28 00:53:36 -0400 |
---|---|---|
committer | hongzhidao <hongzhidao@gmail.com> | 2020-08-28 00:53:36 -0400 |
commit | 806135f1c93c09bb513efc1341d084951b080278 (patch) | |
tree | fad5c6e1fbdcc4be78fb289546ebcfdfbb0aec32 /test/test_routing.py | |
parent | d5e915934066c77a59d211efafca10c117b73d05 (diff) | |
download | unit-806135f1c93c09bb513efc1341d084951b080278.tar.gz unit-806135f1c93c09bb513efc1341d084951b080278.tar.bz2 |
Router: fixed "pass" to upstreams.
Messed up return values in nxt_upstream_find() caused error in applying any
configuration with a valid "pass" value in router configuration pointing to
upstream. That wasn't the case in "listeners" objects, where the return value
wasn't checked.
Also, it caused segfault in cases where the "pass" option was configured with
variables and resulting value was pointing to a non-existent upstream.
Added missing return checks as well to catch possible memory allocation errors.
The bug was introduced in d32bc428f46b.
This closes #472 issue on GitHub.
Diffstat (limited to 'test/test_routing.py')
-rw-r--r-- | test/test_routing.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/test/test_routing.py b/test/test_routing.py index 4107f57e..734825ef 100644 --- a/test/test_routing.py +++ b/test/test_routing.py @@ -329,11 +329,90 @@ class TestRouting(TestApplicationProto): [{"match": {"method": "GET"}}], 'routes' ), 'route pass absent configure' + def test_routes_route_pass(self): + assert 'success' in self.conf( + { + "applications": { + "app": { + "type": "python", + "processes": {"spare": 0}, + "path": "/app", + "module": "wsgi", + } + }, + "upstreams": { + "one": { + "servers": { + "127.0.0.1:7081": {}, + "127.0.0.1:7082": {}, + }, + }, + "two": { + "servers": { + "127.0.0.1:7081": {}, + "127.0.0.1:7082": {}, + }, + }, + }, + } + ) + + assert 'success' in self.conf( + [{"action": {"pass": "routes"}}], 'routes' + ) + assert 'success' in self.conf( + [{"action": {"pass": "applications/app"}}], 'routes' + ) + assert 'success' in self.conf( + [{"action": {"pass": "upstreams/one"}}], 'routes' + ) + def test_routes_route_pass_absent(self): assert 'error' in self.conf( [{"match": {"method": "GET"}, "action": {}}], 'routes' ), 'route pass absent configure' + def test_routes_route_pass_invalid(self): + assert 'success' in self.conf( + { + "applications": { + "app": { + "type": "python", + "processes": {"spare": 0}, + "path": "/app", + "module": "wsgi", + } + }, + "upstreams": { + "one": { + "servers": { + "127.0.0.1:7081": {}, + "127.0.0.1:7082": {}, + }, + }, + "two": { + "servers": { + "127.0.0.1:7081": {}, + "127.0.0.1:7082": {}, + }, + }, + }, + } + ) + + assert 'error' in self.conf( + [{"action": {"pass": "blah"}}], 'routes' + ), 'route pass invalid' + assert 'error' in self.conf( + [{"action": {"pass": "routes/blah"}}], 'routes' + ), 'route pass routes invalid' + assert 'error' in self.conf( + [{"action": {"pass": "applications/blah"}}], 'routes' + ), 'route pass applications invalid' + assert 'error' in self.conf( + [{"action": {"pass": "upstreams/blah"}}], 'routes' + ), 'route pass upstreams invalid' + def test_routes_action_unique(self): assert 'success' in self.conf( { |