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.
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"`

View File

@ -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))
}

View File

@ -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"]`