Skip to content

Commit

Permalink
Add check for negative name indices in flamebearer profiles (#3324)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-p authored May 29, 2024
1 parent 24a46e4 commit ed202fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/og/structs/flamebearer/flamebearer.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ func (fb FlamebearerProfileV1) Validate() error {
if l[i] >= len(fb.Flamebearer.Names) {
return fmt.Errorf("invalid name index %d, it should be smaller than %d", l[i], len(fb.Flamebearer.Levels))
}
if l[i] < 0 {
return fmt.Errorf("invalid name index %d, it should be a non-negative value", l[i])
}
}
}
return nil
Expand Down
15 changes: 15 additions & 0 deletions pkg/og/structs/flamebearer/flamebearer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,21 @@ var _ = Describe("Checking profile validation", func() {
})
})

When("the name index is negative", func() {
Context("and we validate a single profile", func() {
var fb FlamebearerProfile
BeforeEach(func() {
fb.Metadata.Format = "single"
fb.Flamebearer.Names = []string{"name"}
fb.Flamebearer.Levels = [][]int{{0, 0, 0, -1}}
})

It("returns an error", func() {
Expect(fb.Validate()).To(MatchError("invalid name index -1, it should be a non-negative value"))
})
})
})

When("everything is valid", func() {
Context("and we validate a single profile", func() {
var fb FlamebearerProfile
Expand Down

0 comments on commit ed202fa

Please sign in to comment.