diff --git a/internal/roles/roles.go b/internal/roles/roles.go index f7841c26..0b134b2a 100644 --- a/internal/roles/roles.go +++ b/internal/roles/roles.go @@ -22,6 +22,13 @@ func IsDelegatedTargetsRole(name string) bool { } func IsTopLevelManifest(name string) bool { + if IsVersionedManifest(name) { + var found bool + _, name, found = strings.Cut(name, ".") + if !found { + panic("expected a versioned manifest of the form x.role.json") + } + } return IsTopLevelRole(strings.TrimSuffix(name, ".json")) } diff --git a/internal/roles/roles_test.go b/internal/roles/roles_test.go index 17ed265b..8af1b02c 100644 --- a/internal/roles/roles_test.go +++ b/internal/roles/roles_test.go @@ -24,18 +24,24 @@ func TestIsDelegatedTargetsRole(t *testing.T) { func TestIsTopLevelManifest(t *testing.T) { assert.True(t, IsTopLevelManifest("root.json")) + assert.True(t, IsTopLevelManifest("1.root.json")) assert.True(t, IsTopLevelManifest("targets.json")) assert.True(t, IsTopLevelManifest("timestamp.json")) assert.True(t, IsTopLevelManifest("snapshot.json")) + assert.True(t, IsTopLevelManifest("2.snapshot.json")) assert.False(t, IsTopLevelManifest("bins.json")) + assert.False(t, IsTopLevelManifest("3.bins.json")) } func TestIsDelegatedTargetsManifest(t *testing.T) { assert.False(t, IsDelegatedTargetsManifest("root.json")) + assert.False(t, IsDelegatedTargetsManifest("1.root.json")) assert.False(t, IsDelegatedTargetsManifest("targets.json")) + assert.False(t, IsDelegatedTargetsManifest("2.targets.json")) assert.False(t, IsDelegatedTargetsManifest("timestamp.json")) assert.False(t, IsDelegatedTargetsManifest("snapshot.json")) assert.True(t, IsDelegatedTargetsManifest("bins.json")) + assert.True(t, IsDelegatedTargetsManifest("2.bins.json")) } func TestIsVersionedManifest(t *testing.T) {