mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 09:26:03 +00:00
fix(instances): console changes that cannot be made are refused, not reported as done
A switch to the serial console removed the graphics device but kept a serial console of another type, a TCP one say, which the browser does not open; the audit log said the console type was set. The switch is now refused, with nothing changed, unless the serial console is a pty one. A listen address change of a console that listens on a network, a socket or nowhere did nothing without a word. It is refused with the reason. The .vv file pointed virt-viewer at "::" for a console on all IPv6 addresses; such a console is reached through the host, as one on 0.0.0.0.
This commit is contained in:
parent
88e7e0fa90
commit
d6df6b1df4
11 changed files with 291 additions and 210 deletions
|
|
@ -108,6 +108,11 @@ class ConsoleForm(forms.Form):
|
|||
self.add_error("password", _("A VNC password takes up to 8 letters, digits or symbols, without accents."))
|
||||
elif not password.isprintable(): # a SPICE password
|
||||
self.add_error("password", _("A password takes no line breaks or other control characters."))
|
||||
# refused before anything is saved; a new console type gets an address listener
|
||||
if ("listen_on" in self.changed_data and data.get("console_type") in ("", self.initial["console_type"])
|
||||
and self.instance.proxy.get_console_listen_type(config=True) in ("network", "socket", "none")):
|
||||
self.add_error("listen_on", _("The console listens on no address (on a network, a socket or nowhere); "
|
||||
"change it in the XML editor"))
|
||||
# A console that listens beyond localhost (set by an administrator)
|
||||
# keeps its password unless an administrator removes it.
|
||||
if action == "none" and not self.is_superuser and not self.instance.proxy.console_listens_locally():
|
||||
|
|
|
|||
|
|
@ -66,6 +66,12 @@ class CanOpenConsoleTestCase(TestCase):
|
|||
# the VM found by its UUID; a console on all addresses is reached through the host
|
||||
for line in (b"type=vnc", b"host=192.0.2.7", b"port=5900", b"title=cons-vm"):
|
||||
self.assertIn(line + b"\n", res.content)
|
||||
with patch("instances.models.wvmInstance") as wvm:
|
||||
proxy = wvm.return_value.cached_reads.return_value.__enter__.return_value
|
||||
proxy.host = "192.0.2.7"
|
||||
proxy.get_console_listener_addr.return_value = "::" # all IPv6 addresses
|
||||
res = self.client.get(reverse("instances:getvvfile", args=[self.instance.id]))
|
||||
self.assertIn(b"host=192.0.2.7\n", res.content)
|
||||
# the password only with the permission the console page asks for, as there
|
||||
self.assertNotIn(b"password=", res.content)
|
||||
self.owner.user_permissions.add(Permission.objects.get(codename="passwordless_console"))
|
||||
|
|
|
|||
|
|
@ -57,6 +57,23 @@ class UpdateConsoleTestCase(TestCase):
|
|||
self.assertEqual(messages[-1], "Console settings were not saved: "
|
||||
"The console settings were changed meanwhile; check them and save again.")
|
||||
|
||||
def test_a_listen_address_that_cannot_change_saves_nothing(self):
|
||||
# a socket console: refused before the password and keymap are saved
|
||||
with patch("instances.models.wvmInstance") as wvm:
|
||||
proxy = wvm.return_value
|
||||
proxy.get_console_type.return_value = "vnc"
|
||||
proxy.get_console_listen_type.return_value = "socket"
|
||||
proxy.get_console_listener_addr.return_value = "127.0.0.1"
|
||||
proxy.get_console_keymap.return_value = ""
|
||||
proxy.get_console_passwd.return_value = None
|
||||
response = self.client.post(reverse("instances:update_console", args=[self.instance.id]),
|
||||
{**VNC, "listen_on": "0.0.0.0", "keymap": "de", "password_action": "generate",
|
||||
"seen": console_seen("vnc", "127.0.0.1", "auto", None)})
|
||||
proxy.set_console_passwd.assert_not_called()
|
||||
proxy.set_console_keymap.assert_not_called()
|
||||
proxy.set_console_listener_addr.assert_not_called()
|
||||
self.assertIn("listens on no address", str(list(get_messages(response.wsgi_request))[0]))
|
||||
|
||||
def test_a_template_s_console_settings_are_not_changed(self):
|
||||
# its page has no console form: a template is cloned, not run
|
||||
self.instance.is_template = True
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ class VMRowTests(TestCase):
|
|||
self.proxy.get_console_passwd.return_value = ""
|
||||
self.proxy.get_console_keymap.return_value = ""
|
||||
self.proxy.set_console_keymap.return_value = False # no graphics device
|
||||
self.proxy.set_console_listener_addr.return_value = False # a socket, no address
|
||||
self.proxy.set_console_listener_addr.return_value = False # no graphics device
|
||||
form = {"listen_on": "0.0.0.0", "keymap": "de", "password_action": "keep",
|
||||
"seen": console_seen("vnc", "127.0.0.1", "auto", "")}
|
||||
self.post("update_console", form)
|
||||
|
|
|
|||
|
|
@ -2485,7 +2485,8 @@ def getvvfile(request, pk):
|
|||
listen = proxy.get_console_listener_addr()
|
||||
response.writelines("[virt-viewer]\n")
|
||||
response.writelines(f"type={proxy.get_console_type()}\n")
|
||||
response.writelines(f"host={proxy.host if listen == '0.0.0.0' else listen}\n")
|
||||
# a console on all IPv4 or IPv6 addresses is reached through the host
|
||||
response.writelines(f"host={proxy.host if listen in ('0.0.0.0', '::') else listen}\n")
|
||||
response.writelines(f"port={proxy.get_console_port()}\n")
|
||||
response.writelines(f"title={keyfile_value(proxy.instance.name())}\n")
|
||||
# as the console page: without the permission the viewer asks for the password
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue