File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -210,6 +210,61 @@ def test_rules_no_src_dest(self):
210210 )
211211 self .assertEqual (o .render (), expected )
212212
213+ def test_render_rule_wrong (self ):
214+ rule = {
215+ "ip_rules" : [
216+ {
217+ "in" : "eth0" ,
218+ "out" : "eth1" ,
219+ "src" : "wrong" ,
220+ "dest" : "wrong" ,
221+ "tos" : 2 ,
222+ "action" : "blackhole"
223+ }
224+ ]
225+ }
226+ o = OpenWrt (rule )
227+ try :
228+ o .validate ()
229+ except ValidationError as e :
230+ # check error message
231+ pass
232+ else :
233+ self .fail ('ValidationError not raised' )
234+ # fix 'src' and expect wrong 'dest' to fail
235+ rule ['src' ] = '192.168.1.1/24'
236+ o = OpenWrt (rule )
237+ try :
238+ o .validate ()
239+ except ValidationError as e :
240+ # check error message
241+ pass
242+ else :
243+ self .fail ('ValidationError not raised' )
244+ # fix 'dest' and expect no ValidationError raised
245+ rule ['src' ] = '192.168.1.1/24'
246+ o = OpenWrt (rule )
247+ o .validate ()
248+
249+ def test_parse_rules_zone (self ):
250+ o = OpenWrt (native = """package network
251+
252+ config rule 'rule1'
253+ option action 'blackhole'
254+ option dest 'wrong'
255+ option in 'eth0'
256+ option out 'eth1'
257+ option src 'wrong'
258+ option tos '2'
259+ """ )
260+ try :
261+ o .validate ()
262+ except ValidationError as e :
263+ # check error message
264+ pass
265+ else :
266+ self .fail ('ValidationError not raised' )
267+
213268 _switch_netjson = {
214269 "switch" : [
215270 {
You can’t perform that action at this time.
0 commit comments