diff --git a/pkg/token/bearer.go b/pkg/token/bearer.go index 812faf26..8ac333e4 100644 --- a/pkg/token/bearer.go +++ b/pkg/token/bearer.go @@ -23,7 +23,14 @@ type BearerToken struct { token acl.BearerToken } -func (b BearerToken) ToV2() *acl.BearerToken { +// ToV2 converts BearerToken to v2 BearerToken message. +// +// Nil BearerToken converts to nil. +func (b *BearerToken) ToV2() *acl.BearerToken { + if b == nil { + return nil + } + return &b.token } @@ -100,6 +107,7 @@ func NewBearerToken() *BearerToken { return b } +// ToV2 converts BearerToken to v2 BearerToken message. func NewBearerTokenFromV2(v2 *acl.BearerToken) *BearerToken { if v2 == nil { v2 = new(acl.BearerToken) diff --git a/pkg/token/bearer_test.go b/pkg/token/bearer_test.go index 38bf47b1..26dca9e5 100644 --- a/pkg/token/bearer_test.go +++ b/pkg/token/bearer_test.go @@ -55,3 +55,11 @@ func TestFilterEncoding(t *testing.T) { require.Equal(t, f, d2) }) } + +func TestBearerToken_ToV2(t *testing.T) { + t.Run("nil", func(t *testing.T) { + var x *token.BearerToken + + require.Nil(t, x.ToV2()) + }) +}