Skip to content

Commit aced50a

Browse files
ospf authentication rules updated (#186)
* ospf authentication rules updated * ospf authentication rules updated * ospf authentication rules updated
1 parent b27d1f7 commit aced50a

File tree

4 files changed

+85
-26
lines changed

4 files changed

+85
-26
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from comfy import medium
2+
import re
3+
4+
5+
@medium(
6+
name='rule_3321_set_authentication_message_digest_for_ospf_area',
7+
platform=['cisco_ios', 'cisco_xe'],
8+
)
9+
def rule_3321_set_authentication_message_digest_for_ospf_area(configuration, device, ref):
10+
config = str(configuration)
11+
interfaces = re.split(r'\ninterface ', config)
12+
failed_interfaces = []
13+
14+
for section in interfaces[1:]: # skip any preamble before the first interface
15+
lines = section.strip().splitlines()
16+
if not lines:
17+
continue
18+
19+
interface_name = lines[0].strip()
20+
21+
# exclude loopbacks
22+
if interface_name.lstrip().lower().startswith('loopback'):
23+
continue
24+
25+
# Check if this interface has OSPF enabled
26+
has_ospf = any(re.search(r'\bip ospf\b', line) for line in lines)
27+
28+
if has_ospf:
29+
# Check for authentication
30+
has_auth = any(
31+
re.search(r'\bip ospf authentication message-digest\b', line)
32+
for line in lines
33+
)
34+
if not has_auth:
35+
failed_interfaces.append(interface_name)
36+
37+
combined_message = {
38+
"message": (
39+
"OSPF authentication (message-digest) missing on interfaces: "
40+
+ ", ".join(failed_interfaces)
41+
),
42+
"ref": ref,
43+
}
44+
assert (
45+
len(failed_interfaces) == 0
46+
), combined_message
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.rule_3321_set_authetnication_message_digest_for_ospf_area
1+
.rule_3321_set_authentication_message_digest_for_ospf_area
22

33
References: 1. http://www.cisco.com/en/US/docs/ios-xml/ios/iproute_ospf/command/ospf-i1.html#GUID-3D5781A3-F8DF-4760-A551-6A3AB80A42ED
44
2. http://www.cisco.com/en/US/docs/ios-xml/ios/iproute_ospf/command/ospf-a1.html#GUID-81D0F753-D8D5-494E-9A10-B15433CFD445

CIS/cisco_ios/332_require_ospf_auth_if_used/rule_3321_set_authetnication_message_digest_for_ospf_area.py

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,46 @@
1-
import pytest
21
from comfy import medium
2+
import re
33

44

5-
@pytest.mark.skip("has to be reviewed")
65
@medium(
76
name='rule_3322_set_ip_ospf_message_digest_key_md5',
8-
platform=['cisco_ios', 'cisco_xe'],
9-
commands={'interface_config': 'sh run int {interface_name}'}
7+
platform=['cisco_ios'],
108
)
11-
def rule_3322_set_ip_ospf_message_digest_key_md5(commands, ref):
12-
# Replace {interface_name} with the actual interface you want to test in the command dictionary or
13-
# modify the rule to iterate through a list of interfaces if needed.
9+
def rule_3322_set_ip_ospf_message_digest_key_md5(configuration, device, ref):
10+
config = str(configuration)
11+
interfaces = re.split(r'\ninterface ', config)
12+
failed_interfaces = []
1413

15-
# Extracting the OSPF MD5 key configuration from the command output
16-
interface_config = commands.interface_config
14+
for section in interfaces[1:]: # skip any preamble before the first interface
15+
lines = section.strip().splitlines()
16+
if not lines:
17+
continue
1718

18-
# Verifying the presence of the OSPF MD5 key in the interface configuration
19-
assert 'ip ospf message-digest-key' in interface_config and 'md5' in interface_config, ref
19+
interface_name = lines[0].strip()
20+
21+
# exclude loopbacks
22+
if interface_name.lstrip().lower().startswith('loopback'):
23+
continue
24+
25+
# Check if this interface has OSPF enabled
26+
has_ospf = any(re.search(r'\bip ospf\b', line) for line in lines)
27+
28+
if has_ospf:
29+
# Check for authentication
30+
has_auth = any(
31+
re.search(r'\bip ospf authentication message-digest key\b', line)
32+
for line in lines
33+
)
34+
if not has_auth:
35+
failed_interfaces.append(interface_name)
36+
37+
combined_message = {
38+
"message": (
39+
"OSPF authentication (message-digest-key) missing on interfaces: "
40+
+ ", ".join(failed_interfaces)
41+
),
42+
"ref": ref,
43+
}
44+
assert (
45+
len(failed_interfaces) == 0
46+
), combined_message

0 commit comments

Comments
 (0)