*: 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
|
||||
}()
|
||||
|
||||
ccr := connector.NewConnectorConfigRepoFromConfigs([]connector.ConnectorConfig{
|
||||
&connector.LocalConnectorConfig{ID: "local"},
|
||||
})
|
||||
ccr := func() connector.ConnectorConfigRepo {
|
||||
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.adAPI = NewAdminAPI(f.mgr, f.ur, f.pwr, "local")
|
||||
|
||||
|
|
|
@ -3,8 +3,6 @@ package connector
|
|||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
"github.com/coreos/dex/repo"
|
||||
)
|
||||
|
||||
func ReadConfigs(r io.Reader) ([]ConnectorConfig, error) {
|
||||
|
@ -22,24 +20,3 @@ func ReadConfigs(r io.Reader) ([]ConnectorConfig, error) {
|
|||
}
|
||||
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"
|
||||
"testing"
|
||||
|
||||
"github.com/go-gorp/gorp"
|
||||
|
||||
"github.com/coreos/dex/connector"
|
||||
"github.com/coreos/dex/db"
|
||||
)
|
||||
|
||||
func newConnectorConfigRepo(t *testing.T, configs []connector.ConnectorConfig) connector.ConnectorConfigRepo {
|
||||
var dbMap *gorp.DbMap
|
||||
if os.Getenv("DEX_TEST_DSN") == "" {
|
||||
return connector.NewConnectorConfigRepoFromConfigs(configs)
|
||||
dbMap = db.NewMemDB()
|
||||
} else {
|
||||
dbMap = connect(t)
|
||||
}
|
||||
dbMap := connect(t)
|
||||
repo := db.NewConnectorConfigRepo(dbMap)
|
||||
if err := repo.Set(configs); err != nil {
|
||||
t.Fatalf("Unable to set connector configs: %v", err)
|
||||
|
|
|
@ -62,9 +62,15 @@ func makeUserObjects(users []user.UserWithRemoteIdentities, passwords []user.Pas
|
|||
return repo
|
||||
}()
|
||||
|
||||
ccr := connector.NewConnectorConfigRepoFromConfigs(
|
||||
[]connector.ConnectorConfig{&connector.LocalConnectorConfig{ID: "local"}},
|
||||
)
|
||||
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
|
||||
}()
|
||||
|
||||
um := manager.NewUserManager(ur, pwr, ccr, db.TransactionFactory(dbMap), manager.ManagerOptions{})
|
||||
um.Clock = clock
|
||||
return ur, pwr, um
|
||||
|
|
|
@ -131,7 +131,10 @@ func (cfg *SingleServerConfig) Configure(srv *Server) error {
|
|||
if err != nil {
|
||||
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)
|
||||
skRepo := db.NewSessionKeyRepo(dbMap)
|
||||
|
|
|
@ -118,7 +118,10 @@ func makeTestFixtures() (*testFixtures, error) {
|
|||
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{})
|
||||
|
||||
|
|
|
@ -141,9 +141,17 @@ func makeTestFixtures() (*UsersAPI, *testEmailer) {
|
|||
return repo
|
||||
}()
|
||||
|
||||
ccr := connector.NewConnectorConfigRepoFromConfigs([]connector.ConnectorConfig{
|
||||
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
|
||||
}()
|
||||
|
||||
mgr := manager.NewUserManager(ur, pwr, ccr, db.TransactionFactory(dbMap), manager.ManagerOptions{})
|
||||
mgr.Clock = clock
|
||||
ci := oidc.ClientIdentity{
|
||||
|
|
|
@ -77,9 +77,17 @@ func makeTestFixtures() *testFixtures {
|
|||
return repo
|
||||
}()
|
||||
|
||||
f.ccr = connector.NewConnectorConfigRepoFromConfigs([]connector.ConnectorConfig{
|
||||
f.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
|
||||
}()
|
||||
|
||||
f.mgr = NewUserManager(f.ur, f.pwr, f.ccr, db.TransactionFactory(dbMap), ManagerOptions{})
|
||||
f.mgr.Clock = f.clock
|
||||
return f
|
||||
|
|
Reference in a new issue