Skip to content

Commit

Permalink
Fix interfaces unique names checking on dnsmasq (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
ObjatieGroba committed Mar 20, 2021
1 parent b4e6fe8 commit f56d1e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions debinterface/dnsmasqRange.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,18 @@ def validate(self):
raise ValueError("Missing option : {0}".format(key))
if inet_aton(rng["end"]) < inet_aton(rng["start"]):
raise ValueError("Start IP range must be before end IP")
return True

itf_names = [
data["interface"]
for data in self._config["dhcp-range"]
]
if len(itf_names) != set(itf_names):

if len(itf_names) != len(set(itf_names)):
msg = "Multiple interfaces with the same name"
raise ValueError(msg)
except KeyError:
pass # dhcp-range is not mandatory
return True

def update_range(self, interface, start, end, lease_time):
"""Update existing range based on the interface name
Expand Down
10 changes: 10 additions & 0 deletions test/test_dnsmasqRange.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,13 @@ def test_update_range(self):
self.assertEqual(set(expected.keys()), set(cur_range.keys()))
for expected_key, expected_value in expected.items():
self.assertEqual(expected_value, cur_range[expected_key])

def test_validate_invalid_duplicate_interface(self):
"""Test validate with duplicate interface name"""

dns = DnsmasqRange("fdlkfdl")
invalid = copy.deepcopy(DNSMASQ_DEFAULT_CONFIG)
invalid["dhcp-range"][1]["interface"] = invalid["dhcp-range"][0]["interface"]
dns._config = invalid
with self.assertRaises(ValueError):
dns.validate()

0 comments on commit f56d1e5

Please sign in to comment.