mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 03:36:48 +00:00
fix(networks): the fixed-address dialogs take real MAC addresses and host names
The MAC field's pattern ([0-9/:]+) had no hex letters, so the browser
refused nearly every MAC address (52:54:00🆎cd:ef) and no IPv4 fixed
address could be added from the page. The host name field of both
dialogs ([a-zA-Z0-9_]+) refused names such as web-01 or db.lan. The MAC
takes hex digits and ":", the name letters, digits, "_", "." and "-";
the server already escapes both into the network XML.
This commit is contained in:
parent
7865d11d5b
commit
7f1780ad2d
4 changed files with 34 additions and 3 deletions
|
|
@ -24,13 +24,13 @@
|
|||
<div class="row">
|
||||
<label class="col-sm-4 col-form-label">{% trans "MAC" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input type="text" class="form-control" name="mac" required pattern="[0-9\/\:]+">
|
||||
<input type="text" class="form-control" name="mac" required pattern="[0-9a-fA-F:]+">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label class="col-sm-4 col-form-label">{% trans "Name" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input type="text" class="form-control" name="name" pattern="[a-zA-Z0-9_]+">
|
||||
<input type="text" class="form-control" name="name" pattern="[a-zA-Z0-9_.\-]+">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
<div class="row">
|
||||
<label class="col-sm-4 col-form-label">{% trans "Name" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<input type="text" class="form-control" name="name" pattern="[a-zA-Z0-9_]+">
|
||||
<input type="text" class="form-control" name="name" pattern="[a-zA-Z0-9_.\-]+">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
|
|
|||
0
networks/tests/__init__.py
Normal file
0
networks/tests/__init__.py
Normal file
31
networks/tests/test_fixed_address_form.py
Normal file
31
networks/tests/test_fixed_address_form.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
"""The fixed-address dialogs take real MAC addresses and host names: the
|
||||
browser refuses what their pattern attributes do not match."""
|
||||
|
||||
import re
|
||||
from types import SimpleNamespace
|
||||
|
||||
from django.template.loader import render_to_string
|
||||
from django.test import SimpleTestCase
|
||||
from lxml import html
|
||||
|
||||
|
||||
def pattern(template, name):
|
||||
superuser = SimpleNamespace(user=SimpleNamespace(is_superuser=True))
|
||||
page = html.fromstring(render_to_string(template, {"request": superuser}))
|
||||
return re.compile(page.xpath(f"//input[@name='{name}']/@pattern")[0])
|
||||
|
||||
|
||||
class FixedAddressFormTests(SimpleTestCase):
|
||||
def test_macs_and_host_names_are_accepted(self):
|
||||
mac = pattern("modify_ipv4_fixed_address.html", "mac")
|
||||
for value in ("52:54:00:ab:cd:ef", "52:54:00:AB:CD:EF"):
|
||||
with self.subTest(mac=value):
|
||||
self.assertTrue(mac.fullmatch(value))
|
||||
for template in ("modify_ipv4_fixed_address.html", "modify_ipv6_fixed_address.html"):
|
||||
name = pattern(template, "name")
|
||||
for value in ("web-01", "db.lan", "vm_1"):
|
||||
with self.subTest(template=template, name=value):
|
||||
self.assertTrue(name.fullmatch(value))
|
||||
for value in ("a b", 'x"<'):
|
||||
with self.subTest(template=template, refused=value):
|
||||
self.assertFalse(name.fullmatch(value))
|
||||
Loading…
Add table
Add a link
Reference in a new issue