Skip to content

Commit

Permalink
avoid hardcoding langpack signing format
Browse files Browse the repository at this point in the history
  • Loading branch information
bhearsum committed Jan 16, 2025
1 parent 58d933f commit 0839cc2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
15 changes: 4 additions & 11 deletions iscript/src/iscript/autograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
32 changes: 32 additions & 0 deletions iscript/tests/test_autograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0839cc2

Please sign in to comment.