Skip to content

Commit dbf1a05

Browse files
authored
[fix] Use context variables in Vpn.auto_client for OpenVPN backend
Bug: The `Vpn.auto_client` method was incorrectly using the Vpn.host field when generating the client configuration for the OpenVPN backend. This resulted in the `remote` directive being hardcoded in the `Template.config`, instead of being rendered from the provided context variables. Fix: The `Vpn.auto_client` method has been updated to use the correct context-based values. [backport 1.2]
1 parent a9c6f61 commit dbf1a05

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

openwisp_controller/config/base/vpn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ def auto_client(self, auto_cert=True, template_backend_class=None):
648648
context_keys.pop("ip_address", None)
649649
context_keys.pop("vpn_subnet", None)
650650
auto = backend.auto_client(
651-
host=self.host,
651+
host=vpn_host,
652652
server=self.config[config_dict_key][0],
653653
**context_keys,
654654
)

openwisp_controller/config/tests/test_vpn.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,13 @@ def test_auto_client(self):
194194
vpn = self._create_vpn()
195195
auto = vpn.auto_client()
196196
context_keys = vpn._get_auto_context_keys()
197-
del context_keys["vpn_host"]
198197
del context_keys["vpn_port"]
199198
for key in context_keys.keys():
200199
context_keys[key] = "{{%s}}" % context_keys[key]
201200
control = vpn.backend_class.auto_client(
202-
host=vpn.host, server=self._vpn_config["openvpn"][0], **context_keys
201+
host=context_keys.pop("vpn_host"),
202+
server=self._vpn_config["openvpn"][0],
203+
**context_keys,
203204
)
204205
control["files"] = [
205206
{
@@ -224,14 +225,15 @@ def test_auto_client_auto_cert_False(self):
224225
vpn = self._create_vpn()
225226
auto = vpn.auto_client(auto_cert=False)
226227
context_keys = vpn._get_auto_context_keys()
227-
del context_keys["vpn_host"]
228228
del context_keys["vpn_port"]
229229
for key in context_keys.keys():
230230
context_keys[key] = "{{%s}}" % context_keys[key]
231231
for key in ["cert_path", "cert_contents", "key_path", "key_contents"]:
232232
del context_keys[key]
233233
control = vpn.backend_class.auto_client(
234-
host=vpn.host, server=self._vpn_config["openvpn"][0], **context_keys
234+
host=context_keys.pop("vpn_host"),
235+
server=self._vpn_config["openvpn"][0],
236+
**context_keys,
235237
)
236238
control["files"] = [
237239
{

0 commit comments

Comments
 (0)