*: remove in memory connector config repo
This commit is contained in:
parent
b572b8dd6c
commit
dcf5835189
8 changed files with 54 additions and 39 deletions
|
@ -59,9 +59,15 @@ func makeTestFixtures() *testFixtures {
|
||||||
return repo
|
return repo
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ccr := connector.NewConnectorConfigRepoFromConfigs([]connector.ConnectorConfig{
|
ccr := func() connector.ConnectorConfigRepo {
|
||||||
&connector.LocalConnectorConfig{ID: "local"},
|
c := []connector.ConnectorConfig{&connector.LocalConnectorConfig{ID: "local"}}
|
||||||
})
|
repo := db.NewConnectorConfigRepo(dbMap)
|
||||||
|
if err := repo.Set(c); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return repo
|
||||||
|
}()
|
||||||
|
|
||||||
f.mgr = manager.NewUserManager(f.ur, f.pwr, ccr, db.TransactionFactory(dbMap), manager.ManagerOptions{})
|
f.mgr = manager.NewUserManager(f.ur, f.pwr, ccr, db.TransactionFactory(dbMap), manager.ManagerOptions{})
|
||||||
f.adAPI = NewAdminAPI(f.mgr, f.ur, f.pwr, "local")
|
f.adAPI = NewAdminAPI(f.mgr, f.ur, f.pwr, "local")
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,6 @@ package connector
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/coreos/dex/repo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ReadConfigs(r io.Reader) ([]ConnectorConfig, error) {
|
func ReadConfigs(r io.Reader) ([]ConnectorConfig, error) {
|
||||||
|
@ -22,24 +20,3 @@ func ReadConfigs(r io.Reader) ([]ConnectorConfig, error) {
|
||||||
}
|
}
|
||||||
return cfgs, nil
|
return cfgs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type memConnectorConfigRepo struct {
|
|
||||||
configs []ConnectorConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewConnectorConfigRepoFromConfigs(cfgs []ConnectorConfig) ConnectorConfigRepo {
|
|
||||||
return &memConnectorConfigRepo{configs: cfgs}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *memConnectorConfigRepo) All() ([]ConnectorConfig, error) {
|
|
||||||
return r.configs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *memConnectorConfigRepo) GetConnectorByID(_ repo.Transaction, id string) (ConnectorConfig, error) {
|
|
||||||
for _, cfg := range r.configs {
|
|
||||||
if cfg.ConnectorID() == id {
|
|
||||||
return cfg, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, ErrorNotFound
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,15 +4,19 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/go-gorp/gorp"
|
||||||
|
|
||||||
"github.com/coreos/dex/connector"
|
"github.com/coreos/dex/connector"
|
||||||
"github.com/coreos/dex/db"
|
"github.com/coreos/dex/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newConnectorConfigRepo(t *testing.T, configs []connector.ConnectorConfig) connector.ConnectorConfigRepo {
|
func newConnectorConfigRepo(t *testing.T, configs []connector.ConnectorConfig) connector.ConnectorConfigRepo {
|
||||||
|
var dbMap *gorp.DbMap
|
||||||
if os.Getenv("DEX_TEST_DSN") == "" {
|
if os.Getenv("DEX_TEST_DSN") == "" {
|
||||||
return connector.NewConnectorConfigRepoFromConfigs(configs)
|
dbMap = db.NewMemDB()
|
||||||
|
} else {
|
||||||
|
dbMap = connect(t)
|
||||||
}
|
}
|
||||||
dbMap := connect(t)
|
|
||||||
repo := db.NewConnectorConfigRepo(dbMap)
|
repo := db.NewConnectorConfigRepo(dbMap)
|
||||||
if err := repo.Set(configs); err != nil {
|
if err := repo.Set(configs); err != nil {
|
||||||
t.Fatalf("Unable to set connector configs: %v", err)
|
t.Fatalf("Unable to set connector configs: %v", err)
|
||||||
|
|
|
@ -62,9 +62,15 @@ func makeUserObjects(users []user.UserWithRemoteIdentities, passwords []user.Pas
|
||||||
return repo
|
return repo
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ccr := connector.NewConnectorConfigRepoFromConfigs(
|
ccr := func() connector.ConnectorConfigRepo {
|
||||||
[]connector.ConnectorConfig{&connector.LocalConnectorConfig{ID: "local"}},
|
repo := db.NewConnectorConfigRepo(dbMap)
|
||||||
)
|
c := []connector.ConnectorConfig{&connector.LocalConnectorConfig{ID: "local"}}
|
||||||
|
if err := repo.Set(c); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return repo
|
||||||
|
}()
|
||||||
|
|
||||||
um := manager.NewUserManager(ur, pwr, ccr, db.TransactionFactory(dbMap), manager.ManagerOptions{})
|
um := manager.NewUserManager(ur, pwr, ccr, db.TransactionFactory(dbMap), manager.ManagerOptions{})
|
||||||
um.Clock = clock
|
um.Clock = clock
|
||||||
return ur, pwr, um
|
return ur, pwr, um
|
||||||
|
|
|
@ -131,7 +131,10 @@ func (cfg *SingleServerConfig) Configure(srv *Server) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("decoding connector configs: %v", err)
|
return fmt.Errorf("decoding connector configs: %v", err)
|
||||||
}
|
}
|
||||||
cfgRepo := connector.NewConnectorConfigRepoFromConfigs(cfgs)
|
cfgRepo := db.NewConnectorConfigRepo(dbMap)
|
||||||
|
if err := cfgRepo.Set(cfgs); err != nil {
|
||||||
|
return fmt.Errorf("failed to set connectors: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
sRepo := db.NewSessionRepo(dbMap)
|
sRepo := db.NewSessionRepo(dbMap)
|
||||||
skRepo := db.NewSessionKeyRepo(dbMap)
|
skRepo := db.NewSessionKeyRepo(dbMap)
|
||||||
|
|
|
@ -118,7 +118,10 @@ func makeTestFixtures() (*testFixtures, error) {
|
||||||
ID: "local",
|
ID: "local",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
connCfgRepo := connector.NewConnectorConfigRepoFromConfigs(connConfigs)
|
connCfgRepo := db.NewConnectorConfigRepo(dbMap)
|
||||||
|
if err := connCfgRepo.Set(connConfigs); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
manager := usermanager.NewUserManager(userRepo, pwRepo, connCfgRepo, db.TransactionFactory(dbMap), usermanager.ManagerOptions{})
|
manager := usermanager.NewUserManager(userRepo, pwRepo, connCfgRepo, db.TransactionFactory(dbMap), usermanager.ManagerOptions{})
|
||||||
|
|
||||||
|
|
|
@ -141,9 +141,17 @@ func makeTestFixtures() (*UsersAPI, *testEmailer) {
|
||||||
return repo
|
return repo
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ccr := connector.NewConnectorConfigRepoFromConfigs([]connector.ConnectorConfig{
|
ccr := func() connector.ConnectorConfigRepo {
|
||||||
|
repo := db.NewConnectorConfigRepo(dbMap)
|
||||||
|
c := []connector.ConnectorConfig{
|
||||||
&connector.LocalConnectorConfig{ID: "local"},
|
&connector.LocalConnectorConfig{ID: "local"},
|
||||||
})
|
}
|
||||||
|
if err := repo.Set(c); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return repo
|
||||||
|
}()
|
||||||
|
|
||||||
mgr := manager.NewUserManager(ur, pwr, ccr, db.TransactionFactory(dbMap), manager.ManagerOptions{})
|
mgr := manager.NewUserManager(ur, pwr, ccr, db.TransactionFactory(dbMap), manager.ManagerOptions{})
|
||||||
mgr.Clock = clock
|
mgr.Clock = clock
|
||||||
ci := oidc.ClientIdentity{
|
ci := oidc.ClientIdentity{
|
||||||
|
|
|
@ -77,9 +77,17 @@ func makeTestFixtures() *testFixtures {
|
||||||
return repo
|
return repo
|
||||||
}()
|
}()
|
||||||
|
|
||||||
f.ccr = connector.NewConnectorConfigRepoFromConfigs([]connector.ConnectorConfig{
|
f.ccr = func() connector.ConnectorConfigRepo {
|
||||||
|
repo := db.NewConnectorConfigRepo(dbMap)
|
||||||
|
c := []connector.ConnectorConfig{
|
||||||
&connector.LocalConnectorConfig{ID: "local"},
|
&connector.LocalConnectorConfig{ID: "local"},
|
||||||
})
|
}
|
||||||
|
if err := repo.Set(c); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return repo
|
||||||
|
}()
|
||||||
|
|
||||||
f.mgr = NewUserManager(f.ur, f.pwr, f.ccr, db.TransactionFactory(dbMap), ManagerOptions{})
|
f.mgr = NewUserManager(f.ur, f.pwr, f.ccr, db.TransactionFactory(dbMap), ManagerOptions{})
|
||||||
f.mgr.Clock = f.clock
|
f.mgr.Clock = f.clock
|
||||||
return f
|
return f
|
||||||
|
|
Reference in a new issue