1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 11:16:47 +00:00

fix(storages): the pool form in the page no longer refuses paths the server accepts

The create pool modals kept their own pattern attributes, older and
stricter than the server's check: a logical source took only lower-case
letters, digits and "/", dir and NFS paths no "." or ":", and the NFS
fields stopped at 40 characters (the form allows 100). The browser
refused /dev/mapper/vg0-data, /dev/disk/by-id/wwn-..., /srv/vm.images or
/export/vm_images.v2 before the server saw them. The path fields keep
"required" and leave the check to the server, which shows its message.
This commit is contained in:
catborise 2026-10-19 16:20:15 +03:00
parent 64057f8d05
commit 45b92c8638
2 changed files with 19 additions and 5 deletions

View file

@ -62,7 +62,7 @@
<div class="row">
<label class="col-sm-3 col-form-label">{% trans "Path" %}</label>
<div class="col-sm-6">
<input type="text" name="target" class="form-control" value="/var/lib/libvirt/images" required pattern="[a-zA-Z0-9\/\-_]+">
<input type="text" name="target" class="form-control" value="/var/lib/libvirt/images" required>
</div>
</div>
</div>
@ -91,7 +91,7 @@
<div class="row">
<label class="col-sm-3 col-form-label">{% trans "Device" %}</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="source" value="/dev/sdb" required pattern="[a-z0-9\/]+">
<input type="text" class="form-control" name="source" value="/dev/sdb" required>
</div>
</div>
</div>
@ -191,7 +191,7 @@
<div class="row">
<label class="col-sm-3 col-form-label">{% trans "Remote Path" %}</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="source" placeholder="/srv/storage/" maxlength="40" required pattern="[a-zA-Z0-9\/\-_]+">
<input type="text" class="form-control" name="source" placeholder="/srv/storage/" maxlength="100" required>
</div>
</div>
<div class="row">
@ -208,7 +208,7 @@
<div class="row">
<label class="col-sm-3 col-form-label">{% trans "Local Path" %}</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="target" placeholder="/srv/storage/" maxlength="40" required pattern="[a-zA-Z0-9\/\-_]+">
<input type="text" class="form-control" name="target" placeholder="/srv/storage/" maxlength="100" required>
</div>
</div>
</div>
@ -236,7 +236,7 @@
<div class="row">
<label class="col-sm-3 col-form-label">{% trans "Path" %}</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="target" value="/var/lib/libvirt/iso" required pattern="[a-zA-Z0-9\/\-_]+">
<input type="text" class="form-control" name="target" value="/var/lib/libvirt/iso" required>
</div>
</div>
</div>

View file

@ -3,8 +3,11 @@ paths of letters, digits and "/", "_", ".", ":" and "-" (not first, not right
after "/"): both values go into the pool XML."""
import time
from types import SimpleNamespace
from django.template.loader import render_to_string
from django.test import SimpleTestCase
from lxml import html
from storages.forms import AddStgPool
@ -60,3 +63,14 @@ class PoolTargetTests(SimpleTestCase):
start = time.monotonic()
self.assertTrue(target_error("," + "-" * 98 + "!"))
self.assertLess(time.monotonic() - start, 1)
def test_the_create_form_leaves_the_path_check_to_the_server(self):
# a stricter pattern or a shorter maxlength in the page refuses paths the form accepts
superuser = SimpleNamespace(user=SimpleNamespace(is_superuser=True))
page = html.fromstring(render_to_string("create_stg_block.html", {"request": superuser}))
fields = page.xpath("//input[@name='target' or @name='source']")
self.assertEqual(len(fields), 5)
for field in fields:
with self.subTest(form=field.xpath("string(ancestor::form//input[@name='stg_type']/@value)"), name=field.name):
self.assertIsNone(field.get("pattern"))
self.assertGreaterEqual(int(field.get("maxlength", 100)), 100)