From 0839cc204892d2ac0e09588e1636f63234561929 Mon Sep 17 00:00:00 2001 From: Ben Hearsum Date: Wed, 15 Jan 2025 21:32:20 -0500 Subject: [PATCH] avoid hardcoding langpack signing format --- iscript/src/iscript/autograph.py | 15 ++++----------- iscript/tests/test_autograph.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/iscript/src/iscript/autograph.py b/iscript/src/iscript/autograph.py index 45404ed0f..869552b67 100644 --- a/iscript/src/iscript/autograph.py +++ b/iscript/src/iscript/autograph.py @@ -500,17 +500,10 @@ def langpack_id(app): return id -async def sign_langpacks(config, sign_config, all_paths): - """Signs langpacks that are specified in all_paths. - - Raises: - IScriptError if we don't have any valid language packs to sign in any path. - - """ +async def sign_langpacks(config, sign_config, all_paths, fmt): + """Signs langpacks that are specified in all_paths.""" for app in all_paths: - app.check_required_attrs(["orig_path", "formats", "artifact_prefix"]) - if not {"autograph_langpack"} & set(app.formats): - raise IScriptError(f"{app.formats} does not contain 'autograph_langpack'") + app.check_required_attrs(["orig_path", "artifact_prefix"]) app.target_bundle_path = "{}/{}{}".format(config["artifact_dir"], app.artifact_prefix, app.orig_path.split(app.artifact_prefix)[1]) id = langpack_id(app) @@ -519,7 +512,7 @@ async def sign_langpacks(config, sign_config, all_paths): await sign_file_with_autograph( sign_config, app.orig_path, - "autograph_langpack", + fmt, to=app.target_bundle_path, keyid=LANGPACK_AUTOGRAPH_KEY_ID[sign_config.get("release_type", "dep")], extension_id=id, diff --git a/iscript/tests/test_autograph.py b/iscript/tests/test_autograph.py index 8af01159f..0d3b9f906 100644 --- a/iscript/tests/test_autograph.py +++ b/iscript/tests/test_autograph.py @@ -328,6 +328,38 @@ async def fake_call(url, *args, **kwargs): await autograph.sign_omnija_with_autograph(config, sign_config, tmp_path, fmt) +@pytest.mark.asyncio +@pytest.mark.parametrize( + "fmt,expected_url", + ( + ("autograph_langpack", "https://autograph-hsm.dev.mozaws.net"), + ("stage_autograph_langpack", "https://autograph-stage.dev.mozaws.net"), + ("gcp_prod_autograph_langpack", "https://autograph-gcp.dev.mozaws.net"), + ), +) +async def test_langpack_autograph(mocker, tmp_path, sign_config, fmt, expected_url): + dir = tmp_path / "public" / "build" + os.makedirs(dir) + orig = dir / "test.xpi" + with open(orig, "w+") as f: + f.write("") + + lid = mocker.patch("iscript.autograph.langpack_id") + lid.return_value = "test-xpi" + + async def fake_call(url, *args, **kwargs): + assert expected_url in url + return [{"signed_file": base64.b64encode(b"siglangpacksig")}] + + mocker.patch.object(autograph, "call_autograph", fake_call) + + config = {"artifact_dir": tmp_path} + app = App() + app.orig_path = orig.as_posix() + app.artifact_prefix = "public/build" + await autograph.sign_langpacks(config, sign_config, [app], fmt) + + @pytest.mark.asyncio @pytest.mark.parametrize( "fmt,expected_url",