Skip to content

Commit

Permalink
#3599 use urllib.parse rather than custom code
Browse files Browse the repository at this point in the history
but still keep a bunch of mangling functions in normalize_display_name so we can support the older schemes a little while longer
  • Loading branch information
totaam committed Oct 19, 2022
1 parent 223dc02 commit 18720c1
Show file tree
Hide file tree
Showing 6 changed files with 285 additions and 269 deletions.
11 changes: 8 additions & 3 deletions tests/unittests/unit/scripts/parse_display_name_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def _test_opts(self):
opts.exit_ssh = False
opts.ssh = "ssh -v "
opts.remote_xpra = "run-xpra"
opts.username = ""
opts.password = ""
opts.password_file = None
opts.ssl_server_hostname = ""
opts.ssl_cert = ""
Expand All @@ -50,7 +52,9 @@ def err(*args):
if e:
for k,v in e.items():
actual = r.get(k)
assert actual==v, f"expected {v!r} but got {actual!r} from parse_display_name({s})={r}, expected {e}"
if actual!=v:
raise ValueError(f"expected {v!r} but got {actual!r} for {k!r}"+
f" from parse_display_name({s!r})={r!r}, expected {e!r}")
return r

def test_parse_display_name(self):
Expand All @@ -72,11 +76,11 @@ def e(s):
raise Exception(f"parse_display_name should fail for {s}")
if POSIX:
e("ZZZZZZ")
t("10", {"display_name" : "10", "local" : True, "type" : "unix-domain"})
t("10", {"display_name" : ":10", "local" : True, "type" : "unix-domain"})
t(socket_dir+"/thesocket", {"display_name" : "socket://"+socket_dir+"/thesocket"})
t("socket:"+socket_dir+"/thesocket", {"display_name" : "socket:"+socket_dir+"/thesocket"})
e("tcp://host:NOTANUMBER/")
e("tcp://host:0/")
e("tcp://host:-1/")
e("tcp://host:65536/")
t("tcp://username@host/", {"username" : "username", "password" : None})
for socktype in ("tcp", "ws", "wss", "ssl", "ssh"):
Expand Down Expand Up @@ -104,6 +108,7 @@ def e(s):
t("vsock://any:any/", {"vsock" : (CID_ANY, PORT_ANY)})
t("vsock://10:2000/", {"vsock" : (10, 2000)})
t("vnc+ssh://host/0")
t("tcp:localhost:10000", {"host" : "localhost", "port" : 10000, "type" : "tcp"})


def main():
Expand Down
10 changes: 3 additions & 7 deletions xpra/client/gtk_base/client_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
connect_to, make_client,
configure_network, configure_env, configure_logging,
)
from xpra.scripts.parsing import is_local, add_ssh_args, parse_ssh_option, add_ssh_proxy_args
from xpra.scripts.parsing import is_local, get_ssh_args, parse_ssh_option, get_ssh_proxy_args
from xpra.exit_codes import RETRY_EXIT_CODES, EXIT_STR
from xpra.platform.info import get_username
from xpra.log import Logger, enable_debug_for
Expand Down Expand Up @@ -744,8 +744,7 @@ def connect_builtin(self):
self.is_putty = ssh_cmd_0.endswith("plink") or ssh_cmd_0.endswith("plink.exe")
self.is_paramiko = ssh_cmd_0 =="paramiko"
full_ssh = ssh_cmd[:]
full_ssh += add_ssh_args(username, password, host, self.config.ssh_port,
None, self.is_putty, self.is_paramiko)
full_ssh += get_ssh_args(params, ssh_cmd)
if username:
params["username"] = username
if self.nostrict_host_check.get_active():
Expand All @@ -756,10 +755,7 @@ def connect_builtin(self):
params["proxy_port"] = self.config.proxy_port
params["proxy_username"] = self.config.proxy_username
params["proxy_password"] = self.config.proxy_password
full_ssh += add_ssh_proxy_args(self.config.proxy_username, self.config.proxy_password,
self.config.proxy_host, self.config.proxy_port,
self.config.proxy_key, ssh_cmd,
self.is_putty, self.is_paramiko)
full_ssh += get_ssh_proxy_args(params, ssh_cmd)
params["host"] = host
params["local"] = is_local(self.config.host)
params["full_ssh"] = full_ssh
Expand Down
20 changes: 19 additions & 1 deletion xpra/net/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,29 @@ class ConnectionClosedException(Exception):
MAX_PACKET_SIZE = envint("XPRA_MAX_PACKET_SIZE", 16*1024*1024)
FLUSH_HEADER = envbool("XPRA_FLUSH_HEADER", True)

SOCKET_TYPES = ("tcp", "ws", "wss", "ssl", "ssh", "rfb", "vsock")
SOCKET_TYPES = ("tcp", "ws", "wss", "ssl", "ssh", "rfb", "vsock", "socket")

IP_SOCKTYPES = ("tcp", "ssl", "ws", "wss", "ssh")
TCP_SOCKTYPES = ("tcp", "ssl", "ws", "wss", "ssh")

URL_MODES = {
"xpra" : "tcp",
"xpras" : "ssl",
"xpra+tcp" : "tcp",
"xpratcp" : "tcp",
"xpra+tls" : "ssl",
"xpratls" : "ssl",
"xpra+ssl" : "ssl",
"xprassl" : "ssl",
"xpra+ssh" : "ssh",
"xprassh" : "ssh",
"xpra+ws" : "ws",
"xpraws" : "ws",
"xpra+wss" : "wss",
"xprawss" : "wss",
"rfb" : "vnc",
}


#this is used for generating aliases:
PACKET_TYPES = [
Expand Down
3 changes: 2 additions & 1 deletion xpra/net/socket_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,8 @@ def get_ssl_attributes(opts, server_side=True, overrides=None):
for attr in SSL_ATTRIBUTES:
v = (overrides or {}).get(attr)
if v is None:
ssl_attr = "ssl_%s" % attr.replace("-", "_") #ie: "ssl_ca_certs"
fn = attr.replace("-", "_")
ssl_attr = f"ssl_{fn}" #ie: "ssl_ca_certs"
v = getattr(opts, ssl_attr)
args[attr] = v
return args
Expand Down
5 changes: 3 additions & 2 deletions xpra/scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,8 @@ def find_session_by_name(opts, session_name):
return None
if len(session_uuid_to_path)>1:
raise InitException(f"more than one session found matching {session_name!r}")
return "socket://%s" % tuple(session_uuid_to_path.values())[0]
socket_path = tuple(session_uuid_to_path.values())[0]
return f"socket://{socket_path}"


def display_desc_to_uri(display_desc):
Expand Down Expand Up @@ -758,7 +759,7 @@ def display_desc_to_uri(display_desc):
cid, iport = display_desc["vsock"]
uri += f"{cid}:{iport}"
else:
raise NotImplementedError("%s is not implemented yet" % dtype)
raise NotImplementedError(f"{dtype} is not implemented yet")
uri += "/" + display_desc_to_display_path(display_desc)
return uri

Expand Down
Loading

0 comments on commit 18720c1

Please sign in to comment.