@@ -298,6 +298,22 @@ def test_vpn_client_get_common_name(self):
298298 d .name = d .mac_address
299299 self .assertIn (d .mac_address , client ._get_common_name ())
300300
301+ def test_get_common_name_does_not_mutate_device_name (self ):
302+ """Regression test: _get_common_name() must not mutate the
303+ device object's name in memory. A long device name should be
304+ truncated only for the common_name, not on the device itself."""
305+ long_name = "a" * 80
306+ vpn = self ._create_vpn ()
307+ d = self ._create_device (name = long_name )
308+ c = self ._create_config (device = d )
309+ client = VpnClient (vpn = vpn , config = c , auto_cert = True )
310+ client ._get_common_name ()
311+ self .assertEqual (
312+ d .name ,
313+ long_name ,
314+ "_get_common_name() must not truncate device.name in memory" ,
315+ )
316+
301317 def test_get_auto_context_keys (self ):
302318 vpn = self ._create_vpn ()
303319 keys = vpn ._get_auto_context_keys ()
@@ -402,6 +418,25 @@ def test_vpn_and_cert_different_organization(self):
402418 else :
403419 self .fail ("ValidationError not raised" )
404420
421+ def test_auto_create_cert_preserves_full_device_name (self ):
422+ """Regression test: when a device has a very long name, the
423+ auto-created certificate's display name should be the original
424+ (full) device name, not the truncated common_name version."""
425+ long_name = "a" * 80 # exceeds 63 - len(mac_address) limit
426+ org = self ._create_org (name = "org1" )
427+ vpn = self ._create_vpn (organization = org )
428+ d = self ._create_device (organization = org , name = long_name )
429+ c = self ._create_config (device = d )
430+ template = self ._create_template ()
431+ client = VpnClient (vpn = vpn , config = c , auto_cert = True , template = template )
432+ client .full_clean ()
433+ client .save ()
434+ # The cert's name field should be the full original device name
435+ cert = Cert .objects .filter (organization = org , name = long_name )
436+ self .assertEqual (cert .count (), 1 )
437+ # Device name must not be mutated
438+ self .assertEqual (d .name , long_name )
439+
405440 def test_auto_create_cert_with_long_device_name (self ):
406441 device_name = "abcdifghijklmnopqrstuvwxyz12345678901234567890"
407442 org = self ._create_org (name = "org1" )
0 commit comments