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. Fixed lint error in ./openwisp_controller/geo/tests/test_api.py:97:52: E202 whitespace before '}'.

Fixes #922
  • Loading branch information
dee077 authored and pandafy committed Dec 23, 2024
1 parent 07ae5ce commit 7adce69
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 @@ -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
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 7adce69

Please sign in to comment.