diff --git a/admin/api_test.go b/admin/api_test.go index daaf913e..4409e2b7 100644 --- a/admin/api_test.go +++ b/admin/api_test.go @@ -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") diff --git a/connector/config_repo.go b/connector/config_repo.go index e44e5fe3..3ff6d68f 100644 --- a/connector/config_repo.go +++ b/connector/config_repo.go @@ -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 -} diff --git a/functional/repo/connector_repo_test.go b/functional/repo/connector_repo_test.go index b4ea43ab..09752926 100644 --- a/functional/repo/connector_repo_test.go +++ b/functional/repo/connector_repo_test.go @@ -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) diff --git a/integration/common_test.go b/integration/common_test.go index eed147ef..f7fe429b 100644 --- a/integration/common_test.go +++ b/integration/common_test.go @@ -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 diff --git a/server/config.go b/server/config.go index d204065f..f54e5a29 100644 --- a/server/config.go +++ b/server/config.go @@ -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) diff --git a/server/testutil.go b/server/testutil.go index 84788988..c1d5ce31 100644 --- a/server/testutil.go +++ b/server/testutil.go @@ -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{}) diff --git a/user/api/api_test.go b/user/api/api_test.go index 0cf1e019..ac44389e 100644 --- a/user/api/api_test.go +++ b/user/api/api_test.go @@ -141,9 +141,17 @@ func makeTestFixtures() (*UsersAPI, *testEmailer) { 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 + }() + mgr := manager.NewUserManager(ur, pwr, ccr, db.TransactionFactory(dbMap), manager.ManagerOptions{}) mgr.Clock = clock ci := oidc.ClientIdentity{ diff --git a/user/manager/manager_test.go b/user/manager/manager_test.go index 4599c572..ab3e7c09 100644 --- a/user/manager/manager_test.go +++ b/user/manager/manager_test.go @@ -77,9 +77,17 @@ func makeTestFixtures() *testFixtures { return repo }() - f.ccr = connector.NewConnectorConfigRepoFromConfigs([]connector.ConnectorConfig{ - &connector.LocalConnectorConfig{ID: "local"}, - }) + 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