dex/vendor/github.com/ericchiang/oidc/oidc_test.go

55 lines
889 B
Go
Raw Normal View History

2016-07-26 01:30:28 +05:30
package oidc
import "testing"
func TestClientVerifier(t *testing.T) {
tests := []struct {
clientID string
payload string
wantErr bool
}{
{
clientID: "1",
payload: `{"aud":"1"}`,
},
{
clientID: "1",
payload: `{"aud":"2"}`,
wantErr: true,
},
{
clientID: "1",
payload: `{"aud":["1"]}`,
},
{
clientID: "1",
payload: `{"aud":["1", "2"]}`,
},
{
clientID: "3",
payload: `{"aud":["1", "2"]}`,
wantErr: true,
},
{
clientID: "3",
payload: `{"aud":}`, // invalid JSON
wantErr: true,
},
{
clientID: "1",
payload: `{}`,
wantErr: true,
},
}
for i, tc := range tests {
err := (clientVerifier{tc.clientID}).verifyIDTokenPayload([]byte(tc.payload))
if err != nil && !tc.wantErr {
t.Errorf("case %d: %v", i)
}
if err == nil && tc.wantErr {
t.Errorf("case %d: expected error")
}
}
}