fix(webapp): a Webapp tab installs a desktop plugin from any source the CLI takes
Private plugins live behind ssh keys or in local folders. The Webapp's host-side desktop install accepted https only; it now takes git@/ssh://, file:// and http:// like the agent installer and native Desktop, per the maintainer ruling on #146189.
This commit is contained in:
@@ -60,13 +60,12 @@ def _checked_name(name: Optional[str]) -> str:
|
||||
return candidate
|
||||
|
||||
|
||||
def _https_source(identifier: str, catalog_name: Optional[str]) -> tuple[str, Optional[str], Optional[str]]:
|
||||
def _resolve_source(identifier: str, catalog_name: Optional[str]) -> tuple[str, Optional[str], Optional[str]]:
|
||||
"""``(git_url, subdir, catalog_sha)`` through the installer's own resolution and kill list, with the
|
||||
catalog's reviewed pin when *catalog_name* is given (its repository replaces *identifier*).
|
||||
|
||||
A browser tab asks for this clone, so it is https only: ``file://`` would copy any folder of the
|
||||
host, ``ssh``/``git@`` would spend the host's keys, and ``http://`` can be rewritten in transit.
|
||||
Native Desktop's install keeps those for a user at their own machine."""
|
||||
Every scheme the CLI installs from is accepted (``git@``/``ssh://`` for private plugins, ``file://``,
|
||||
``http://``): the Webapp opens only for the signed-in owner of this host, whose keys and disk these are."""
|
||||
pc = _pc()
|
||||
revision = None
|
||||
if catalog_name:
|
||||
@@ -79,8 +78,6 @@ def _https_source(identifier: str, catalog_name: Optional[str]) -> tuple[str, Op
|
||||
git_url, subdir = pc._resolve_git_url(identifier)
|
||||
except ValueError as exc:
|
||||
raise pc.PluginOperationError(str(exc)) from exc
|
||||
if not git_url.startswith("https://"):
|
||||
raise pc.PluginOperationError("A desktop plugin is installed from the Webapp over https:// only.")
|
||||
from hermes_cli.plugins_cmd_catalog import raise_if_removed
|
||||
raise_if_removed(identifier, git_url, *((catalog_name,) if catalog_name else ()))
|
||||
return git_url, subdir, revision
|
||||
@@ -104,7 +101,7 @@ def install_desktop_plugin(identifier: str, *, ref: Optional[str], catalog_name:
|
||||
try:
|
||||
if not _COMMIT.fullmatch(sha):
|
||||
raise pc.PluginOperationError("Installing a desktop plugin needs the commit the install dialog reviewed.")
|
||||
git_url, subdir, catalog_sha = _https_source(identifier, catalog_name)
|
||||
git_url, subdir, catalog_sha = _resolve_source(identifier, catalog_name)
|
||||
root = desktop_plugins_root()
|
||||
with tempfile.TemporaryDirectory(prefix="hermes-plugin-install-") as tmp:
|
||||
clone = Path(tmp) / "plugin"
|
||||
|
||||
@@ -121,13 +121,14 @@ def test_a_second_install_refuses_until_force_replaces_it(home, repo):
|
||||
assert "v: 2" in (_root(home) / "gizmo" / "plugin.js").read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def test_only_an_https_source_is_installed(home, repo):
|
||||
def test_a_local_folder_source_is_installed_like_the_cli_installs_it(home, repo):
|
||||
"""Private plugins live behind ssh keys or in local folders: the Webapp takes every scheme the CLI does."""
|
||||
sha = _commit(repo, {"plugin.js": "export default {}\n"})
|
||||
|
||||
for source in (repo.as_uri(), "http://example.invalid/acme/gizmo.git", "git@example.invalid:acme/gizmo.git"):
|
||||
result = install.install_desktop_plugin(source, ref=sha)
|
||||
assert result["ok"] is False and "https://" in result["error"], (source, result)
|
||||
assert not _root(home).joinpath("gizmo").exists()
|
||||
result = install.install_desktop_plugin(repo.as_uri(), ref=sha)
|
||||
|
||||
assert result["ok"] is True, result
|
||||
assert (_root(home) / result["plugin_name"] / "plugin.js").is_file()
|
||||
|
||||
|
||||
def test_a_link_out_of_the_clone_is_refused(home, repo, tmp_path):
|
||||
|
||||
Reference in New Issue
Block a user