Skip to content

Commit

Permalink
Merge branch 'eliquious-fix-multiple-audience-bug'
Browse files Browse the repository at this point in the history
  • Loading branch information
ericlagergren committed Mar 9, 2016
2 parents 4f3649f + 0b9113d commit 1ada734
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
JOSE
============
[![Build Status](https://travis-ci.org/SermoDigital/jose.svg?branch=master)](https://travis-ci.org/SermoDigital/jose)
[![GoDoc](https://godoc.org/github.com/SermoDigital/jose?status.svg)](https://godoc.org/github.com/SermoDigital/jose)

JOSE is a comprehensive set of JWT, JWS, and JWE libraries.

Expand Down
4 changes: 3 additions & 1 deletion jwt/claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ func (c Claims) Audience() ([]string, bool) {
return []string{t}, true
case []string:
return t, true
case interface{}, []interface{}:
case []interface{}:
return stringify(t...)
case interface{}:
return stringify(t)
}
return nil, false
Expand Down
86 changes: 85 additions & 1 deletion jwt/claims_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,85 @@
package jwt
package jwt_test

import (
"testing"

"github.com/SermoDigital/jose/crypto"
"github.com/SermoDigital/jose/jws"
)

func TestMultipleAudienceBug_AfterMarshal(t *testing.T) {

// Create JWS claims
claims := jws.Claims{}
claims.SetAudience("example.com", "api.example.com")

token := jws.NewJWT(claims, crypto.SigningMethodHS256)
serializedToken, _ := token.Serialize([]byte("abcdef"))

// Unmarshal JSON
newToken, _ := jws.ParseJWT(serializedToken)

c := newToken.Claims()

// Get Audience
aud, ok := c.Audience()
if !ok {

// Fails
t.Fail()
}

t.Logf("aud Value: %s", aud)
t.Logf("aud Type : %T", aud)
}

func TestMultipleAudienceFix_AfterMarshal(t *testing.T) {
// Create JWS claims
claims := jws.Claims{}
claims.SetAudience("example.com", "api.example.com")

token := jws.NewJWT(claims, crypto.SigningMethodHS256)
serializedToken, _ := token.Serialize([]byte("abcdef"))

// Unmarshal JSON
newToken, _ := jws.ParseJWT(serializedToken)

c := newToken.Claims()

// Get Audience
aud, ok := c.Audience()
if !ok {

// Fails
t.Fail()
}

t.Logf("aud len(): %d", len(aud))
t.Logf("aud Value: %s", aud)
t.Logf("aud Type : %T", aud)
}

func TestSingleAudienceFix_AfterMarshal(t *testing.T) {
// Create JWS claims
claims := jws.Claims{}
claims.SetAudience("example.com")

token := jws.NewJWT(claims, crypto.SigningMethodHS256)
serializedToken, _ := token.Serialize([]byte("abcdef"))

// Unmarshal JSON
newToken, _ := jws.ParseJWT(serializedToken)
c := newToken.Claims()

// Get Audience
aud, ok := c.Audience()
if !ok {

// Fails
t.Fail()
}

t.Logf("aud len(): %d", len(aud))
t.Logf("aud Value: %s", aud)
t.Logf("aud Type : %T", aud)
}

0 comments on commit 1ada734

Please sign in to comment.