diff --git a/requirements.txt b/requirements.txt index bfd239d..cbb31c1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ requests<3.0 libcnml<0.10.0 -openvpn-status-reader>=0.3,<0.4 +openvpn-status-reader @ https://github.com/openwisp/openvpn-status-reader/archive/refs/heads/fix/openvpn-status-peer-prefixes.tar.gz networkx>=3.6.1,<3.7 telnetlib3>=5.0.1,<6 diff --git a/tests/static/openvpn-transport-prefixes.txt b/tests/static/openvpn-transport-prefixes.txt new file mode 100644 index 0000000..5a4b264 --- /dev/null +++ b/tests/static/openvpn-transport-prefixes.txt @@ -0,0 +1,16 @@ +OpenVPN CLIENT LIST +Updated,2026-10-24 12:00:00 +Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since +udp4-client,udp4:181.126.36.3:1194,1,2,2026-10-24 11:00:00 +tcp4-client,tcp4:181.126.36.4:1194,3,4,2026-10-24 11:01:00 +udp6-client,udp6:[2001:db8::3]:1194,5,6,2026-10-24 11:02:00 +tcp6-client,tcp6:[2001:db8::4]:1194,7,8,2026-10-24 11:03:00 +ROUTING TABLE +Virtual Address,Common Name,Real Address,Last Ref +10.0.0.3,udp4-client,udp4:181.126.36.3:1194,2026-10-24 11:00:01 +10.0.0.4,tcp4-client,tcp4:181.126.36.4:1194,2026-10-24 11:01:01 +2001:db8:1::3,udp6-client,udp6:[2001:db8::3]:1194,2026-10-24 11:02:01 +2001:db8:1::4,tcp6-client,tcp6:[2001:db8::4]:1194,2026-10-24 11:03:01 +GLOBAL STATS +Max bcast/mcast queue length,0 +END diff --git a/tests/test_openvpn.py b/tests/test_openvpn.py index 4253527..06bf0a8 100644 --- a/tests/test_openvpn.py +++ b/tests/test_openvpn.py @@ -12,6 +12,9 @@ links5_tap = open("{0}/static/openvpn-5-links-tap.txt".format(CURRENT_DIR)).read() bug = open("{0}/static/openvpn-bug.txt".format(CURRENT_DIR)).read() special_case = open("{0}/static/openvpn-special-case.txt".format(CURRENT_DIR)).read() +transport_prefixes = open( + "{0}/static/openvpn-transport-prefixes.txt".format(CURRENT_DIR) +).read() class TestOpenvpnParser(TestCase): @@ -91,6 +94,25 @@ def test_empty_dict(self): def test_empty_string(self): OpenvpnParser(data="") + def test_transport_prefixed_peers(self): + data = OpenvpnParser(transport_prefixes).json(dict=True) + nodes = { + node["properties"]["common_name"]: node + for node in data["nodes"] + if "common_name" in node["properties"] + } + + for common_name, address, port in [ + ("udp4-client", "181.126.36.3", 1194), + ("tcp4-client", "181.126.36.4", 1194), + ("udp6-client", "2001:db8::3", 1194), + ("tcp6-client", "2001:db8::4", 1194), + ]: + with self.subTest(common_name=common_name): + properties = nodes[common_name]["properties"] + self.assertEqual(properties["real_address"], address) + self.assertEqual(properties["port"], port) + def test_label_diff_added(self): old = OpenvpnParser({}) new = OpenvpnParser(links5_tap)