2015-08-18 05:57:27 +05:30
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2015-10-13 03:08:02 +05:30
|
|
|
"encoding/base64"
|
2015-08-18 05:57:27 +05:30
|
|
|
"errors"
|
2015-09-01 02:08:06 +05:30
|
|
|
"fmt"
|
2015-08-18 05:57:27 +05:30
|
|
|
"net/url"
|
|
|
|
"reflect"
|
2016-06-17 06:01:33 +05:30
|
|
|
"strings"
|
2015-08-18 05:57:27 +05:30
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/coreos/go-oidc/jose"
|
|
|
|
"github.com/coreos/go-oidc/key"
|
|
|
|
"github.com/coreos/go-oidc/oauth2"
|
|
|
|
"github.com/coreos/go-oidc/oidc"
|
2016-01-13 06:46:28 +05:30
|
|
|
"github.com/kylelemons/godebug/pretty"
|
2016-06-03 01:35:18 +05:30
|
|
|
|
|
|
|
"github.com/coreos/dex/client"
|
|
|
|
"github.com/coreos/dex/db"
|
|
|
|
"github.com/coreos/dex/refresh/refreshtest"
|
2016-06-11 04:17:40 +05:30
|
|
|
"github.com/coreos/dex/scope"
|
2016-06-03 01:35:18 +05:30
|
|
|
"github.com/coreos/dex/session/manager"
|
|
|
|
"github.com/coreos/dex/user"
|
2015-08-18 05:57:27 +05:30
|
|
|
)
|
|
|
|
|
2016-05-12 22:23:01 +05:30
|
|
|
var validRedirURL = url.URL{
|
|
|
|
Scheme: "http",
|
|
|
|
Host: "client.example.com",
|
|
|
|
Path: "/callback",
|
|
|
|
}
|
2016-02-10 04:36:07 +05:30
|
|
|
|
2015-08-18 05:57:27 +05:30
|
|
|
type StaticKeyManager struct {
|
|
|
|
key.PrivateKeyManager
|
|
|
|
expiresAt time.Time
|
|
|
|
signer jose.Signer
|
|
|
|
keys []jose.JWK
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *StaticKeyManager) ExpiresAt() time.Time {
|
|
|
|
return m.expiresAt
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *StaticKeyManager) Signer() (jose.Signer, error) {
|
|
|
|
return m.signer, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *StaticKeyManager) JWKs() ([]jose.JWK, error) {
|
|
|
|
return m.keys, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type StaticSigner struct {
|
|
|
|
sig []byte
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ss *StaticSigner) ID() string {
|
|
|
|
return "static"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ss *StaticSigner) Alg() string {
|
|
|
|
return "static"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ss *StaticSigner) Verify(sig, data []byte) error {
|
|
|
|
if !reflect.DeepEqual(ss.sig, sig) {
|
|
|
|
return errors.New("signature mismatch")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ss *StaticSigner) Sign(data []byte) ([]byte, error) {
|
|
|
|
return ss.sig, ss.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ss *StaticSigner) JWK() jose.JWK {
|
|
|
|
return jose.JWK{}
|
|
|
|
}
|
|
|
|
|
2016-02-10 00:40:28 +05:30
|
|
|
func staticGenerateCodeFunc(code string) manager.GenerateCodeFunc {
|
2015-08-18 05:57:27 +05:30
|
|
|
return func() (string, error) {
|
|
|
|
return code, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeNewUserRepo() (user.UserRepo, error) {
|
2016-02-10 01:52:40 +05:30
|
|
|
userRepo := db.NewUserRepo(db.NewMemDB())
|
2015-08-18 05:57:27 +05:30
|
|
|
|
|
|
|
id := "testid-1"
|
|
|
|
err := userRepo.Create(nil, user.User{
|
|
|
|
ID: id,
|
|
|
|
Email: "testname@example.com",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = userRepo.AddRemoteIdentity(nil, id, user.RemoteIdentity{
|
|
|
|
ConnectorID: "test_connector_id",
|
|
|
|
ID: "YYY",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return userRepo, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServerProviderConfig(t *testing.T) {
|
|
|
|
srv := &Server{IssuerURL: url.URL{Scheme: "http", Host: "server.example.com"}}
|
|
|
|
|
|
|
|
want := oidc.ProviderConfig{
|
2016-01-13 06:46:28 +05:30
|
|
|
Issuer: &url.URL{Scheme: "http", Host: "server.example.com"},
|
|
|
|
AuthEndpoint: &url.URL{Scheme: "http", Host: "server.example.com", Path: "/auth"},
|
|
|
|
TokenEndpoint: &url.URL{Scheme: "http", Host: "server.example.com", Path: "/token"},
|
|
|
|
KeysEndpoint: &url.URL{Scheme: "http", Host: "server.example.com", Path: "/keys"},
|
|
|
|
|
2015-08-18 05:57:27 +05:30
|
|
|
GrantTypesSupported: []string{oauth2.GrantTypeAuthCode, oauth2.GrantTypeClientCreds},
|
|
|
|
ResponseTypesSupported: []string{"code"},
|
|
|
|
SubjectTypesSupported: []string{"public"},
|
2016-01-13 06:46:28 +05:30
|
|
|
IDTokenSigningAlgValues: []string{"RS256"},
|
2015-08-18 05:57:27 +05:30
|
|
|
TokenEndpointAuthMethodsSupported: []string{"client_secret_basic"},
|
|
|
|
}
|
|
|
|
got := srv.ProviderConfig()
|
|
|
|
|
2016-01-13 06:46:28 +05:30
|
|
|
if diff := pretty.Compare(want, got); diff != "" {
|
|
|
|
t.Fatalf("provider config did not match expected: %s", diff)
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServerNewSession(t *testing.T) {
|
2016-02-10 00:40:28 +05:30
|
|
|
sm := manager.NewSessionManager(db.NewSessionRepo(db.NewMemDB()), db.NewSessionKeyRepo(db.NewMemDB()))
|
2015-08-18 05:57:27 +05:30
|
|
|
srv := &Server{
|
|
|
|
SessionManager: sm,
|
|
|
|
}
|
|
|
|
|
|
|
|
state := "pants"
|
|
|
|
nonce := "oncenay"
|
2016-04-15 04:27:53 +05:30
|
|
|
ci := client.Client{
|
2015-08-18 05:57:27 +05:30
|
|
|
Credentials: oidc.ClientCredentials{
|
2016-05-12 22:23:01 +05:30
|
|
|
ID: testClientID,
|
|
|
|
Secret: clientTestSecret,
|
2015-08-18 05:57:27 +05:30
|
|
|
},
|
|
|
|
Metadata: oidc.ClientMetadata{
|
2016-01-13 06:46:28 +05:30
|
|
|
RedirectURIs: []url.URL{
|
2015-08-18 05:57:27 +05:30
|
|
|
url.URL{
|
|
|
|
Scheme: "http",
|
|
|
|
Host: "client.example.com",
|
|
|
|
Path: "/callback",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-01-13 06:46:28 +05:30
|
|
|
key, err := srv.NewSession("bogus_idpc", ci.Credentials.ID, state, ci.Metadata.RedirectURIs[0], nonce, false, []string{"openid"})
|
2015-08-18 05:57:27 +05:30
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
sessionID, err := sm.ExchangeKey(key)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Session not retreivable: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ses, err := sm.AttachRemoteIdentity(sessionID, oidc.Identity{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unable to add Identity to Session: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-01-13 06:46:28 +05:30
|
|
|
if !reflect.DeepEqual(ci.Metadata.RedirectURIs[0], ses.RedirectURL) {
|
|
|
|
t.Fatalf("Session created with incorrect RedirectURL: want=%#v got=%#v", ci.Metadata.RedirectURIs[0], ses.RedirectURL)
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if ci.Credentials.ID != ses.ClientID {
|
|
|
|
t.Fatalf("Session created with incorrect ClientID: want=%q got=%q", ci.Credentials.ID, ses.ClientID)
|
|
|
|
}
|
|
|
|
|
|
|
|
if state != ses.ClientState {
|
|
|
|
t.Fatalf("Session created with incorrect State: want=%q got=%q", state, ses.ClientState)
|
|
|
|
}
|
|
|
|
|
|
|
|
if nonce != ses.Nonce {
|
|
|
|
t.Fatalf("Session created with incorrect Nonce: want=%q got=%q", nonce, ses.Nonce)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServerLogin(t *testing.T) {
|
|
|
|
|
2016-06-17 06:01:33 +05:30
|
|
|
tests := []struct {
|
|
|
|
testCase string
|
|
|
|
connectorID string
|
|
|
|
clientID string
|
|
|
|
userID string
|
|
|
|
remoteUserID string
|
|
|
|
email string
|
|
|
|
configure func(s *Server)
|
|
|
|
|
|
|
|
wantError bool // should server.Login fail?
|
|
|
|
wantLogin bool // should server.Login redirect back to the app?
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
testCase: "good user",
|
|
|
|
connectorID: testConnectorID1,
|
|
|
|
clientID: testClientID,
|
|
|
|
userID: testUserID1,
|
|
|
|
remoteUserID: testUserRemoteID1,
|
|
|
|
email: testUserEmail1,
|
|
|
|
wantLogin: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testCase: "user has remote identity with another connector",
|
|
|
|
connectorID: testConnectorIDOpenID,
|
|
|
|
clientID: testClientID,
|
|
|
|
userID: testUserID1,
|
|
|
|
remoteUserID: testUserRemoteID1,
|
|
|
|
email: testUserEmail1,
|
|
|
|
wantLogin: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testCase: "unknown connector id",
|
|
|
|
connectorID: "bad connector id",
|
|
|
|
clientID: testClientID,
|
|
|
|
userID: testUserID1,
|
|
|
|
remoteUserID: testUserRemoteID1,
|
|
|
|
email: testUserEmail1,
|
|
|
|
wantError: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testCase: "unregistered user",
|
|
|
|
connectorID: testConnectorIDOpenID,
|
|
|
|
clientID: testClientID,
|
|
|
|
userID: testUserID1,
|
|
|
|
remoteUserID: "unregistered-user-id",
|
|
|
|
email: "newemail@example.com",
|
|
|
|
wantLogin: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testCase: "unregistered user with register on first login",
|
|
|
|
connectorID: testConnectorIDOpenID,
|
|
|
|
clientID: testClientID,
|
|
|
|
userID: testUserID1,
|
|
|
|
remoteUserID: "unregistered-user-id",
|
|
|
|
email: "newemail@example.com",
|
|
|
|
configure: func(srv *Server) { srv.RegisterOnFirstLogin = true },
|
|
|
|
wantLogin: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testCase: "unregistered user through local connector with register on first login",
|
|
|
|
connectorID: testConnectorLocalID,
|
|
|
|
clientID: testClientID,
|
|
|
|
userID: testUserID1,
|
|
|
|
remoteUserID: "unregistered-user-id",
|
|
|
|
email: "newemail@example.com",
|
|
|
|
configure: func(srv *Server) { srv.RegisterOnFirstLogin = true },
|
|
|
|
wantLogin: false,
|
|
|
|
},
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
2016-06-17 06:01:33 +05:30
|
|
|
for _, tt := range tests {
|
|
|
|
f, err := makeTestFixtures()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error making test fixtures: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if tt.configure != nil {
|
|
|
|
tt.configure(f.srv)
|
|
|
|
}
|
|
|
|
|
|
|
|
sm := f.sessionManager
|
|
|
|
sessionID, err := sm.NewSession(tt.connectorID, tt.clientID, "bogus", testRedirectURL, "", false, []string{"openid"})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("case %s: new session: %v", tt.testCase, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
key, err := sm.NewSessionKey(sessionID)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("case %s: new session key: %v", tt.testCase, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
ident := oidc.Identity{ID: tt.remoteUserID, Name: "elroy", Email: tt.email}
|
|
|
|
redirectURL, err := f.srv.Login(ident, key)
|
|
|
|
if err != nil {
|
|
|
|
if !tt.wantError {
|
|
|
|
t.Errorf("case %s: server.Login: %v", tt.testCase, err)
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if tt.wantError {
|
|
|
|
t.Errorf("case %s: expected server.Login to fail", tt.testCase)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Did the server redirect back to the client app or display an error to the user?
|
|
|
|
gotRedirectURL := strings.HasPrefix(redirectURL, testRedirectURL.String())
|
|
|
|
if gotRedirectURL && !tt.wantLogin {
|
|
|
|
t.Errorf("case %s: should not have logged in", tt.testCase)
|
|
|
|
}
|
|
|
|
if !gotRedirectURL && tt.wantLogin {
|
|
|
|
t.Errorf("case %s: failed to log in. expected redirect url got: %s", tt.testCase, redirectURL)
|
|
|
|
}
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServerLoginUnrecognizedSessionKey(t *testing.T) {
|
2016-06-07 01:33:07 +05:30
|
|
|
f, err := makeTestFixtures()
|
2016-05-12 22:23:01 +05:30
|
|
|
if err != nil {
|
2016-06-07 01:33:07 +05:30
|
|
|
t.Fatalf("error making test fixtures: %v", err)
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
2016-06-07 01:33:07 +05:30
|
|
|
ident := oidc.Identity{ID: testUserRemoteID1, Name: "elroy", Email: testUserEmail1}
|
|
|
|
code, err := f.srv.Login(ident, testClientID)
|
2015-08-18 05:57:27 +05:30
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("Expected non-nil error")
|
|
|
|
}
|
|
|
|
|
|
|
|
if code != "" {
|
|
|
|
t.Fatalf("Expected empty code, got=%s", code)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-26 02:54:51 +05:30
|
|
|
func TestServerLoginDisabledUser(t *testing.T) {
|
2016-06-07 01:33:07 +05:30
|
|
|
f, err := makeTestFixtures()
|
2015-09-26 02:54:51 +05:30
|
|
|
if err != nil {
|
2016-06-07 01:33:07 +05:30
|
|
|
t.Fatalf("error making test fixtures: %v", err)
|
2015-09-26 02:54:51 +05:30
|
|
|
}
|
|
|
|
|
2016-06-07 01:33:07 +05:30
|
|
|
err = f.userRepo.Create(nil, user.User{
|
2015-09-26 02:54:51 +05:30
|
|
|
ID: "disabled-1",
|
|
|
|
Email: "disabled@example.com",
|
|
|
|
Disabled: true,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-06-07 01:33:07 +05:30
|
|
|
err = f.userRepo.AddRemoteIdentity(nil, "disabled-1", user.RemoteIdentity{
|
2015-09-26 02:54:51 +05:30
|
|
|
ConnectorID: "test_connector_id",
|
|
|
|
ID: "disabled-connector-id",
|
|
|
|
})
|
|
|
|
|
2016-06-07 01:33:07 +05:30
|
|
|
sessionID, err := f.sessionManager.NewSession("test_connector_id", testClientID, "bogus", testRedirectURL, "", false, []string{"openid"})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error: %v", err)
|
2015-09-26 02:54:51 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
ident := oidc.Identity{ID: "disabled-connector-id", Name: "elroy", Email: "elroy@example.com"}
|
2016-06-07 01:33:07 +05:30
|
|
|
key, err := f.sessionManager.NewSessionKey(sessionID)
|
2015-09-26 02:54:51 +05:30
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-06-07 01:33:07 +05:30
|
|
|
_, err = f.srv.Login(ident, key)
|
2015-09-26 02:54:51 +05:30
|
|
|
if err == nil {
|
|
|
|
t.Errorf("disabled user was allowed to log in")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-18 05:57:27 +05:30
|
|
|
func TestServerCodeToken(t *testing.T) {
|
2016-06-03 01:35:18 +05:30
|
|
|
f, err := makeTestFixtures()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error creating test fixtures: %v", err)
|
|
|
|
}
|
|
|
|
sm := f.sessionManager
|
|
|
|
|
2015-09-01 02:08:06 +05:30
|
|
|
tests := []struct {
|
|
|
|
scope []string
|
|
|
|
refreshToken string
|
|
|
|
}{
|
|
|
|
// No 'offline_access' in scope, should get empty refresh token.
|
|
|
|
{
|
|
|
|
scope: []string{"openid"},
|
|
|
|
refreshToken: "",
|
|
|
|
},
|
|
|
|
// Have 'offline_access' in scope, should get non-empty refresh token.
|
|
|
|
{
|
2016-06-03 01:35:18 +05:30
|
|
|
// NOTE(ericchiang): This test assumes that the database ID of the
|
|
|
|
// first refresh token will be "1".
|
2015-09-01 02:08:06 +05:30
|
|
|
scope: []string{"openid", "offline_access"},
|
2016-02-10 01:07:32 +05:30
|
|
|
refreshToken: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
2015-09-01 02:08:06 +05:30
|
|
|
},
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
2015-09-01 02:08:06 +05:30
|
|
|
for i, tt := range tests {
|
2016-06-07 01:33:07 +05:30
|
|
|
sessionID, err := sm.NewSession("bogus_idpc", testClientID, "bogus", url.URL{}, "", false, tt.scope)
|
2015-09-01 02:08:06 +05:30
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("case %d: unexpected error: %v", i, err)
|
|
|
|
}
|
|
|
|
_, err = sm.AttachRemoteIdentity(sessionID, oidc.Identity{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("case %d: unexpected error: %v", i, err)
|
|
|
|
}
|
2015-08-18 05:57:27 +05:30
|
|
|
|
2016-06-07 01:33:07 +05:30
|
|
|
_, err = sm.AttachUser(sessionID, testUserID1)
|
2015-09-01 02:08:06 +05:30
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("case %d: unexpected error: %v", i, err)
|
|
|
|
}
|
2015-08-18 05:57:27 +05:30
|
|
|
|
2015-09-01 02:08:06 +05:30
|
|
|
key, err := sm.NewSessionKey(sessionID)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("case %d: unexpected error: %v", i, err)
|
|
|
|
}
|
|
|
|
|
2016-06-03 01:35:18 +05:30
|
|
|
jwt, token, err := f.srv.CodeToken(oidc.ClientCredentials{
|
|
|
|
ID: testClientID,
|
|
|
|
Secret: clientTestSecret}, key)
|
2015-09-01 02:08:06 +05:30
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("case %d: unexpected error: %v", i, err)
|
|
|
|
}
|
|
|
|
if jwt == nil {
|
|
|
|
t.Fatalf("case %d: expect non-nil jwt", i)
|
|
|
|
}
|
|
|
|
if token != tt.refreshToken {
|
|
|
|
t.Fatalf("case %d: expect refresh token %q, got %q", i, tt.refreshToken, token)
|
|
|
|
}
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServerTokenUnrecognizedKey(t *testing.T) {
|
2016-06-07 01:33:07 +05:30
|
|
|
f, err := makeTestFixtures()
|
2016-05-12 22:23:01 +05:30
|
|
|
if err != nil {
|
2016-06-07 01:33:07 +05:30
|
|
|
t.Fatalf("error making test fixtures: %v", err)
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
2016-06-07 01:33:07 +05:30
|
|
|
sm := f.sessionManager
|
2015-08-18 05:57:27 +05:30
|
|
|
|
2016-06-07 01:33:07 +05:30
|
|
|
sessionID, err := sm.NewSession("connector_id", testClientID, "bogus", url.URL{}, "", false, []string{"openid", "offline_access"})
|
2015-08-18 05:57:27 +05:30
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = sm.AttachRemoteIdentity(sessionID, oidc.Identity{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-06-07 01:33:07 +05:30
|
|
|
jwt, token, err := f.srv.CodeToken(testClientCredentials, "foo")
|
2015-08-18 05:57:27 +05:30
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("Expected non-nil error")
|
|
|
|
}
|
|
|
|
if jwt != nil {
|
|
|
|
t.Fatalf("Expected nil jwt")
|
|
|
|
}
|
|
|
|
if token != "" {
|
|
|
|
t.Fatalf("Expected empty refresh token")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServerTokenFail(t *testing.T) {
|
|
|
|
keyFixture := "goodkey"
|
2016-06-07 01:33:07 +05:30
|
|
|
|
2015-08-18 05:57:27 +05:30
|
|
|
signerFixture := &StaticSigner{sig: []byte("beer"), err: nil}
|
|
|
|
|
|
|
|
tests := []struct {
|
2015-09-01 02:08:06 +05:30
|
|
|
signer jose.Signer
|
|
|
|
argCC oidc.ClientCredentials
|
|
|
|
argKey string
|
2015-09-01 07:54:45 +05:30
|
|
|
err error
|
2015-09-01 02:08:06 +05:30
|
|
|
scope []string
|
|
|
|
refreshToken string
|
2015-08-18 05:57:27 +05:30
|
|
|
}{
|
|
|
|
// control test case to make sure fixtures check out
|
2015-09-01 02:08:06 +05:30
|
|
|
{
|
2016-02-10 01:07:32 +05:30
|
|
|
// NOTE(ericchiang): This test assumes that the database ID of the first
|
|
|
|
// refresh token will be "1".
|
2015-09-01 02:08:06 +05:30
|
|
|
signer: signerFixture,
|
2016-06-07 01:33:07 +05:30
|
|
|
argCC: testClientCredentials,
|
2015-09-01 02:08:06 +05:30
|
|
|
argKey: keyFixture,
|
|
|
|
scope: []string{"openid", "offline_access"},
|
2016-02-10 01:07:32 +05:30
|
|
|
refreshToken: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
2015-09-01 02:08:06 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
// no 'offline_access' in 'scope', should get empty refresh token
|
2015-08-18 05:57:27 +05:30
|
|
|
{
|
|
|
|
signer: signerFixture,
|
2016-06-07 01:33:07 +05:30
|
|
|
argCC: testClientCredentials,
|
2015-08-18 05:57:27 +05:30
|
|
|
argKey: keyFixture,
|
2015-09-01 02:08:06 +05:30
|
|
|
scope: []string{"openid"},
|
2015-08-18 05:57:27 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
// unrecognized key
|
|
|
|
{
|
|
|
|
signer: signerFixture,
|
2016-06-07 01:33:07 +05:30
|
|
|
argCC: testClientCredentials,
|
2015-08-18 05:57:27 +05:30
|
|
|
argKey: "foo",
|
2015-09-01 07:54:45 +05:30
|
|
|
err: oauth2.NewError(oauth2.ErrorInvalidGrant),
|
2015-09-01 02:08:06 +05:30
|
|
|
scope: []string{"openid", "offline_access"},
|
2015-08-18 05:57:27 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
// unrecognized client
|
|
|
|
{
|
|
|
|
signer: signerFixture,
|
|
|
|
argCC: oidc.ClientCredentials{ID: "YYY"},
|
|
|
|
argKey: keyFixture,
|
2015-09-01 07:54:45 +05:30
|
|
|
err: oauth2.NewError(oauth2.ErrorInvalidClient),
|
2015-09-01 02:08:06 +05:30
|
|
|
scope: []string{"openid", "offline_access"},
|
2015-08-18 05:57:27 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
// signing operation fails
|
|
|
|
{
|
|
|
|
signer: &StaticSigner{sig: nil, err: errors.New("fail")},
|
2016-06-07 01:33:07 +05:30
|
|
|
argCC: testClientCredentials,
|
2015-08-18 05:57:27 +05:30
|
|
|
argKey: keyFixture,
|
2015-09-01 07:54:45 +05:30
|
|
|
err: oauth2.NewError(oauth2.ErrorServerError),
|
2015-09-01 02:08:06 +05:30
|
|
|
scope: []string{"openid", "offline_access"},
|
2015-08-18 05:57:27 +05:30
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
2016-06-07 01:33:07 +05:30
|
|
|
|
|
|
|
f, err := makeTestFixtures()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error making test fixtures: %v", err)
|
|
|
|
}
|
|
|
|
sm := f.sessionManager
|
2015-08-18 05:57:27 +05:30
|
|
|
sm.GenerateCode = func() (string, error) { return keyFixture, nil }
|
2016-06-07 01:33:07 +05:30
|
|
|
f.srv.RefreshTokenRepo = refreshtest.NewTestRefreshTokenRepo()
|
|
|
|
f.srv.KeyManager = &StaticKeyManager{
|
|
|
|
signer: tt.signer,
|
|
|
|
}
|
2015-08-18 05:57:27 +05:30
|
|
|
|
2016-06-07 01:33:07 +05:30
|
|
|
sessionID, err := sm.NewSession(testConnectorID1, testClientID, "bogus", url.URL{}, "", false, tt.scope)
|
2015-08-18 05:57:27 +05:30
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = sm.AttachRemoteIdentity(sessionID, oidc.Identity{})
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("case %d: unexpected error: %v", i, err)
|
|
|
|
continue
|
|
|
|
}
|
2016-06-07 01:33:07 +05:30
|
|
|
_, err = sm.AttachUser(sessionID, testUserID1)
|
2015-08-18 05:57:27 +05:30
|
|
|
if err != nil {
|
2015-09-01 02:08:06 +05:30
|
|
|
t.Fatalf("case %d: unexpected error: %v", i, err)
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
_, err = sm.NewSessionKey(sessionID)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-06-07 01:33:07 +05:30
|
|
|
jwt, token, err := f.srv.CodeToken(tt.argCC, tt.argKey)
|
2015-09-01 02:08:06 +05:30
|
|
|
if token != tt.refreshToken {
|
|
|
|
fmt.Printf("case %d: expect refresh token %q, got %q\n", i, tt.refreshToken, token)
|
|
|
|
t.Fatalf("case %d: expect refresh token %q, got %q", i, tt.refreshToken, token)
|
|
|
|
panic("")
|
|
|
|
}
|
2015-09-01 07:54:45 +05:30
|
|
|
if !reflect.DeepEqual(err, tt.err) {
|
|
|
|
t.Errorf("case %d: expect %v, got %v", i, tt.err, err)
|
|
|
|
}
|
|
|
|
if err == nil && jwt == nil {
|
|
|
|
t.Errorf("case %d: got nil JWT", i)
|
|
|
|
}
|
|
|
|
if err != nil && jwt != nil {
|
|
|
|
t.Errorf("case %d: got non-nil JWT %v", i, jwt)
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServerRefreshToken(t *testing.T) {
|
2016-06-07 01:33:07 +05:30
|
|
|
|
2016-05-12 22:23:01 +05:30
|
|
|
clientB := client.Client{
|
|
|
|
Credentials: oidc.ClientCredentials{
|
|
|
|
ID: "example2.com",
|
|
|
|
Secret: clientTestSecret,
|
|
|
|
},
|
|
|
|
Metadata: oidc.ClientMetadata{
|
|
|
|
RedirectURIs: []url.URL{
|
|
|
|
url.URL{Scheme: "https", Host: "example2.com", Path: "one/two/three"},
|
|
|
|
},
|
|
|
|
},
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
signerFixture := &StaticSigner{sig: []byte("beer"), err: nil}
|
|
|
|
|
2016-02-10 01:07:32 +05:30
|
|
|
// NOTE(ericchiang): These tests assume that the database ID of the first
|
|
|
|
// refresh token will be "1".
|
2015-08-18 05:57:27 +05:30
|
|
|
tests := []struct {
|
2016-06-10 04:26:37 +05:30
|
|
|
token string
|
|
|
|
clientID string // The client that associates with the token.
|
|
|
|
creds oidc.ClientCredentials
|
|
|
|
signer jose.Signer
|
|
|
|
createScopes []string
|
|
|
|
refreshScopes []string
|
2016-06-11 04:17:40 +05:30
|
|
|
expectedAud []string
|
2016-06-10 04:26:37 +05:30
|
|
|
err error
|
2015-08-18 05:57:27 +05:30
|
|
|
}{
|
|
|
|
// Everything is good.
|
|
|
|
{
|
2016-06-11 04:17:40 +05:30
|
|
|
token: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
|
|
|
clientID: testClientID,
|
|
|
|
creds: testClientCredentials,
|
|
|
|
signer: signerFixture,
|
|
|
|
createScopes: []string{"openid", "profile"},
|
|
|
|
refreshScopes: []string{"openid", "profile"},
|
2015-08-18 05:57:27 +05:30
|
|
|
},
|
2016-06-10 04:26:37 +05:30
|
|
|
// Asking for a scope not originally granted to you.
|
|
|
|
{
|
2016-06-11 04:17:40 +05:30
|
|
|
token: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
|
|
|
clientID: testClientID,
|
|
|
|
creds: testClientCredentials,
|
|
|
|
signer: signerFixture,
|
|
|
|
createScopes: []string{"openid", "profile"},
|
|
|
|
refreshScopes: []string{"openid", "profile", "extra_scope"},
|
|
|
|
err: oauth2.NewError(oauth2.ErrorInvalidRequest),
|
2016-06-10 04:26:37 +05:30
|
|
|
},
|
2015-08-18 05:57:27 +05:30
|
|
|
// Invalid refresh token(malformatted).
|
|
|
|
{
|
2016-06-11 04:17:40 +05:30
|
|
|
token: "invalid-token",
|
|
|
|
clientID: testClientID,
|
|
|
|
creds: testClientCredentials,
|
|
|
|
signer: signerFixture,
|
|
|
|
createScopes: []string{"openid", "profile"},
|
|
|
|
refreshScopes: []string{"openid", "profile"},
|
|
|
|
err: oauth2.NewError(oauth2.ErrorInvalidRequest),
|
2015-08-18 05:57:27 +05:30
|
|
|
},
|
2015-09-01 07:54:45 +05:30
|
|
|
// Invalid refresh token(invalid payload content).
|
2015-08-18 05:57:27 +05:30
|
|
|
{
|
2016-06-11 04:17:40 +05:30
|
|
|
token: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-2"))),
|
|
|
|
clientID: testClientID,
|
|
|
|
creds: testClientCredentials,
|
|
|
|
signer: signerFixture,
|
|
|
|
createScopes: []string{"openid", "profile"},
|
|
|
|
refreshScopes: []string{"openid", "profile"},
|
|
|
|
err: oauth2.NewError(oauth2.ErrorInvalidRequest),
|
2015-09-01 07:54:45 +05:30
|
|
|
},
|
|
|
|
// Invalid refresh token(invalid ID content).
|
|
|
|
{
|
2016-06-11 04:17:40 +05:30
|
|
|
token: fmt.Sprintf("0/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
|
|
|
clientID: testClientID,
|
|
|
|
creds: testClientCredentials,
|
|
|
|
signer: signerFixture,
|
|
|
|
createScopes: []string{"openid", "profile"},
|
|
|
|
refreshScopes: []string{"openid", "profile"},
|
|
|
|
err: oauth2.NewError(oauth2.ErrorInvalidRequest),
|
2015-08-18 05:57:27 +05:30
|
|
|
},
|
|
|
|
// Invalid client(client is not associated with the token).
|
|
|
|
{
|
2016-06-11 04:17:40 +05:30
|
|
|
token: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
|
|
|
clientID: testClientID,
|
|
|
|
creds: clientB.Credentials,
|
|
|
|
signer: signerFixture,
|
|
|
|
createScopes: []string{"openid", "profile"},
|
|
|
|
refreshScopes: []string{"openid", "profile"},
|
|
|
|
err: oauth2.NewError(oauth2.ErrorInvalidClient),
|
2015-08-18 05:57:27 +05:30
|
|
|
},
|
|
|
|
// Invalid client(no client ID).
|
|
|
|
{
|
2016-06-11 04:17:40 +05:30
|
|
|
token: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
|
|
|
clientID: testClientID,
|
|
|
|
creds: oidc.ClientCredentials{ID: "", Secret: "aaa"},
|
|
|
|
signer: signerFixture,
|
|
|
|
createScopes: []string{"openid", "profile"},
|
|
|
|
refreshScopes: []string{"openid", "profile"},
|
|
|
|
err: oauth2.NewError(oauth2.ErrorInvalidClient),
|
2015-08-18 05:57:27 +05:30
|
|
|
},
|
|
|
|
// Invalid client(no such client).
|
|
|
|
{
|
2016-06-11 04:17:40 +05:30
|
|
|
token: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
|
|
|
clientID: testClientID,
|
|
|
|
creds: oidc.ClientCredentials{ID: "AAA", Secret: "aaa"},
|
|
|
|
signer: signerFixture,
|
|
|
|
createScopes: []string{"openid", "profile"},
|
|
|
|
refreshScopes: []string{"openid", "profile"},
|
|
|
|
err: oauth2.NewError(oauth2.ErrorInvalidClient),
|
2015-08-18 05:57:27 +05:30
|
|
|
},
|
|
|
|
// Invalid client(no secrets).
|
|
|
|
{
|
2016-06-11 04:17:40 +05:30
|
|
|
token: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
|
|
|
clientID: testClientID,
|
|
|
|
creds: oidc.ClientCredentials{ID: testClientID},
|
|
|
|
signer: signerFixture,
|
|
|
|
createScopes: []string{"openid", "profile"},
|
|
|
|
refreshScopes: []string{"openid", "profile"},
|
|
|
|
err: oauth2.NewError(oauth2.ErrorInvalidClient),
|
2015-08-18 05:57:27 +05:30
|
|
|
},
|
|
|
|
// Invalid client(invalid secret).
|
|
|
|
{
|
2016-06-11 04:17:40 +05:30
|
|
|
token: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
|
|
|
clientID: testClientID,
|
|
|
|
creds: oidc.ClientCredentials{ID: "bad-id", Secret: "bad-secret"},
|
|
|
|
signer: signerFixture,
|
|
|
|
createScopes: []string{"openid", "profile"},
|
|
|
|
refreshScopes: []string{"openid", "profile"},
|
|
|
|
err: oauth2.NewError(oauth2.ErrorInvalidClient),
|
2015-08-18 05:57:27 +05:30
|
|
|
},
|
|
|
|
// Signing operation fails.
|
|
|
|
{
|
2016-06-11 04:17:40 +05:30
|
|
|
token: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
|
|
|
clientID: testClientID,
|
|
|
|
creds: testClientCredentials,
|
|
|
|
signer: &StaticSigner{sig: nil, err: errors.New("fail")},
|
|
|
|
createScopes: []string{"openid", "profile"},
|
|
|
|
refreshScopes: []string{"openid", "profile"},
|
|
|
|
err: oauth2.NewError(oauth2.ErrorServerError),
|
|
|
|
},
|
|
|
|
// Valid Cross-Client
|
|
|
|
{
|
|
|
|
token: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
|
|
|
clientID: "client_a",
|
|
|
|
creds: oidc.ClientCredentials{
|
|
|
|
ID: "client_a",
|
|
|
|
Secret: base64.URLEncoding.EncodeToString(
|
|
|
|
[]byte("client_a_secret")),
|
|
|
|
},
|
|
|
|
signer: signerFixture,
|
|
|
|
createScopes: []string{"openid", "profile", scope.ScopeGoogleCrossClient + "client_b"},
|
|
|
|
refreshScopes: []string{"openid", "profile", scope.ScopeGoogleCrossClient + "client_b"},
|
|
|
|
expectedAud: []string{"client_b"},
|
|
|
|
},
|
|
|
|
// Valid Cross-Client - but this time we leave out the scopes in the
|
|
|
|
// refresh request, which should result in the original stored scopes
|
|
|
|
// being used.
|
|
|
|
{
|
|
|
|
token: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
|
|
|
clientID: "client_a",
|
|
|
|
creds: oidc.ClientCredentials{
|
|
|
|
ID: "client_a",
|
|
|
|
Secret: base64.URLEncoding.EncodeToString(
|
|
|
|
[]byte("client_a_secret")),
|
|
|
|
},
|
|
|
|
signer: signerFixture,
|
|
|
|
createScopes: []string{"openid", "profile", scope.ScopeGoogleCrossClient + "client_b"},
|
|
|
|
refreshScopes: []string{},
|
|
|
|
expectedAud: []string{"client_b"},
|
|
|
|
},
|
|
|
|
// Valid Cross-Client - asking for fewer scopes than originally used
|
|
|
|
// when creating the refresh token, which is ok.
|
|
|
|
{
|
|
|
|
token: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
|
|
|
clientID: "client_a",
|
|
|
|
creds: oidc.ClientCredentials{
|
|
|
|
ID: "client_a",
|
|
|
|
Secret: base64.URLEncoding.EncodeToString(
|
|
|
|
[]byte("client_a_secret")),
|
|
|
|
},
|
|
|
|
signer: signerFixture,
|
|
|
|
createScopes: []string{"openid", "profile", scope.ScopeGoogleCrossClient + "client_b", scope.ScopeGoogleCrossClient + "client_c"},
|
|
|
|
refreshScopes: []string{"openid", "profile", scope.ScopeGoogleCrossClient + "client_b"},
|
|
|
|
expectedAud: []string{"client_b"},
|
|
|
|
},
|
|
|
|
// Valid Cross-Client - asking for multiple clients in the audience.
|
|
|
|
{
|
|
|
|
token: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
|
|
|
clientID: "client_a",
|
|
|
|
creds: oidc.ClientCredentials{
|
|
|
|
ID: "client_a",
|
|
|
|
Secret: base64.URLEncoding.EncodeToString(
|
|
|
|
[]byte("client_a_secret")),
|
|
|
|
},
|
|
|
|
signer: signerFixture,
|
|
|
|
createScopes: []string{"openid", "profile", scope.ScopeGoogleCrossClient + "client_b", scope.ScopeGoogleCrossClient + "client_c"},
|
|
|
|
refreshScopes: []string{"openid", "profile", scope.ScopeGoogleCrossClient + "client_b", scope.ScopeGoogleCrossClient + "client_c"},
|
|
|
|
expectedAud: []string{"client_b", "client_c"},
|
|
|
|
},
|
|
|
|
// Invalid Cross-Client - didn't orignally request cross-client when
|
|
|
|
// refresh token was created.
|
|
|
|
{
|
|
|
|
token: fmt.Sprintf("1/%s", base64.URLEncoding.EncodeToString([]byte("refresh-1"))),
|
|
|
|
clientID: "client_a",
|
|
|
|
creds: oidc.ClientCredentials{
|
|
|
|
ID: "client_a",
|
|
|
|
Secret: base64.URLEncoding.EncodeToString(
|
|
|
|
[]byte("client_a_secret")),
|
|
|
|
},
|
|
|
|
signer: signerFixture,
|
|
|
|
createScopes: []string{"openid", "profile"},
|
|
|
|
refreshScopes: []string{"openid", "profile", scope.ScopeGoogleCrossClient + "client_b"},
|
|
|
|
err: oauth2.NewError(oauth2.ErrorInvalidRequest),
|
2015-08-18 05:57:27 +05:30
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
|
|
|
km := &StaticKeyManager{
|
|
|
|
signer: tt.signer,
|
|
|
|
}
|
2016-06-11 04:17:40 +05:30
|
|
|
f, err := makeCrossClientTestFixtures()
|
2016-05-12 22:23:01 +05:30
|
|
|
if err != nil {
|
2016-06-07 01:33:07 +05:30
|
|
|
t.Fatalf("error making test fixtures: %v", err)
|
2016-05-12 22:23:01 +05:30
|
|
|
}
|
2016-06-07 01:33:07 +05:30
|
|
|
f.srv.RefreshTokenRepo = refreshtest.NewTestRefreshTokenRepo()
|
|
|
|
f.srv.KeyManager = km
|
|
|
|
_, err = f.clientRepo.New(nil, clientB)
|
2015-08-18 05:57:27 +05:30
|
|
|
if err != nil {
|
2016-06-07 01:33:07 +05:30
|
|
|
t.Errorf("case %d: error creating other client: %v", i, err)
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
2016-07-16 04:30:59 +05:30
|
|
|
if _, err := f.srv.RefreshTokenRepo.Create(testUserID1, tt.clientID, "", tt.createScopes); err != nil {
|
2015-08-18 05:57:27 +05:30
|
|
|
t.Fatalf("Unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-06-10 04:26:37 +05:30
|
|
|
jwt, err := f.srv.RefreshToken(tt.creds, tt.refreshScopes, tt.token)
|
2015-09-01 07:54:45 +05:30
|
|
|
if !reflect.DeepEqual(err, tt.err) {
|
|
|
|
t.Errorf("Case %d: expect: %v, got: %v", i, tt.err, err)
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if jwt != nil {
|
|
|
|
if string(jwt.Signature) != "beer" {
|
|
|
|
t.Errorf("Case %d: expect signature: beer, got signature: %v", i, jwt.Signature)
|
|
|
|
}
|
|
|
|
claims, err := jwt.Claims()
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Case %d: unexpected error: %v", i, err)
|
|
|
|
}
|
2016-06-11 04:17:40 +05:30
|
|
|
|
|
|
|
var expectedAud interface{}
|
|
|
|
if tt.expectedAud == nil {
|
|
|
|
expectedAud = testClientID
|
|
|
|
} else if len(tt.expectedAud) == 1 {
|
|
|
|
expectedAud = tt.expectedAud[0]
|
|
|
|
} else {
|
|
|
|
expectedAud = tt.expectedAud
|
|
|
|
}
|
|
|
|
|
|
|
|
if claims["iss"] != testIssuerURL.String() {
|
|
|
|
t.Errorf("Case %d: want=%v, got=%v", i,
|
|
|
|
testIssuerURL.String(), claims["iss"])
|
|
|
|
}
|
|
|
|
if claims["sub"] != testUserID1 {
|
|
|
|
t.Errorf("Case %d: want=%v, got=%v", i,
|
|
|
|
testUserID1, claims["sub"])
|
|
|
|
}
|
|
|
|
if diff := pretty.Compare(claims["aud"], expectedAud); diff != "" {
|
|
|
|
t.Errorf("Case %d: want=%v, got=%v", i,
|
|
|
|
expectedAud, claims["aud"])
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|