Repository: openwisp/openwisp-controller (language: python)

Issue:
[bug] VPN Server: validate trigger URL before saving
When a VPN server is saved, if the trigger URL is changed we should perform some basic validation on it before saving, right now when problems are not detected messages like these come up in the logs:

Invalid URL 'https:://domain.com/trigger-update': No host supplied


Discussion / hints:

Fix patch:
diff --git a/openwisp_controller/config/base/vpn.py b/openwisp_controller/config/base/vpn.py
index 40980e306..28c32fbe1 100644
--- a/openwisp_controller/config/base/vpn.py
+++ b/openwisp_controller/config/base/vpn.py
@@ -79,13 +79,12 @@ class AbstractVpn(ShareableOrgMixinUniqueName, BaseConfig):
         on_delete=models.SET_NULL,
     )
     # optional, helpful for updating WireGuard and VXLAN server configuration
-    webhook_endpoint = models.CharField(
+    webhook_endpoint = models.URLField(
         verbose_name=_('Webhook Endpoint'),
         help_text=_(
             'Webhook to trigger for updating server configuration '
             '(e.g. https://openwisp2.mydomain.com:8081/trigger-update)'
         ),
-        max_length=128,
         blank=True,
         null=True,
     )
diff --git a/openwisp_controller/config/migrations/0045_alter_vpn_webhook_endpoint.py b/openwisp_controller/config/migrations/0045_alter_vpn_webhook_endpoint.py
new file mode 100644
index 000000000..a08c0ae4e
--- /dev/null
+++ b/openwisp_controller/config/migrations/0045_alter_vpn_webhook_endpoint.py
@@ -0,0 +1,26 @@
+# Generated by Django 3.2.15 on 2022-09-09 12:49
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('config', '0044_config_error_reason'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='vpn',
+            name='webhook_endpoint',
+            field=models.URLField(
+                blank=True,
+                help_text=(
+                    'Webhook to trigger for updating server configuration'
+                    ' (e.g. https://openwisp2.mydomain.com:8081/trigger-update)'
+                ),
+                null=True,
+                verbose_name='Webhook Endpoint',
+            ),
+        ),
+    ]


Test patch:
diff --git a/tests/openwisp2/sample_config/migrations/0001_initial.py b/tests/openwisp2/sample_config/migrations/0001_initial.py
index db38c67c5..59156a5b5 100644
--- a/tests/openwisp2/sample_config/migrations/0001_initial.py
+++ b/tests/openwisp2/sample_config/migrations/0001_initial.py
@@ -358,13 +358,12 @@ class Migration(migrations.Migration):
                 ),
                 (
                     'webhook_endpoint',
-                    models.CharField(
+                    models.URLField(
                         blank=True,
                         help_text=(
                             'Webhook to trigger for updating server configuration '
                             '(e.g. https://openwisp2.mydomain.com:8081/trigger-update)'
                         ),
-                        max_length=128,
                         null=True,
                         verbose_name='Webhook Endpoint',
                     ),