mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 19:26:48 +00:00
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.
31 lines
1.3 KiB
Python
31 lines
1.3 KiB
Python
"""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))
|