openwisp-controller icon indicating copy to clipboard operation
openwisp-controller copied to clipboard

[bug] Deleting VPN template does not delete VpnClient objects

Open pandafy opened this issue 1 year ago • 2 comments

How to replicate

  1. Open Django shell (in command line) and check the number of VpnClient objects using this query VpnClient.objects.count()
  2. Create a VPN server object with OpenVPN backend
  3. Create a VPN template for this VPN server
  4. Add the VPN template to a device
  5. Go to the VPN template page and delete the Template
  6. Open Django shell (in command line) and check the number of VpnClient objects using this query VpnClient.objects.count()

Expected outcome The number of VpnClients is different in Step 1 and Step 6 should be same.

Actual outcome

The number of VpnClients is different in Step 1 and Step 6 (increased by one). It is because the deletion of VPN template didn't trigger deletion of related VpnClient objects (there is no direct relation).

pandafy avatar Feb 09 '24 12:02 pandafy

I found that it is possible to have two different VPN templates for the same VPN server object. But, it is not possible to apply both the templates on the same device, as the JSONSchema generates the following error

There is a conflict with the specified templates. Invalid configuration triggered by "#/files", validator says:

Screenshot from 2024-02-09 17-53-02

I think we should discourage using different templates for the same VPN server object on the same device using validation (we can create a separate issue for this).

pandafy avatar Feb 09 '24 12:02 pandafy

We should double check the working of the following code. I think, it is not getting triggered when the template object is deleted.

https://github.com/openwisp/openwisp-controller/blob/226442c47be5031e64033ae44c8b00aaf2623c68/openwisp_controller/config/base/config.py#L229-L275

pandafy avatar Feb 09 '24 12:02 pandafy