connect: Handle \ in username

We need to quote URL values in the username, that's what libvirt expects.
Unquote the values before caching them in the URI object, so console
connections continue to work

https://bugzilla.redhat.com/show_bug.cgi?id=1452389
This commit is contained in:
Cole Robinson 2017-06-01 14:14:49 -04:00
parent 860268f735
commit 1d0b4a0a9e
3 changed files with 9 additions and 2 deletions

View File

@ -57,3 +57,7 @@ class TestURI(unittest.TestCase):
scheme="qemu", transport="ssh", username="root",
hostname="192.168.2.3", path="/system",
query="no_verify=1", host_is_ipv4_string=True)
self._compare(
"qemu+ssh://foo%5Cbar@hostname/system",
scheme="qemu", path="/system", transport="ssh",
hostname="hostname", username="foo\\bar")

View File

@ -22,6 +22,7 @@ import glob
import os
import logging
import socket
import urllib
from gi.repository import Gio
from gi.repository import GObject
@ -393,7 +394,7 @@ class vmmConnect(vmmGObjectUI):
addrstr = ""
if user:
addrstr += user + "@"
addrstr += urllib.quote(user) + "@"
if host.count(":") > 1:
host = "[%s]" % host

View File

@ -19,6 +19,7 @@
import logging
import re
import urllib
from .cli import parse_optstr_tuples
@ -46,9 +47,10 @@ class URI(object):
"""
def __init__(self, uri):
self.uri = uri
unquoted_uri = urllib.unquote(uri)
(self.scheme, self.username, self.hostname,
self.path, self.query, self.fragment) = self._split(self.uri)
self.path, self.query, self.fragment) = self._split(unquoted_uri)
self.transport = ''
if "+" in self.scheme: