@@ -1082,3 +1082,76 @@ def test_republishing_a_live_tunnel_keeps_its_certificate():
|
||||
assert again["uid"] == row["uid"]
|
||||
assert again["status"] == tunnels.STATUS_ACTIVE
|
||||
assert again["last_error"] == ""
|
||||
|
||||
|
||||
def _editor_listener():
|
||||
import socket
|
||||
|
||||
sock = socket.socket()
|
||||
sock.bind(("127.0.0.1", 0))
|
||||
sock.listen(8)
|
||||
return sock
|
||||
|
||||
|
||||
def _workspace_json(slug: str, key: str) -> dict:
|
||||
import requests
|
||||
|
||||
return requests.get(
|
||||
f"{BASE_URL}/projects/{slug}/workspace",
|
||||
headers={"Accept": "application/json", "X-API-KEY": key},
|
||||
timeout=HTTP_TIMEOUT,
|
||||
).json()
|
||||
|
||||
|
||||
def test_workspace_json_reports_the_phase_from_a_live_editor_probe(app_server, seeded_db):
|
||||
owner = _seeded_user("bob_test")
|
||||
project = _http_project(owner["uid"], "WS Phase Http")
|
||||
sock = _editor_listener()
|
||||
port = sock.getsockname()[1]
|
||||
try:
|
||||
_instance(
|
||||
project_uid=project["uid"],
|
||||
workspace_owner_uid=owner["uid"],
|
||||
editor_port=editor.EDITOR_DEFAULT_PORT,
|
||||
ports_json=(
|
||||
f'[{{"host": {port}, "container": {editor.EDITOR_DEFAULT_PORT}, '
|
||||
'"proto": "tcp"}]'
|
||||
),
|
||||
)
|
||||
body = _workspace_json(project["slug"], owner["api_key"])
|
||||
assert body["workspace"]["phase"] == provision.PHASE_READY
|
||||
assert body["workspace"]["phase_label"] == "Ready"
|
||||
assert body["workspace"]["editor_ready"] is True
|
||||
assert body["workspace"]["owner_uid"] == owner["uid"]
|
||||
assert body["editor_url"].endswith("/code/")
|
||||
finally:
|
||||
sock.close()
|
||||
|
||||
body = _workspace_json(project["slug"], owner["api_key"])
|
||||
assert body["workspace"]["phase"] == provision.PHASE_STARTING
|
||||
assert body["workspace"]["phase_label"] == "Starting"
|
||||
assert body["workspace"]["editor_ready"] is False
|
||||
assert body["workspace"]["status"] == "running"
|
||||
|
||||
|
||||
def test_editor_proxy_refuses_a_stopped_workspace_as_plain_text(app_server, seeded_db):
|
||||
import requests
|
||||
|
||||
owner = _seeded_user("bob_test")
|
||||
project = _http_project(owner["uid"], "WS Proxy Stopped")
|
||||
instance = _instance(
|
||||
project_uid=project["uid"],
|
||||
workspace_owner_uid=owner["uid"],
|
||||
status="stopped",
|
||||
desired_state="stopped",
|
||||
)
|
||||
|
||||
response = requests.get(
|
||||
f"{BASE_URL}/projects/{project['slug']}/containers/instances/{instance['uid']}/code/",
|
||||
headers={"X-API-KEY": owner["api_key"]},
|
||||
timeout=HTTP_TIMEOUT,
|
||||
)
|
||||
|
||||
assert response.status_code == 409, response.text[:400]
|
||||
assert response.headers["content-type"].startswith("text/plain")
|
||||
assert "not running" in response.text
|
||||
|
||||
Reference in New Issue
Block a user