Skip to content

Commit

Permalink
[fix] Fixed deletion of VPN Client certificate #611
Browse files Browse the repository at this point in the history
- Deletion of VPN Client certificate raises 'ObjectDoesNotExist' exception.
- Wrapped post_delete signal in a try-except block.

Closes #611
  • Loading branch information
Aryamanz29 authored May 9, 2022
1 parent 062800f commit 7404c1a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions openwisp_controller/config/base/vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,11 @@ class method for ``post_delete`` signal
# only invalidates, does not regenerate the cache
# to avoid generating high load during bulk deletes
instance.vpn._invalidate_peer_cache()

if instance.cert:
instance.cert.delete()
try:
if instance.cert:
instance.cert.delete()
except ObjectDoesNotExist:
pass
try:
if instance.ip:
instance.ip.delete()
Expand Down
13 changes: 13 additions & 0 deletions openwisp_controller/config/tests/test_vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ def test_vpn_client_auto_cert_deletes_cert(self):
self.assertEqual(VpnClient.objects.filter(pk=vpnclient.pk).count(), 0)
self.assertEqual(Cert.objects.filter(pk=cert_pk).count(), 0)

def test_vpn_client_cert_post_deletes_cert(self):
org = self._get_org()
vpn = self._create_vpn()
t = self._create_template(name='vpn-test', type='vpn', vpn=vpn, auto_cert=True)
c = self._create_config(organization=org)
c.templates.add(t)
vpnclient = c.vpnclient_set.first()
cert_pk = vpnclient.cert.pk
self.assertEqual(Cert.objects.filter(pk=cert_pk).count(), 1)
vpnclient.cert.delete()
self.assertEqual(VpnClient.objects.filter(pk=vpnclient.pk).count(), 0)
self.assertEqual(Cert.objects.filter(pk=cert_pk).count(), 0)

def test_vpn_cert_and_ca_mismatch(self):
ca = self._create_ca()
different_ca = self._create_ca(common_name='different-ca')
Expand Down

0 comments on commit 7404c1a

Please sign in to comment.