2015-08-18 05:57:27 +05:30
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
2016-02-10 04:36:07 +05:30
|
|
|
"encoding/base64"
|
2015-08-18 05:57:27 +05:30
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/coreos/go-oidc/key"
|
2016-04-06 00:07:26 +05:30
|
|
|
"github.com/go-gorp/gorp"
|
2015-08-18 05:57:27 +05:30
|
|
|
"github.com/jonboulle/clockwork"
|
|
|
|
|
2015-12-08 06:49:55 +05:30
|
|
|
"github.com/coreos/dex/connector"
|
2016-02-10 01:52:40 +05:30
|
|
|
"github.com/coreos/dex/db"
|
2015-08-18 05:57:27 +05:30
|
|
|
"github.com/coreos/dex/user"
|
2015-12-08 04:59:58 +05:30
|
|
|
"github.com/coreos/dex/user/manager"
|
2015-08-18 05:57:27 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
clock = clockwork.NewFakeClock()
|
|
|
|
|
|
|
|
testIssuerURL = url.URL{Scheme: "https", Host: "auth.example.com"}
|
2016-05-12 22:23:01 +05:30
|
|
|
testClientID = "client.example.com"
|
|
|
|
testClientSecret = base64.URLEncoding.EncodeToString([]byte("secret"))
|
2015-08-18 05:57:27 +05:30
|
|
|
testRedirectURL = url.URL{Scheme: "https", Host: "client.example.com", Path: "/redirect"}
|
2016-05-12 22:23:01 +05:30
|
|
|
testBadRedirectURL = url.URL{Scheme: "https", Host: "bad.example.com", Path: "/redirect"}
|
2015-08-18 05:57:27 +05:30
|
|
|
testResetPasswordURL = url.URL{Scheme: "https", Host: "auth.example.com", Path: "/resetPassword"}
|
|
|
|
testPrivKey, _ = key.GeneratePrivateKey()
|
|
|
|
)
|
|
|
|
|
|
|
|
type tokenHandlerTransport struct {
|
|
|
|
Handler http.Handler
|
|
|
|
Token string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *tokenHandlerTransport) RoundTrip(r *http.Request) (*http.Response, error) {
|
|
|
|
r.Header.Set("Authorization", fmt.Sprintf("Bearer %s", t.Token))
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
t.Handler.ServeHTTP(w, r)
|
|
|
|
resp := http.Response{
|
|
|
|
StatusCode: w.Code,
|
|
|
|
Header: w.Header(),
|
|
|
|
Body: ioutil.NopCloser(w.Body),
|
|
|
|
}
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
|
2016-04-06 00:07:26 +05:30
|
|
|
// TODO(ericchiang): Replace DbMap with storage interface. See #278
|
|
|
|
|
|
|
|
func makeUserObjects(users []user.UserWithRemoteIdentities, passwords []user.PasswordInfo) (*gorp.DbMap, user.UserRepo, user.PasswordInfoRepo, *manager.UserManager) {
|
2016-02-10 01:52:40 +05:30
|
|
|
dbMap := db.NewMemDB()
|
|
|
|
ur := func() user.UserRepo {
|
|
|
|
repo, err := db.NewUserRepoFromUsers(dbMap, users)
|
|
|
|
if err != nil {
|
|
|
|
panic("Failed to create user repo: " + err.Error())
|
|
|
|
}
|
|
|
|
return repo
|
|
|
|
}()
|
2016-02-10 02:27:42 +05:30
|
|
|
pwr := func() user.PasswordInfoRepo {
|
|
|
|
repo, err := db.NewPasswordInfoRepoFromPasswordInfos(dbMap, passwords)
|
|
|
|
if err != nil {
|
|
|
|
panic("Failed to create password info repo: " + err.Error())
|
|
|
|
}
|
|
|
|
return repo
|
|
|
|
}()
|
2015-08-18 05:57:27 +05:30
|
|
|
|
2016-02-10 05:14:38 +05:30
|
|
|
ccr := func() connector.ConnectorConfigRepo {
|
|
|
|
repo := db.NewConnectorConfigRepo(dbMap)
|
|
|
|
c := []connector.ConnectorConfig{&connector.LocalConnectorConfig{ID: "local"}}
|
|
|
|
if err := repo.Set(c); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return repo
|
|
|
|
}()
|
|
|
|
|
2016-02-10 01:52:40 +05:30
|
|
|
um := manager.NewUserManager(ur, pwr, ccr, db.TransactionFactory(dbMap), manager.ManagerOptions{})
|
2015-08-18 05:57:27 +05:30
|
|
|
um.Clock = clock
|
2016-04-06 00:07:26 +05:30
|
|
|
return dbMap, ur, pwr, um
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|