Skip to content

Commit

Permalink
fix: get assertions for aliased snaps (#671)
Browse files Browse the repository at this point in the history
Signed-off-by: Callahan Kovacs <[email protected]>
  • Loading branch information
mr-cal authored Oct 2, 2024
1 parent f09f22d commit 4fbc046
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion craft_providers/actions/snap_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def _get_assertions_file(
"public-key-sha3-384=BWDEoaqyr25nF5SNCvEv2v"
"7QnM9QsfCc0PBMYD_i2NGSQ32EF2d4D0hqUel3m8ul",
],
["snap-declaration", f"snap-name={snap_name}"],
["snap-declaration", f"snap-name={snap_name.partition('_')[0]}"],
["snap-revision", f"snap-revision={snap_revision}", f"snap-id={snap_id}"],
["account", f"account-id={snap_publisher_id}"],
]
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ included in each version.
1.20.4 (2024-09-27)
-------------------
- ``requests-unixsocket`` dependency is replaced with ``requests-unixsocket2``
- Fix a bug where signed aliased snaps couldn't be injected into the build
environment.

1.20.3 (2024-04-11)
-------------------
Expand Down
32 changes: 25 additions & 7 deletions tests/unit/actions/test_snap_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,16 @@ def test_inject_from_host_dangerous(
}


@pytest.mark.parametrize(
("snap_name", "snap_instance_name"),
[
pytest.param("test-name", "test-name", id="non-aliased"),
pytest.param("test-name", "test-name_suffix", id="aliased"),
],
)
def test_inject_from_host_not_dangerous(
snap_instance_name,
snap_name,
config_fixture,
mock_get_host_snap_info,
mock_requests,
Expand All @@ -427,7 +436,7 @@ def test_inject_from_host_not_dangerous(
"snap",
"known",
"snap-declaration",
"snap-name=test-name",
f"snap-name={snap_name}",
]
)
fake_process.register_subprocess(
Expand All @@ -452,28 +461,37 @@ def test_inject_from_host_not_dangerous(
"fake-executor",
"snap",
"ack",
"/tmp/test-name.assert",
f"/tmp/{snap_name}.assert",
]
)
fake_process.register_subprocess(
[
"fake-executor",
"snap",
"install",
"/tmp/test-name.snap",
f"/tmp/{snap_name}.snap",
]
)

snap_installer.inject_from_host(
executor=fake_executor, snap_name="test-name", classic=False
executor=fake_executor, snap_name=snap_instance_name, classic=False
)

mock_requests.get.assert_called_with(
"http+unix://%2Frun%2Fsnapd.socket/v2/snaps/test-name/file"
f"http+unix://%2Frun%2Fsnapd.socket/v2/snaps/{snap_instance_name}/file"
)

assert len(fake_process.calls) == 6
assert Exact("Installing snap 'test-name' from host (classic=False)") in logs.debug
if snap_instance_name == snap_name:
assert (
rf"Installing snap {snap_instance_name!r} from host \(classic=False\)"
in logs.debug
)
else:
assert (
rf"Installing snap {snap_instance_name!r} from host as {snap_name!r} in instance \(classic=False\)\."
in logs.debug
)
assert "Revisions found: host='2', target='1'" in logs.debug

# check saved config
Expand All @@ -484,7 +502,7 @@ def test_inject_from_host_not_dangerous(
)
config = InstanceConfiguration(**yaml.safe_load(saved_config_record["content"]))
assert config.snaps is not None
assert config.snaps["test-name"] == {
assert config.snaps[snap_name] == {
"revision": "2",
"source": snap_installer.SNAP_SRC_HOST,
}
Expand Down

0 comments on commit 4fbc046

Please sign in to comment.