Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions openwisp_controller/config/base/vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,12 +892,12 @@ def _get_common_name(self):
"""
d = self.config.device
end = 63 - len(d.mac_address)
d.name = d.name[:end]
name = d.name[:end]
unique_slug = shortuuid.ShortUUID().random(length=8)
cn_format = app_settings.COMMON_NAME_FORMAT
if cn_format == "{mac_address}-{name}" and d.name == d.mac_address:
if cn_format == "{mac_address}-{name}" and name == d.mac_address:
cn_format = "{mac_address}"
common_name = cn_format.format(**d.__dict__)[:55]
common_name = cn_format.format(**{**d.__dict__, "name": name})[:55]
common_name = f"{common_name}-{unique_slug}"
return common_name

Expand Down
2 changes: 2 additions & 0 deletions openwisp_controller/config/tests/test_vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ def test_auto_create_cert_with_long_device_name(self):
)
client.full_clean()
client.save()
# Ensure _get_common_name does not mutate device.name
self.assertEqual(d.name, device_name)
# The last 9 characters gets truncated and replaced with unique id
self.assertIn(
"{mac_address}-{name}".format(**d.__dict__)[:-9], client._get_common_name()
Expand Down
Loading