Skip to content

Commit

Permalink
fixed: panic on Normalizing nil claims
Browse files Browse the repository at this point in the history
  • Loading branch information
primalmotion committed Oct 7, 2019
1 parent cbec154 commit e5a134a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ func UnsecureClaimsFromToken(token string) ([]string, error) {
// NormalizeAuth normalizes the response to a simple structure.
func NormalizeAuth(c *types.MidgardClaims) (claims []string) {

if c == nil {
return
}

if c.Subject != "" {
claims = append(claims, "@auth:subject="+c.Subject)
}
Expand Down
9 changes: 9 additions & 0 deletions client/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ func TestUtils_NormalizeAuth(t *testing.T) {
So(v, ShouldContain, "@auth:d2=v2")
})
})

Convey("When I normalize nil claims", func() {

v := NormalizeAuth(nil)

Convey("Then the subject should be correct", func() {
So(len(v), ShouldEqual, 0)
})
})
})
}

Expand Down

0 comments on commit e5a134a

Please sign in to comment.