-
Notifications
You must be signed in to change notification settings - Fork 606
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with id_token unmarshalling (#538)
- Loading branch information
Showing
2 changed files
with
83 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
package apple | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/markbates/goth" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/markbates/goth" | ||
) | ||
|
||
func Test_Implements_Session(t *testing.T) { | ||
|
@@ -45,3 +47,45 @@ func Test_String(t *testing.T) { | |
|
||
a.Equal(s.String(), s.Marshal()) | ||
} | ||
|
||
func TestIDTokenClaimsUnmarshal(t *testing.T) { | ||
t.Parallel() | ||
a := assert.New(t) | ||
|
||
cases := []struct { | ||
name string | ||
idToken string | ||
expectedClaims IDTokenClaims | ||
}{ | ||
{ | ||
name: "'is_private_email' claim is a string", | ||
idToken: `{"AuthURL":"","AccessToken":"","RefreshToken":"","ExpiresAt":"0001-01-01T00:00:00Z","sub":"","email":"[email protected]","is_private_email":"true"}`, | ||
expectedClaims: IDTokenClaims{ | ||
Email: "[email protected]", | ||
IsPrivateEmail: BoolString{ | ||
StringValue: "true", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "'is_private_email' claim is a boolean", | ||
idToken: `{"AuthURL":"","AccessToken":"","RefreshToken":"","ExpiresAt":"0001-01-01T00:00:00Z","sub":"","email":"[email protected]","is_private_email":true}`, | ||
expectedClaims: IDTokenClaims{ | ||
Email: "[email protected]", | ||
IsPrivateEmail: BoolString{ | ||
BoolValue: true, | ||
IsValidBool: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
idTokenClaims := IDTokenClaims{} | ||
err := json.Unmarshal([]byte(c.idToken), &idTokenClaims) | ||
a.NoError(err) | ||
a.Equal(idTokenClaims, c.expectedClaims) | ||
}) | ||
} | ||
} |