Skip to content

Commit 2063fa2

Browse files
committed
3.2.3 (2024-02-01)
1 parent ef587a3 commit 2063fa2

File tree

8 files changed

+75
-23
lines changed

8 files changed

+75
-23
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ instead of
2323
permit host 10.0.0.1
2424
2525
26-
3.2.2 (2024-02-01)
26+
3.2.3 (2024-02-01)
2727
------------------
2828
**Fixed:** ip access-list standard, permit A.B.C.D (without host keyword)
2929

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ or install the package from github.com release
6060

6161
.. code:: bash
6262
63-
pip install https://github.com/vladimirs-git/cisco-acl/archive/refs/tags/3.2.2.tar.gz
63+
pip install https://github.com/vladimirs-git/cisco-acl/archive/refs/tags/3.2.3.tar.gz
6464
6565
or install the package from github.com repository
6666

cisco_acl/option.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""ACE. Option."""
22
from __future__ import annotations
33

4+
import string
45
from functools import total_ordering
56

67
from cisco_acl import helpers as h
@@ -70,10 +71,14 @@ def line(self, line: str) -> None:
7071
line = h.init_line(line)
7172
self._line = line
7273

73-
items: LStr = [s.strip() for s in line.split()]
74-
items = [s for s in items if s]
75-
self._flags = [s for s in items if s not in LOGS]
76-
self._logs = [s for s in items if s in LOGS]
74+
options: LStr = [s.strip() for s in line.split()]
75+
options = [s for s in options if s]
76+
for option in options:
77+
if option[0] not in string.ascii_lowercase:
78+
raise ValueError(f"invalid {option=}")
79+
80+
self._flags = [s for s in options if s not in LOGS]
81+
self._logs = [s for s in options if s in LOGS]
7782

7883
@property
7984
def logs(self) -> LStr:

examples/examples_acl_standard.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
ip access-list standard ACL1
77
permit 10.0.0.1
88
permit host 10.0.0.2
9-
permit host 10.0.0.3 0.0.0.0
9+
permit 10.0.0.3 0.0.0.0
1010
permit 10.0.0.4 0.0.0.3
11+
permit 10.0.0.5 0.0.0.3
1112
"""
1213

1314
# Create ACL.
@@ -16,7 +17,8 @@
1617
# ip access-list standard ACL1
1718
# permit host 10.0.0.1
1819
# permit host 10.0.0.2
19-
# permit host 10.0.0.3 0.0.0.0
20+
# permit host 10.0.0.3
21+
# permit 10.0.0.4 0.0.0.3
2022
# permit 10.0.0.4 0.0.0.3
2123

2224
# todo
@@ -25,5 +27,6 @@
2527
# ip access-list standard ACL1
2628
# permit 10.0.0.1
2729
# permit 10.0.0.2
28-
# permit 10.0.0.3 0.0.0.0
30+
# permit 10.0.0.3
31+
# permit 10.0.0.4 0.0.0.3
2932
# permit 10.0.0.4 0.0.0.3

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cisco_acl"
3-
version = "3.2.2"
3+
version = "3.2.3"
44
description = "Python package to parse and manage Cisco ACL (Access Control List)"
55
authors = ["Vladimirs Prusakovs <vladimir.prusakovs@gmail.com>"]
66
readme = "README.rst"
@@ -40,7 +40,7 @@ test = ["pytest"]
4040

4141
[tool.poetry.urls]
4242
"Bug Tracker" = "https://github.com/vladimirs-git/cisco-acl/issues"
43-
"Download URL" = "https://github.com/vladimirs-git/cisco-acl/archive/refs/tags/3.2.2.tar.gz"
43+
"Download URL" = "https://github.com/vladimirs-git/cisco-acl/archive/refs/tags/3.2.3.tar.gz"
4444

4545
[tool.pylint]
4646
max-line-length = 100

tests/test__ace.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,25 @@ def test_valid__ungroup_ports(self):
11411141
result = [o.line for o in aces]
11421142
self.assertEqual(result, req, msg=f"{line=}")
11431143

1144+
def test_valid__check_parsed_elements(self):
1145+
"""Ace._check_parsed_elements()"""
1146+
for data, req, in [
1147+
(dict(protocol="ip", srcport="", dstport=""), True),
1148+
]:
1149+
result = Ace._check_parsed_elements(line="", data=data)
1150+
self.assertEqual(result, req, msg=f"{data=}")
1151+
1152+
def test_invalid__check_parsed_elements(self):
1153+
"""Ace._check_parsed_elements()"""
1154+
for data, error, in [
1155+
(dict(protocol="", srcport="", dstport=""), ValueError),
1156+
(dict(protocol="ip", srcport="1", dstport=""), ValueError),
1157+
(dict(protocol="ip", srcport="", dstport="1"), ValueError),
1158+
(dict(protocol="ip", srcport="1", dstport="1"), ValueError),
1159+
]:
1160+
with self.assertRaises(error, msg=f"{data=}"):
1161+
Ace._check_parsed_elements(line="", data=data)
1162+
11441163

11451164
if __name__ == "__main__":
11461165
unittest.main()

tests/test__acl.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,23 @@ def test_valid__line(self):
213213
obj.line = kwargs["line"]
214214
self._test_attrs(obj=obj, req_d=req_d, msg=f"{kwargs=}")
215215

216-
def test_invalid__line(self):
217-
"""Acl.line"""
216+
def test_invalid__line__skip(self):
217+
"""Acl.line skip invalid line"""
218+
expected = ACL_NAME_IOS
219+
for line in [
220+
f"{ACL_NAME_IOS}\npermit ip any any 0.0.0.0" # option
221+
f"{ACL_NAME_IOS_STD}\npermit host 10.0.0.1 0.0.0.0" # option
222+
]:
223+
obj = Acl(line, platform="ios")
224+
result = str(obj).strip()
225+
self.assertEqual(result, expected, msg=f"{line=}")
226+
227+
def test_invalid__line__error(self):
228+
"""Acl.line raise error"""
218229
for line, error, in [
219230
("ip access-list extended\n permit ip any any", ValueError), # no name
220231
("ip access-listy\n permit ip any any", ValueError), # no name
221-
("ip access-list extended NAME NAME\n permit ip any any", ValueError), # 2 names
232+
(f"{ACL_NAME_IOS} NAME\n permit ip any any", ValueError), # 2 names
222233
(PERMIT_IP, ValueError),
223234
]:
224235
with self.assertRaises(error, msg=f"{line=}"):
@@ -341,12 +352,15 @@ def test_valid__type(self):
341352
host_ext = f"{ACL_NAME_IOS}\n" \
342353
f" {REMARK}\n" \
343354
f" permit tcp host 10.0.0.1 eq 1 host 10.0.0.2 eq 2 ack log"
344-
host_std = f"{ACL_NAME_IOS_STD}\n" \
345-
f" {REMARK}\n" \
346-
f" permit host 10.0.0.1"
347-
host_std_ = f"{ACL_NAME_IOS_STD}\n" \
355+
host1_std = f"{ACL_NAME_IOS_STD}\n" \
356+
f" {REMARK}\n" \
357+
f" permit host 10.0.0.1"
358+
host2_std = f"{ACL_NAME_IOS_STD}\n" \
348359
f" {REMARK}\n" \
349360
f" permit 10.0.0.1"
361+
host3_std = f"{ACL_NAME_IOS_STD}\n" \
362+
f" {REMARK}\n" \
363+
f" permit 10.0.0.1 0.0.0.0"
350364
host_ext_ = f"{ACL_NAME_IOS}\n" \
351365
f" {REMARK}\n permit ip host 10.0.0.1 any"
352366
wild_ext = f"{ACL_NAME_IOS}\n" \
@@ -379,17 +393,19 @@ def test_valid__type(self):
379393
("extended", "extended", wild_ext, wild_ext),
380394
("extended", "extended", aceg_ext, aceg_ext),
381395
# extended to standard
382-
("extended", "standard", host_ext, host_std),
396+
("extended", "standard", host_ext, host1_std),
383397
("extended", "standard", wild_ext, wild_std),
384398
("extended", "standard", aceg_ext, aceg_std),
385399
# standard to standard
386-
("standard", "standard", host_std, host_std),
387-
("standard", "standard", host_std_, host_std),
400+
("standard", "standard", host1_std, host1_std),
401+
("standard", "standard", host2_std, host1_std),
402+
("standard", "standard", host3_std, host1_std),
388403
("standard", "standard", wild_std, wild_std),
389404
("standard", "standard", aceg_std, aceg_std),
390405
# standard to extended
391-
("standard", "extended", host_std, host_ext_),
392-
("standard", "extended", host_std_, host_ext_),
406+
("standard", "extended", host1_std, host_ext_),
407+
("standard", "extended", host2_std, host_ext_),
408+
("standard", "extended", host3_std, host_ext_),
393409
("standard", "extended", wild_std, wild_ext_),
394410
("standard", "extended", aceg_std, aceg_ext_),
395411
]:

tests/test__option.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ def test_valid__line(self):
6767
obj1.line = line
6868
self._test_attrs(obj=obj1, req_d=req_d, msg=f"{line=}")
6969

70+
def test_invalid__line(self):
71+
"""Option.line()"""
72+
for platform in h.PLATFORMS:
73+
for line, error in [
74+
("1", ValueError),
75+
]:
76+
with self.assertRaises(error, msg=f"{line=}"):
77+
Option(line=line, platform=platform)
78+
7079
def test_valid__platform(self):
7180
"""Option.platform()"""
7281
option_d = dict(line="syn")

0 commit comments

Comments
 (0)