Router: fixed segmentation fault.

In the case that routes or upstreams is empty and the pass option is a variable.
If the resolved pass is routes or upstreams, a segment error occurred.
This commit is contained in:
Zhidao HONG
2021-08-02 12:30:38 +08:00
parent db03dfad67
commit d16cf04167
3 changed files with 27 additions and 0 deletions

View File

@@ -100,6 +100,25 @@ class TestVariables(TestApplicationProto):
assert self.get(url='/1')['status'] == 200
assert self.get(url='/2')['status'] == 404
def test_variables_empty(self):
def update_pass(prefix):
assert 'success' in self.conf(
{
"listeners": {
"*:7080": {"pass": prefix + "/$method"},
},
},
), 'variables empty'
update_pass("routes");
assert self.get(url='/1')['status'] == 404
update_pass("upstreams");
assert self.get(url='/2')['status'] == 404
update_pass("applications");
assert self.get(url='/3')['status'] == 404
def test_variables_invalid(self):
def check_variables(routes):
assert 'error' in self.conf(