server: Don't use the address in the config for connection establishment.

The address in the config can contain subpaths and it doesn't make sense
for a socket to connect to this address. The net location without the
subpath is now contained in server.address.
This commit is contained in:
Damir Jelić 2019-02-03 22:56:10 +01:00
parent 107a7a606e
commit b884536e7e
5 changed files with 23 additions and 13 deletions

View file

@ -180,7 +180,7 @@ def wrap_socket(server, file_descriptor):
ssl_socket = server.ssl_context.wrap_socket(
sock, do_handshake_on_connect=False,
server_hostname=server.config.address) # type: ssl.SSLSocket
server_hostname=server.address) # type: ssl.SSLSocket
server.socket = ssl_socket

View file

@ -1078,7 +1078,7 @@ def matrix_upload_command_cb(data, buffer, args):
upload = Upload(
server.name,
server.config.address,
server.client.host,
server.client.access_token,
room_buffer.room.room_id,
parsed_args.file,

View file

@ -251,6 +251,7 @@ class MatrixServer(object):
except NotImplementedError:
pass
self.address = None
self.client = None
self.access_token = None # type: Optional[str]
self.next_batch = None # type: Optional[str]
@ -336,15 +337,18 @@ class MatrixServer(object):
netloc, path = (address, "")
path = path.strip("/")
netloc = "{}:{}".format(netloc, port)
return "/".join([netloc, path]).rstrip("/")
return netloc, "/".join([
"{}:{}".format(netloc, port),
path
]).rstrip("/")
def _change_client(self):
host = MatrixServer._parse_url(
netloc, host = MatrixServer._parse_url(
self.config.address,
str(self.config.port)
)
self.address = netloc
self.client = HttpClient(
host,
self.config.username,
@ -558,7 +562,6 @@ class MatrixServer(object):
def connect(self):
# type: (MatrixServer) -> int
if not self.config.address or not self.config.port:
W.prnt("", self.config.address)
message = "{prefix}Server address or port not set".format(
prefix=W.prefix("error")
)
@ -589,7 +592,7 @@ class MatrixServer(object):
"{prefix}matrix: Connecting to " "{server}:{port}{ssl}..."
).format(
prefix=W.prefix("network"),
server=self.config.address,
server=self.address,
port=self.config.port,
ssl=ssl_message,
)
@ -598,7 +601,7 @@ class MatrixServer(object):
W.hook_connect(
self.config.proxy,
self.config.address,
self.address,
self.config.port,
1,
0,

View file

@ -82,7 +82,7 @@ def server_buffer_set_title(server):
ip_string = ""
title = ("Matrix: {address}:{port}{ip}").format(
address=server.config.address, port=server.config.port, ip=ip_string
address=server.address, port=server.config.port, ip=ip_string
)
W.buffer_set(server.server_buffer, "title", title)

View file

@ -6,14 +6,21 @@ G.CONFIG = MockConfig()
class TestClass(object):
def test_address_parsing(self):
host = MatrixServer._parse_url("example.org", "443")
netloc, host = MatrixServer._parse_url("example.org", "443")
assert host == "example.org:443"
assert netloc == "example.org"
host = MatrixServer._parse_url("example.org/_matrix", "443")
netloc, host = MatrixServer._parse_url("example.org/_matrix", "443")
assert host == "example.org:443/_matrix"
assert netloc == "example.org"
host = MatrixServer._parse_url("https://example.org/_matrix", "443")
netloc, host = MatrixServer._parse_url(
"https://example.org/_matrix",
"443"
)
assert host == "example.org:443/_matrix"
assert netloc == "example.org"
host = MatrixServer._parse_url("https://example.org", "443")
netloc, host = MatrixServer._parse_url("https://example.org", "443")
assert host == "example.org:443"
assert netloc == "example.org"