fix: preserve legacy plugin catalogs and protect helper token initialization
This commit is contained in:
1 parent
4dc2057d43
commit
e90da727d4
8 files changed
+81
-18
No files matched your search
@@ -214,6 +214,54 @@ def test_concurrent_managers_share_the_first_host_token(tmp_path, monkeypatch):
|
||||
assert token_path.read_text() == tokens[0]
|
||||
|
||||
|
||||
def test_unreadable_host_token_is_not_replaced(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(hm, "get_temp_dir", lambda _name: tmp_path / "mutex")
|
||||
token_path = tmp_path / "session.token"
|
||||
token_path.write_text("a" * 48)
|
||||
original_read = Path.read_text
|
||||
|
||||
def denied(path, *args, **kwargs):
|
||||
if path == token_path:
|
||||
raise PermissionError("token temporarily inaccessible")
|
||||
return original_read(path, *args, **kwargs)
|
||||
|
||||
monkeypatch.setattr(Path, "read_text", denied)
|
||||
manager = AccessibilityHelperManager(token_path=token_path)
|
||||
with pytest.raises(PermissionError, match="temporarily inaccessible"):
|
||||
manager.host_token()
|
||||
assert original_read(token_path) == "a" * 48
|
||||
monkeypatch.setattr(Path, "read_text", original_read)
|
||||
assert manager.host_token() == "a" * 48
|
||||
|
||||
|
||||
def test_live_provision_mutex_cannot_be_stolen_after_lease_ages(tmp_path, monkeypatch):
|
||||
import hashlib
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
|
||||
monkeypatch.setattr(hm, "get_temp_dir", lambda _name: tmp_path)
|
||||
first = AccessibilityHelperManager()
|
||||
second = AccessibilityHelperManager()
|
||||
entered = threading.Event()
|
||||
|
||||
def contender():
|
||||
with second._provision_mutex(SERIAL):
|
||||
entered.set()
|
||||
|
||||
with ThreadPoolExecutor(max_workers=1) as executor:
|
||||
with first._provision_mutex(SERIAL):
|
||||
digest = hashlib.sha256(SERIAL.encode()).hexdigest()[:16]
|
||||
path = tmp_path / f"{digest}.mutex"
|
||||
old = time.time() - hm._PROVISION_MUTEX_STALE_SECONDS - 10
|
||||
os.utime(path, (old, old))
|
||||
future = executor.submit(contender)
|
||||
stolen = entered.wait(0.2)
|
||||
future.result(timeout=5)
|
||||
assert not stolen
|
||||
assert entered.is_set()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Provision
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
@@ -23,14 +23,14 @@ from artemis.runtime.device_lock import DeviceBusyError, DeviceExecutionLock
|
||||
("configured", "expected"),
|
||||
[
|
||||
(
|
||||
"https://git.playones.com/chenmingxuan/Artemis-Plugins/raw/branch/main/catalog.json",
|
||||
"https://git.playones.com/chenmingxuan/Artemis-Plugins/raw/branch/main/catalog-v3.json",
|
||||
),
|
||||
(
|
||||
"https://git.playones.com/chenmingxuan/Artemis-Plugins/raw/branch/main/catalog-v3.json",
|
||||
"https://git.playones.com/chenmingxuan/Artemis-Plugins/raw/branch/main/catalog-v3.json",
|
||||
),
|
||||
"https://git.playones.com/chenmingxuan/Artemis-Plugins/raw/branch/main/" + name,
|
||||
"https://git.playones.com/chenmingxuan/Artemis-Plugins/raw/branch/main/catalog-v4.json",
|
||||
)
|
||||
for name in ("catalog.json", "catalog-v3.json", "catalog-v4.json")
|
||||
]
|
||||
+ [
|
||||
("https://example.test/catalog.json", "https://example.test/catalog.json"),
|
||||
("https://example.test/catalog-v3.json", "https://example.test/catalog-v3.json"),
|
||||
],
|
||||
)
|
||||
def test_workspace_catalog_routes_only_the_official_legacy_address(
|
||||
|
||||
Reference in new issue
Block a user