Fixes #14847: Relax requirement for IKE policy

This commit is contained in:
Martin Mayer 2024-01-20 11:49:59 +01:00
parent 2b4ec9dc20
commit 2c08853ac6
6 changed files with 41 additions and 8 deletions

View File

@ -16,6 +16,9 @@ The IKE version employed (v1 or v2).
The IKE mode employed (main or aggressive). The IKE mode employed (main or aggressive).
!!! note
IKE mode depends on the IKE version (IKEv1 required, IKEv2 not applicable).
### Proposals ### Proposals
One or more [IKE proposals](./ikeproposal.md) supported for use by this policy. One or more [IKE proposals](./ikeproposal.md) supported for use by this policy.

View File

@ -164,7 +164,7 @@ class IKEPolicyBulkEditForm(NetBoxModelBulkEditForm):
)), )),
) )
nullable_fields = ( nullable_fields = (
'preshared_key', 'description', 'comments', 'mode', 'preshared_key', 'description', 'comments',
) )

View File

@ -174,7 +174,8 @@ class IKEPolicyImportForm(NetBoxModelImportForm):
) )
mode = CSVChoiceField( mode = CSVChoiceField(
label=_('Mode'), label=_('Mode'),
choices=IKEModeChoices choices=IKEModeChoices,
required=False
) )
proposals = CSVModelMultipleChoiceField( proposals = CSVModelMultipleChoiceField(
queryset=IKEProposal.objects.all(), queryset=IKEProposal.objects.all(),

View File

@ -0,0 +1,18 @@
# Generated by Django 4.2.9 on 2024-01-20 09:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('vpn', '0003_ipaddress_multiple_tunnel_terminations'),
]
operations = [
migrations.AlterField(
model_name='ikepolicy',
name='mode',
field=models.CharField(blank=True),
),
]

View File

@ -79,7 +79,8 @@ class IKEPolicy(PrimaryModel):
) )
mode = models.CharField( mode = models.CharField(
verbose_name=_('mode'), verbose_name=_('mode'),
choices=IKEModeChoices choices=IKEModeChoices,
blank=True
) )
proposals = models.ManyToManyField( proposals = models.ManyToManyField(
to='vpn.IKEProposal', to='vpn.IKEProposal',
@ -109,6 +110,17 @@ class IKEPolicy(PrimaryModel):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('vpn:ikepolicy', args=[self.pk]) return reverse('vpn:ikepolicy', args=[self.pk])
def clean(self):
super().clean()
# Mode is required
if self.version == IKEVersionChoices.VERSION_1 and not self.mode:
raise ValidationError(_("Mode is required for selected IKE version"))
# Mode cannot be used
if self.version == IKEVersionChoices.VERSION_2 and self.mode:
raise ValidationError(_("Mode cannot be used for selected IKE version"))
# #
# IPSec # IPSec

View File

@ -305,7 +305,6 @@ class IKEPolicyTestCase(ViewTestCases.PrimaryObjectViewTestCase):
cls.form_data = { cls.form_data = {
'name': 'IKE Policy X', 'name': 'IKE Policy X',
'version': IKEVersionChoices.VERSION_2, 'version': IKEVersionChoices.VERSION_2,
'mode': IKEModeChoices.AGGRESSIVE,
'proposals': [p.pk for p in ike_proposals], 'proposals': [p.pk for p in ike_proposals],
'tags': [t.pk for t in tags], 'tags': [t.pk for t in tags],
} }
@ -313,9 +312,9 @@ class IKEPolicyTestCase(ViewTestCases.PrimaryObjectViewTestCase):
ike_proposal_names = ','.join([p.name for p in ike_proposals]) ike_proposal_names = ','.join([p.name for p in ike_proposals])
cls.csv_data = ( cls.csv_data = (
"name,version,mode,proposals", "name,version,mode,proposals",
f"IKE Proposal 4,2,aggressive,\"{ike_proposal_names}\"", f"IKE Proposal 4,1,main,\"{ike_proposal_names}\"",
f"IKE Proposal 5,2,aggressive,\"{ike_proposal_names}\"", f"IKE Proposal 5,1,aggressive,\"{ike_proposal_names}\"",
f"IKE Proposal 6,2,aggressive,\"{ike_proposal_names}\"", f"IKE Proposal 6,2,,\"{ike_proposal_names}\"",
) )
cls.csv_update_data = ( cls.csv_update_data = (
@ -327,7 +326,7 @@ class IKEPolicyTestCase(ViewTestCases.PrimaryObjectViewTestCase):
cls.bulk_edit_data = { cls.bulk_edit_data = {
'description': 'New description', 'description': 'New description',
'version': IKEVersionChoices.VERSION_2, 'version': IKEVersionChoices.VERSION_1,
'mode': IKEModeChoices.AGGRESSIVE, 'mode': IKEModeChoices.AGGRESSIVE,
} }