diff --git a/craft_providers/actions/snap_installer.py b/craft_providers/actions/snap_installer.py index e61c51b8..12d26051 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/changelog.rst b/docs/changelog.rst index e3267913..159a4c7d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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) ------------------- diff --git a/tests/unit/actions/test_snap_installer.py b/tests/unit/actions/test_snap_installer.py index 6ee7ed59..942f3a07 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, }