Skip to content

Commit

Permalink
fix(snapcraft_legacy): get assertions for aliased snaps
Browse files Browse the repository at this point in the history
Signed-off-by: Callahan Kovacs <[email protected]>
  • Loading branch information
mr-cal committed Oct 3, 2024
1 parent 7c84397 commit f188bf5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
6 changes: 1 addition & 5 deletions snapcraft_legacy/internal/build_providers/_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,7 @@ def _set_data(self) -> None:

if not snap_revision.startswith("x") and snap_channel:
switch_cmd = [
"snap",
"switch",
self.snap_instance_name,
"--channel",
snap_channel,
"snap", "switch", self.snap_name, "--channel", snap_channel
]

if snap_revision.startswith("x"):
Expand Down
8 changes: 7 additions & 1 deletion snapcraft_legacy/internal/repo/snaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,13 @@ def local_download(self, *, snap_path: str, assertion_path: str) -> None:
# We write an empty assertions file for dangerous installs to
# have a consistent interface.
if self.has_assertions():
assertions.append(["snap-declaration", "snap-name={}".format(self.name)])
assertions.append(
[
"snap-declaration",
# use the snap name without any alias
f"snap-name={self.name.partition('_')[0]}"
]
)
assertions.append(
[
"snap-revision",
Expand Down
42 changes: 42 additions & 0 deletions tests/legacy/unit/repo/test_snaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,48 @@ def test_download_from_host(self):
]
)

def test_download_from_host_alias(self):
"""Download an aliased snap from the host."""
fake_get_assertion = fixtures.MockPatch(
"snapcraft_legacy.internal.repo.snaps.get_assertion",
return_value=b"foo-assert",
)
self.useFixture(fake_get_assertion)

self.fake_snapd.snaps_result = [
{
"id": "fake-snap-id",
"name": "fake-snap_alias",
"channel": "stable",
"revision": "10",
}
]

snap_pkg = snaps.SnapPackage("fake-snap_alias/strict/stable")
snap_pkg.local_download(
snap_path="fake-snap.snap", assertion_path="fake-snap.assert"
)

self.assertThat("fake-snap.snap", FileExists())
self.assertThat(
"fake-snap.assert", FileContains("foo-assert\nfoo-assert\nfoo-assert\n")
)
fake_get_assertion.mock.assert_has_calls(
[
mock.call(
[
"account-key",
"public-key-sha3-384=BWDEoaqyr25nF5SNCvEv2v7QnM9QsfCc0PBMYD_i2NGSQ32EF2d4D0hqUel3m8ul",
]
),
# uses the non-aliased name
mock.call(["snap-declaration", "snap-name=fake-snap"]),
mock.call(
["snap-revision", "snap-revision=10", "snap-id=fake-snap-id"]
),
]
)

def test_download_from_host_dangerous(self):
fake_get_assertion = fixtures.MockPatch(
"snapcraft_legacy.internal.repo.snaps.get_assertion",
Expand Down

0 comments on commit f188bf5

Please sign in to comment.