Skip to content

Commit

Permalink
[fix] Always convert MAC address to uppercase format #922
Browse files Browse the repository at this point in the history
Ensure consistency with the behavior of the openwisp-config agent.

Fixes #922

---------

Co-authored-by: Federico Capoano <[email protected]>
  • Loading branch information
dee077 and nemesifier authored Dec 23, 2024
1 parent 07ae5ce commit 95ff8fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions openwisp_controller/config/base/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def _validate_unique_name(self):

def clean(self, *args, **kwargs):
super().clean(*args, **kwargs)
self.mac_address = self.mac_address.upper()
self._validate_unique_name()
self._validate_org_relation('group', field_error='group')
self._validate_org_device_limit()
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(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
2 changes: 1 addition & 1 deletion openwisp_controller/geo/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_put_create_location(self):
device = self._create_object()
self.assertEqual(self.location_model.objects.count(), 0)
url = reverse(self.url_name, args=[device.pk])
r = self.client.put(f'{url}?key={device.key }')
r = self.client.put(f'{url}?key={device.key}')
self.assertEqual(r.status_code, 200)
self.assertDictEqual(
r.json(),
Expand Down

0 comments on commit 95ff8fe

Please sign in to comment.