Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions capirca/lib/cisco.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def __str__(self):
elif self.term.protocol == ['hopopt']:
protocol = ['hbh']
elif self.proto_int:
protocol = [proto if proto in self.ALLOWED_PROTO_STRINGS
protocol = [proto if proto in self.ALLOWED_PROTO_STRINGS or proto.isnumeric()
else self.PROTO_MAP.get(proto)
for proto in self.term.protocol]
else:
Expand Down Expand Up @@ -835,7 +835,7 @@ def __str__(self):
protocol = ['ip']

else:
protocol = [proto if proto in self.ALLOWED_PROTO_STRINGS
protocol = [proto if proto in self.ALLOWED_PROTO_STRINGS or proto.isnumeric()
else self.PROTO_MAP.get(proto)
for proto in self.term.protocol]

Expand Down
14 changes: 13 additions & 1 deletion tests/lib/cisco_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@
action:: accept
}
"""
GOOD_TERM_23 = """
term good_term_23 {
protocol:: 50
action:: accept
}
"""
LONG_COMMENT_TERM = """
term long-comment-term {
comment:: "%s "
Expand Down Expand Up @@ -878,7 +884,6 @@ def testLongHeader(self):
LONG_VERSION_HEADER + GOOD_TERM_7,
self.naming)
acl = cisco.Cisco(pol, EXP_INFO)
print(acl)
self.assertIn('remark This long header should be split even on a', str(acl))
self.assertIn(('remark looooooooooooooooooooooooooonnnnnnnnnnnnnnnnnn'
'gggggggggg string.'), str(acl))
Expand All @@ -889,6 +894,13 @@ def testLongHeader(self):
self.assertIn(('remark 5:0x169ef02a512c5b28!8m2!3d37.4220579!4d-122.084'
'0897'), str(acl))

def testProtocolByNumber(self):
"""Test policy term refering to protocol by number"""
pol = policy.ParsePolicy(
GOOD_HEADER + GOOD_TERM_23, self.naming
)
acl = cisco.Cisco(pol, EXP_INFO)
self.assertIn('permit 50 any any', str(acl))

if __name__ == '__main__':
unittest.main()