The OSINT investigator's workbench. One case, one folder, every tool. Local-first: your media and your investigations never leave your machine.
JavaScript
Sign the Firefox add-on into a directory of its own (#95)
OsintMeThatc756464a055d
diff --git a/scripts/sign_extension.py b/scripts/sign_extension.pyindex 7345b5b..707bc52 100644--- a/scripts/sign_extension.py+++ b/scripts/sign_extension.py@@ -227,10 +227,12 @@ def sign(staging: Path, artifacts: Path) -> Path:check=True,env=signer_env,)- signed = sorted(artifacts.glob("*.xpi"))+ signed = list(artifacts.glob("*.xpi"))if not signed:raise SystemExit("web-ext reported success but produced no .xpi")- return signed[-1]+ if len(signed) > 1:+ raise SystemExit(f"more than one .xpi in {artifacts}, cannot tell which AMO signed")+ return signed[0]# ---- the command ------------------------------------------------------------@@ -280,13 +282,17 @@ def main(argv: list[str] | None = None) -> int:raise SystemExit(f"no such file: {signed}")else:options.output.mkdir(parents=True, exist_ok=True)+ signed = options.output / ASSET_NAME.format(version=version)with tempfile.TemporaryDirectory(prefix="azimut-xpi-") as scratch:staging = Path(scratch) / "payload"stage_payload(staging)- produced = sign(staging, options.output)- signed = options.output / ASSET_NAME.format(version=version)- if produced != signed:- produced.replace(signed)+ # web-ext signs into an empty directory of its own. In the output+ # directory, an XPI left from an earlier cut would be picked up+ # instead of the one AMO just returned (it once shipped 0.3.0 bytes+ # as 0.3.1).+ fresh = Path(scratch) / "signed"+ fresh.mkdir()+ shutil.move(str(sign(staging, fresh)), str(signed))manifest = build_update_manifest(facts["id"],diff --git a/tests/test_extension_signing.py b/tests/test_extension_signing.pyindex 32a228c..aefa018 100644--- a/tests/test_extension_signing.py+++ b/tests/test_extension_signing.py@@ -188,6 +188,47 @@ def test_signing_credentials_are_passed_in_the_private_environment(monkeypatch,assert captured["kwargs"]["env"]["WEB_EXT_API_SECRET"] == "synthetic-secret"+def test_an_earlier_xpi_in_the_output_is_never_taken_for_the_new_one(monkeypatch, tmp_path):+ """dist-xpi/ outlives a cut. An XPI already sitting there under the asset+ name must be replaced by what AMO returns, and the manifest must hash the new+ bytes, whatever the two files sort as."""+ monkeypatch.setenv("AMO_JWT_ISSUER", "synthetic-issuer")+ monkeypatch.setenv("AMO_JWT_SECRET", "synthetic-secret")+ manifest = tmp_path / "updates.json"+ monkeypatch.setattr(sign_extension, "UPDATE_MANIFEST", manifest)+ output = tmp_path / "dist-xpi"+ output.mkdir()+ version = extinstall.bundled_version()+ stale = output / sign_extension.ASSET_NAME.format(version=version)+ stale.write_bytes(b"an earlier release")++ def fake_run(argv, **kwargs):+ artifacts = Path(argv[argv.index("--artifacts-dir") + 1])+ (artifacts / f"0a1b2c-{version}.xpi").write_bytes(b"freshly signed")++ monkeypatch.setattr(sign_extension.subprocess, "run", fake_run)+ assert sign_extension.main(["--output", str(output)]) == 0++ assert [path.name for path in output.iterdir()] == [stale.name]+ assert stale.read_bytes() == b"freshly signed"+ offered = json.loads(manifest.read_text(encoding="utf-8"))["addons"]+ (entry,) = next(iter(offered.values()))["updates"]+ assert entry["update_hash"] == "sha256:" + hashlib.sha256(b"freshly signed").hexdigest()+++def test_the_signer_refuses_to_guess_between_two_xpis(monkeypatch, tmp_path):+ monkeypatch.setenv("AMO_JWT_ISSUER", "synthetic-issuer")+ monkeypatch.setenv("AMO_JWT_SECRET", "synthetic-secret")++ def fake_run(argv, **kwargs):+ (tmp_path / "a.xpi").write_bytes(b"one")+ (tmp_path / "b.xpi").write_bytes(b"two")++ monkeypatch.setattr(sign_extension.subprocess, "run", fake_run)+ with pytest.raises(SystemExit, match="more than one"):+ sign_extension.sign(tmp_path / "payload", tmp_path)++def test_a_signer_failure_cannot_serialize_the_secret(monkeypatch, tmp_path):monkeypatch.setenv("AMO_JWT_ISSUER", "synthetic-issuer")monkeypatch.setenv("AMO_JWT_SECRET", "synthetic-secret")