Skip to content

Commit

Permalink
[bug] Convert MAC address to uppercase before device key generation #922
Browse files Browse the repository at this point in the history


Automatically convert the MAC address to uppercase format in the model clean method to ensure consistency with the openwisp-config agent behavior. -m Fixes
  • Loading branch information
dee077 committed Dec 23, 2024
1 parent 85f0a00 commit 1b4d7bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions openwisp_controller/config/base/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def _validate_unique_name(self):
)

def clean(self, *args, **kwargs):
self.mac_address = self.mac_address.upper()
super().clean(*args, **kwargs)
self._validate_unique_name()
self._validate_org_relation('group', field_error='group')
Expand Down
8 changes: 8 additions & 0 deletions openwisp_controller/config/tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ def test_mac_address_validator(self):
else:
self.fail('ValidationError not raised for "{0}"'.format(mac_address))

def test_device_mac_address_uppercase_from_clean_method(self):
device = self._create_device(mac_address='00:1a:2b:3c:4d:5e')
device.full_clean()
self.assertEqual(device.mac_address, '00:1A:2B:3C:4D:5E')
device.save()
device.refresh_from_db()
self.assertEqual(device.mac_address, '00:1A:2B:3C:4D:5E')

def test_config_status_modified(self):
c = self._create_config(device=self._create_device(), status='applied')
self.assertEqual(c.status, 'applied')
Expand Down

0 comments on commit 1b4d7bc

Please sign in to comment.