Skip to content

Commit

Permalink
fix: fix IsTopLevelManifest calculation for versioned manifests (theu…
Browse files Browse the repository at this point in the history
…pdateframework#381)

* fix: fix IsTopLevelManifest calculation for versioned manifests

This change now correctly recognizes versioned manifests of the form x.root.json as top-level manifests.

Signed-off-by: Asra Ali <asraa@google.com>
  • Loading branch information
asraa authored Sep 12, 2022
1 parent 61872a3 commit a9ddd89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/roles/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}

Expand Down
6 changes: 6 additions & 0 deletions internal/roles/roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a9ddd89

Please sign in to comment.