From e5a134a10f225e215d4c52b684c39a892216aa43 Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Mon, 7 Oct 2019 12:26:27 -0700 Subject: [PATCH] fixed: panic on Normalizing nil claims --- client/utils.go | 4 ++++ client/utils_test.go | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/client/utils.go b/client/utils.go index f17bcf3..c0af6d8 100644 --- a/client/utils.go +++ b/client/utils.go @@ -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) } diff --git a/client/utils_test.go b/client/utils_test.go index 7910298..b43db02 100644 --- a/client/utils_test.go +++ b/client/utils_test.go @@ -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) + }) + }) }) }