[FIX] conftest: assert tunnel response is a proper URL

Since the tunnel value is now a path to a script to run (and get the
public facing address out of), it's pretty easy to give the path to
the wrong program e.g. `--tunnel ngrok` will run ngrok itself, which
is going to yield an error message and do nothing, and then break when
we try to use the nonsensical result (e.g. an empty string or an error
message) as a URL.

So assert that the result does parse as a URL-ish with at least a
scheme and netloc.
This commit is contained in:
Xavier Morel 2025-02-04 08:16:31 +01:00
parent c67bb64537
commit 88453aa462

View File

@ -73,6 +73,7 @@ import xmlrpc.client
from contextlib import closing
from dataclasses import dataclass
from typing import Optional
from urllib.parse import urlsplit
import pytest
import requests
@ -236,7 +237,10 @@ def tunnel(pytestconfig: pytest.Config, port: int):
) as p:
# read() blocks forever and I don't know why, read things about the
# write end of the stdout pipe still being open here?
yield p.stdout.readline().strip()
result = p.stdout.readline().strip()
url = urlsplit(result)
assert url.scheme and url.netloc
yield url.geturl()
p.terminate()
p.wait(30)
else: