From d6ea77ae6517bd7443e9d1c88c8ac05d56603197 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Fri, 21 Oct 2022 11:11:50 +0200 Subject: [PATCH] refactor: rename WeakStringList to AudienceList Signed-off-by: Mark Sagi-Kazar --- registry/auth/token/token.go | 14 +++++++------- registry/auth/token/types.go | 8 ++++---- registry/auth/token/types_test.go | 16 ++++++++-------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/registry/auth/token/token.go b/registry/auth/token/token.go index 4c182d95b..ec2247540 100644 --- a/registry/auth/token/token.go +++ b/registry/auth/token/token.go @@ -42,13 +42,13 @@ type ResourceActions struct { // ClaimSet describes the main section of a JSON Web Token. type ClaimSet struct { // Public claims - Issuer string `json:"iss"` - Subject string `json:"sub"` - Audience WeakStringList `json:"aud"` - Expiration int64 `json:"exp"` - NotBefore int64 `json:"nbf"` - IssuedAt int64 `json:"iat"` - JWTID string `json:"jti"` + Issuer string `json:"iss"` + Subject string `json:"sub"` + Audience AudienceList `json:"aud"` + Expiration int64 `json:"exp"` + NotBefore int64 `json:"nbf"` + IssuedAt int64 `json:"iat"` + JWTID string `json:"jti"` // Private claims Access []*ResourceActions `json:"access"` diff --git a/registry/auth/token/types.go b/registry/auth/token/types.go index 4559d6daf..2aa5c9bab 100644 --- a/registry/auth/token/types.go +++ b/registry/auth/token/types.go @@ -5,10 +5,10 @@ import ( "reflect" ) -// WeakStringList is a slice of strings that can be deserialized from either a single string value or a list of strings. -type WeakStringList []string +// AudienceList is a slice of strings that can be deserialized from either a single string value or a list of strings. +type AudienceList []string -func (s *WeakStringList) UnmarshalJSON(data []byte) (err error) { +func (s *AudienceList) UnmarshalJSON(data []byte) (err error) { var value interface{} if err = json.Unmarshal(data, &value); err != nil { @@ -50,6 +50,6 @@ func (s *WeakStringList) UnmarshalJSON(data []byte) (err error) { return } -func (s WeakStringList) MarshalJSON() (b []byte, err error) { +func (s AudienceList) MarshalJSON() (b []byte, err error) { return json.Marshal([]string(s)) } diff --git a/registry/auth/token/types_test.go b/registry/auth/token/types_test.go index 283d86a80..5e5477611 100644 --- a/registry/auth/token/types_test.go +++ b/registry/auth/token/types_test.go @@ -5,19 +5,19 @@ import ( "testing" ) -func TestWeakStringList_Unmarshal(t *testing.T) { +func TestAudienceList_Unmarshal(t *testing.T) { t.Run("OK", func(t *testing.T) { testCases := []struct { value string - expected WeakStringList + expected AudienceList }{ { value: `"audience"`, - expected: WeakStringList{"audience"}, + expected: AudienceList{"audience"}, }, { value: `["audience1", "audience2"]`, - expected: WeakStringList{"audience1", "audience2"}, + expected: AudienceList{"audience1", "audience2"}, }, { value: `null`, @@ -29,7 +29,7 @@ func TestWeakStringList_Unmarshal(t *testing.T) { testCase := testCase t.Run("", func(t *testing.T) { - var actual WeakStringList + var actual AudienceList err := json.Unmarshal([]byte(testCase.value), &actual) if err != nil { @@ -42,7 +42,7 @@ func TestWeakStringList_Unmarshal(t *testing.T) { }) t.Run("Error", func(t *testing.T) { - var actual WeakStringList + var actual AudienceList err := json.Unmarshal([]byte("1234"), &actual) if err == nil { @@ -51,8 +51,8 @@ func TestWeakStringList_Unmarshal(t *testing.T) { }) } -func TestWeakStringList_Marshal(t *testing.T) { - value := WeakStringList{"audience"} +func TestAudienceList_Marshal(t *testing.T) { + value := AudienceList{"audience"} expected := `["audience"]`