File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -471,6 +471,13 @@ def loads(data, conf=True):
471471 index += m .end ()
472472 continue
473473
474+ m = re .compile (r'^\s*limit_except\s*(.*?)\s*{' , re .S ).search (data [index :])
475+ if m :
476+ l = LimitExcept (m .group (1 ))
477+ lopen .insert (0 , l )
478+ index += m .end ()
479+ continue
480+
474481 m = re .compile (r'^(\s*)#\s*(.*?)\n' , re .S ).search (data [index :])
475482 if m :
476483 c = Comment (m .group (2 ), inline = '\n ' not in m .group (1 ))
Original file line number Diff line number Diff line change 155155}
156156"""
157157
158+ TESTBLOCK_CASE_8 = """
159+ location /M01 {
160+ proxy_pass http://backend;
161+ limit_except GET POST {deny all;}
162+ }
163+ """
158164
159165
160166class TestPythonNginx (unittest .TestCase ):
@@ -241,6 +247,18 @@ def test_filtering(self):
241247 self .assertEqual (len (data .server .filter ('Key' , 'mykey' )), 1 )
242248 self .assertEqual (data .server .filter ('Key' , 'nothere' ), [])
243249
250+ def test_limit_expect (self ):
251+ data = nginx .loads (TESTBLOCK_CASE_8 )
252+ self .assertEqual (len (data .filter ("Location" )), 1 )
253+ self .assertEqual (len (data .filter ("Location" )[0 ].children ), 2 )
254+ self .assertEqual (len (data .filter ("Location" )[0 ].filter ("LimitExcept" )), 1 )
255+ limit_except = data .filter ("Location" )[0 ].filter ("LimitExcept" )[0 ]
256+ self .assertEqual (limit_except .value , "GET POST" )
257+ self .assertEqual (len (limit_except .children ), 1 )
258+ first_key = limit_except .filter ("Key" )[0 ]
259+ self .assertEqual (first_key .name , "deny" )
260+ self .assertEqual (first_key .value , "all" )
261+
244262
245263if __name__ == '__main__' :
246264 unittest .main ()
You can’t perform that action at this time.
0 commit comments