diff --git a/craft_providers/actions/snap_installer.py b/craft_providers/actions/snap_installer.py index efefa04a..cb214ecb 100644 --- a/craft_providers/actions/snap_installer.py +++ b/craft_providers/actions/snap_installer.py @@ -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}"], ] diff --git a/docs/reference/changelog.rst b/docs/reference/changelog.rst index 3f5ff63d..1b89c7a1 100644 --- a/docs/reference/changelog.rst +++ b/docs/reference/changelog.rst @@ -4,6 +4,11 @@ Changelog See the `Releases page`_ on GitHub for a complete list of commits that are included in each version. +2.0.3 (2024-10-02) +------------------ +- Fix a bug where signed aliased snaps couldn't be injected into the build + environment. + 2.0.2 (2024-09-26) ------------------ - Improve multipass version parsing diff --git a/pyproject.toml b/pyproject.toml index 8e464181..0a0ea9f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,7 @@ docs = [ "sphinx-autobuild==2024.9.19", "sphinx-lint==1.0.0", "sphinx-tabs==3.4.5", - "canonical-sphinx~=0.1" + "canonical-sphinx==0.1.0" ] [build-system] diff --git a/tests/unit/actions/test_snap_installer.py b/tests/unit/actions/test_snap_installer.py index 6f98677a..a2a394b9 100644 --- a/tests/unit/actions/test_snap_installer.py +++ b/tests/unit/actions/test_snap_installer.py @@ -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, @@ -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( @@ -452,7 +461,7 @@ def test_inject_from_host_not_dangerous( "fake-executor", "snap", "ack", - "/tmp/test-name.assert", + f"/tmp/{snap_name}.assert", ] ) fake_process.register_subprocess( @@ -460,20 +469,29 @@ def test_inject_from_host_not_dangerous( "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 @@ -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, }