mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
fix(computes): the compute forms save their own kind, a password as typed, and say when the host is not reached
The kind of a compute came from a hidden form field: posted as another number it was saved, and the edit page of that compute failed. Each form now saves its own kind. Passwords lost their leading and trailing spaces on the forms and the API, so a SASL password with one never worked. A host name whose last label is all digits, such as an IPv4 address with a trailing dot, was taken and libvirt could not resolve it. A host saved with a wrong password or not answering was saved silently; the page now says why the panel cannot connect to it.
This commit is contained in:
parent
d682c4bc82
commit
eb3bc69754
10 changed files with 139 additions and 69 deletions
38
computes/tests/test_compute_form.py
Normal file
38
computes/tests/test_compute_form.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
"""The compute forms: each saves its own kind of compute, keeps a password
|
||||
as typed, and tells when the host saved cannot be reached."""
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
from computes.models import Compute
|
||||
from computes.tests.fakes import no_host_answers
|
||||
|
||||
|
||||
class ComputeFormTests(TestCase):
|
||||
def setUp(self):
|
||||
self.client.force_login(get_user_model().objects.create_superuser("cf-admin", "cf@example.com", "pw"))
|
||||
no_host_answers(self)
|
||||
|
||||
def add(self, **data):
|
||||
return self.client.post(reverse("add_tcp_host"), {"name": "kvm1", "hostname": "192.0.2.1", "login": "wvc",
|
||||
"password": "pw", "details": "", **data}, follow=True)
|
||||
|
||||
def test_a_posted_kind_is_not_taken(self):
|
||||
self.add(type=99)
|
||||
compute = Compute.objects.get(name="kvm1")
|
||||
self.assertEqual(compute.type, 1)
|
||||
self.assertEqual(self.client.get(reverse("compute_update", args=[compute.id])).status_code, 200)
|
||||
|
||||
def test_a_password_keeps_its_spaces(self):
|
||||
self.add(password=" pass phrase ")
|
||||
self.assertEqual(Compute.objects.get(name="kvm1").password, " pass phrase ")
|
||||
compute = Compute.objects.get(name="kvm1")
|
||||
self.client.patch(f"/api/v1/computes/{compute.id}/", {"password": " other "}, content_type="application/json")
|
||||
compute.refresh_from_db()
|
||||
self.assertEqual(compute.password, " other ")
|
||||
|
||||
def test_a_host_that_does_not_answer_is_saved_with_a_warning(self):
|
||||
response = self.add()
|
||||
self.assertTrue(Compute.objects.filter(name="kvm1").exists())
|
||||
self.assertContains(response, "The host was saved, but the panel cannot connect to it: unreachable")
|
||||
|
|
@ -16,6 +16,13 @@ class HostnameValidatorTestCase(unittest.TestCase):
|
|||
with self.subTest(value=value):
|
||||
validate_hostname(value)
|
||||
|
||||
def test_rejects_what_is_neither_an_address_nor_a_name(self):
|
||||
# a name's last label is never all digits: libvirt cannot resolve these
|
||||
for value in ("192.0.2.10.", "192.0.2.1.5", "999.1.1.1"):
|
||||
with self.subTest(value=value):
|
||||
with self.assertRaises(ValidationError):
|
||||
validate_hostname(value)
|
||||
|
||||
def test_rejects_uri_and_option_injection(self):
|
||||
for value in (
|
||||
"-x",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue