Skip to content

Commit fa94f90

Browse files
authored
[fix] Swap m2m_changed signal connections for correct VPN client handling
Ensure that VPN clients are created or removed before `templates_changed` is triggered. The VpnClient context can affect the configuration checksum, so swapping the signal connections preserves the correct order of operations. Also added tests to verify that configuration checksums correctly account for VPN client templates.
1 parent cd6f02a commit fa94f90

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

openwisp_controller/config/apps.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,18 @@ def connect_signals(self):
7878
sender=self.config_model.templates.through,
7979
dispatch_uid="config.clean_templates",
8080
)
81+
# VPN clients must be created or removed **before**
82+
# self.config_model.templates_changed is evaluated, because
83+
# the VpnClient context can influence the configuration checksum.
8184
m2m_changed.connect(
82-
self.config_model.templates_changed,
85+
self.config_model.manage_vpn_clients,
8386
sender=self.config_model.templates.through,
84-
dispatch_uid="config.templates_changed",
87+
dispatch_uid="config.manage_vpn_clients",
8588
)
8689
m2m_changed.connect(
87-
self.config_model.manage_vpn_clients,
90+
self.config_model.templates_changed,
8891
sender=self.config_model.templates.through,
89-
dispatch_uid="config.manage_vpn_clients",
92+
dispatch_uid="config.templates_changed",
9093
)
9194
# the order of the following connect() call must be maintained
9295
m2m_changed.connect(

openwisp_controller/config/tests/test_config.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
from .. import settings as app_settings
1414
from ..base.base import logger as base_config_logger
1515
from ..signals import config_backend_changed, config_modified, config_status_changed
16-
from .utils import CreateConfigTemplateMixin, CreateDeviceGroupMixin, TestVpnX509Mixin
16+
from .utils import (
17+
CreateConfigTemplateMixin,
18+
CreateDeviceGroupMixin,
19+
TestVpnX509Mixin,
20+
TestWireguardVpnMixin,
21+
)
1722

1823
Config = load_model("config", "Config")
1924
Device = load_model("config", "Device")
@@ -906,6 +911,7 @@ def test_config_backend_changed(self):
906911
class TestTransactionConfig(
907912
CreateConfigTemplateMixin,
908913
TestVpnX509Mixin,
914+
TestWireguardVpnMixin,
909915
TransactionTestCase,
910916
):
911917
def test_multiple_vpn_client_templates_same_vpn(self):
@@ -983,3 +989,14 @@ def test_certificate_renew_invalidates_checksum_cache(self):
983989
self.assertNotEqual(config.get_cached_checksum(), old_checksum)
984990
config.refresh_from_db()
985991
self.assertEqual(config.status, "modified")
992+
993+
def test_checksum_db_accounts_for_vpnclient(self):
994+
vpn = self._create_wireguard_vpn()
995+
vpn_template = self._create_template(
996+
name="vpn1-template", type="vpn", vpn=vpn, config={}
997+
)
998+
config = self._create_config(organization=self._get_org())
999+
config.templates.add(vpn_template)
1000+
config.refresh_from_db()
1001+
config._invalidate_backend_instance_cache()
1002+
self.assertEqual(config.checksum, config.checksum_db)

0 commit comments

Comments
 (0)