Skip to content

Commit e65f06c

Browse files
[openwrt] Add firewall rule test
1 parent 4aa5e9e commit e65f06c

1 file changed

Lines changed: 70 additions & 1 deletion

File tree

tests/openwrt/test_firewall.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ def test_parse_rule_4(self):
189189
"proto": ["udp"],
190190
"dest_port": "67-68",
191191
"target": "ACCEPT",
192-
193192
}
194193
]
195194
}
@@ -221,6 +220,76 @@ def test_parse_rule_5(self):
221220
o = OpenWrt(native=self._rule_5_uci)
222221
self.assertEqual(o.config, self._rule_5_netjson)
223222

223+
_rule_6_netjson = {
224+
"firewall": {
225+
"rules": [
226+
{
227+
"name": "Allow-Isolated-DHCP",
228+
"src_ip": "10.10.10.10",
229+
"src_mac": "fc:aa:14:18:12:98",
230+
"src": "isolated",
231+
"proto": ["udp"],
232+
"dest_port": "67-68",
233+
"target": "ACCEPT",
234+
"dest": "dest_zone",
235+
"dest_ip": "192.168.1.2",
236+
"ipset": "my_ipset",
237+
"mark": "DROP",
238+
"start_date": "2021-01-21",
239+
"stop_date": "2021-01-22",
240+
"start_time": "01:01:01",
241+
"stop_time": "11:11:11",
242+
"weekdays": ["sun", "mon"],
243+
"monthdays": [2, 10],
244+
"utc_time": True,
245+
"family": "any",
246+
"limit": "3/second",
247+
"limit_burst": 30,
248+
"enabled": True,
249+
}
250+
]
251+
}
252+
}
253+
254+
_rule_6_uci = textwrap.dedent(
255+
"""\
256+
package firewall
257+
258+
config defaults 'defaults'
259+
260+
config rule 'rule_Allow_Isolated_DHCP'
261+
option name 'Allow-Isolated-DHCP'
262+
option src_ip '10.10.10.10'
263+
option src_mac 'fc:aa:14:18:12:98'
264+
option src 'isolated'
265+
option proto 'udp'
266+
option dest_port '67-68'
267+
option target 'ACCEPT'
268+
option dest 'dest_zone'
269+
option dest_ip '192.168.1.2'
270+
option ipset 'my_ipset'
271+
option mark 'DROP'
272+
option start_date '2021-01-21'
273+
option stop_date '2021-01-22'
274+
option start_time '01:01:01'
275+
option stop_time '11:11:11'
276+
list weekdays 'sun'
277+
list weekdays 'mon'
278+
list monthdays '2'
279+
list monthdays '10'
280+
option utc_time '1'
281+
option family 'any'
282+
option limit '3/second'
283+
option limit_burst '30'
284+
option enabled '1'
285+
"""
286+
)
287+
288+
def test_render_rule_6(self):
289+
o = OpenWrt(self._rule_6_netjson)
290+
expected = self._tabs(self._rule_6_uci)
291+
self.assertEqual(o.render(), expected)
292+
224293
_zone_1_netjson = {
225294
"firewall": {
226295
"zones": [

0 commit comments

Comments
 (0)