refactor: rename WeakStringList to AudienceList

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
Mark Sagi-Kazar 2022-10-21 11:11:50 +02:00
parent 3472f7a8e3
commit d6ea77ae65
No known key found for this signature in database
GPG key ID: 31AB0439F4C5C90E
3 changed files with 19 additions and 19 deletions

View file

@ -42,13 +42,13 @@ type ResourceActions struct {
// ClaimSet describes the main section of a JSON Web Token. // ClaimSet describes the main section of a JSON Web Token.
type ClaimSet struct { type ClaimSet struct {
// Public claims // Public claims
Issuer string `json:"iss"` Issuer string `json:"iss"`
Subject string `json:"sub"` Subject string `json:"sub"`
Audience WeakStringList `json:"aud"` Audience AudienceList `json:"aud"`
Expiration int64 `json:"exp"` Expiration int64 `json:"exp"`
NotBefore int64 `json:"nbf"` NotBefore int64 `json:"nbf"`
IssuedAt int64 `json:"iat"` IssuedAt int64 `json:"iat"`
JWTID string `json:"jti"` JWTID string `json:"jti"`
// Private claims // Private claims
Access []*ResourceActions `json:"access"` Access []*ResourceActions `json:"access"`

View file

@ -5,10 +5,10 @@ import (
"reflect" "reflect"
) )
// WeakStringList is a slice of strings that can be deserialized from either a single string value or a list of strings. // AudienceList is a slice of strings that can be deserialized from either a single string value or a list of strings.
type WeakStringList []string type AudienceList []string
func (s *WeakStringList) UnmarshalJSON(data []byte) (err error) { func (s *AudienceList) UnmarshalJSON(data []byte) (err error) {
var value interface{} var value interface{}
if err = json.Unmarshal(data, &value); err != nil { if err = json.Unmarshal(data, &value); err != nil {
@ -50,6 +50,6 @@ func (s *WeakStringList) UnmarshalJSON(data []byte) (err error) {
return return
} }
func (s WeakStringList) MarshalJSON() (b []byte, err error) { func (s AudienceList) MarshalJSON() (b []byte, err error) {
return json.Marshal([]string(s)) return json.Marshal([]string(s))
} }

View file

@ -5,19 +5,19 @@ import (
"testing" "testing"
) )
func TestWeakStringList_Unmarshal(t *testing.T) { func TestAudienceList_Unmarshal(t *testing.T) {
t.Run("OK", func(t *testing.T) { t.Run("OK", func(t *testing.T) {
testCases := []struct { testCases := []struct {
value string value string
expected WeakStringList expected AudienceList
}{ }{
{ {
value: `"audience"`, value: `"audience"`,
expected: WeakStringList{"audience"}, expected: AudienceList{"audience"},
}, },
{ {
value: `["audience1", "audience2"]`, value: `["audience1", "audience2"]`,
expected: WeakStringList{"audience1", "audience2"}, expected: AudienceList{"audience1", "audience2"},
}, },
{ {
value: `null`, value: `null`,
@ -29,7 +29,7 @@ func TestWeakStringList_Unmarshal(t *testing.T) {
testCase := testCase testCase := testCase
t.Run("", func(t *testing.T) { t.Run("", func(t *testing.T) {
var actual WeakStringList var actual AudienceList
err := json.Unmarshal([]byte(testCase.value), &actual) err := json.Unmarshal([]byte(testCase.value), &actual)
if err != nil { if err != nil {
@ -42,7 +42,7 @@ func TestWeakStringList_Unmarshal(t *testing.T) {
}) })
t.Run("Error", func(t *testing.T) { t.Run("Error", func(t *testing.T) {
var actual WeakStringList var actual AudienceList
err := json.Unmarshal([]byte("1234"), &actual) err := json.Unmarshal([]byte("1234"), &actual)
if err == nil { if err == nil {
@ -51,8 +51,8 @@ func TestWeakStringList_Unmarshal(t *testing.T) {
}) })
} }
func TestWeakStringList_Marshal(t *testing.T) { func TestAudienceList_Marshal(t *testing.T) {
value := WeakStringList{"audience"} value := AudienceList{"audience"}
expected := `["audience"]` expected := `["audience"]`