-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #199 from ericchiang/validate_connector
api: validate local connector existence before creating user
- Loading branch information
Showing
20 changed files
with
317 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package repo | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/coreos/dex/connector" | ||
"github.com/coreos/dex/db" | ||
) | ||
|
||
type connectorConfigRepoFactory func(cfgs []connector.ConnectorConfig) connector.ConnectorConfigRepo | ||
|
||
var makeTestConnectorConfigRepoFromConfigs connectorConfigRepoFactory | ||
|
||
func init() { | ||
if dsn := os.Getenv("DEX_TEST_DSN"); dsn == "" { | ||
makeTestConnectorConfigRepoFromConfigs = connector.NewConnectorConfigRepoFromConfigs | ||
} else { | ||
makeTestConnectorConfigRepoFromConfigs = makeTestConnectorConfigRepoMem(dsn) | ||
} | ||
} | ||
|
||
func makeTestConnectorConfigRepoMem(dsn string) connectorConfigRepoFactory { | ||
return func(cfgs []connector.ConnectorConfig) connector.ConnectorConfigRepo { | ||
dbMap := initDB(dsn) | ||
|
||
repo := db.NewConnectorConfigRepo(dbMap) | ||
if err := repo.Set(cfgs); err != nil { | ||
panic(fmt.Sprintf("Unable to set connector configs: %v", err)) | ||
} | ||
return repo | ||
} | ||
} | ||
|
||
func TestConnectorConfigRepoGetByID(t *testing.T) { | ||
tests := []struct { | ||
cfgs []connector.ConnectorConfig | ||
id string | ||
err error | ||
}{ | ||
{ | ||
cfgs: []connector.ConnectorConfig{ | ||
&connector.LocalConnectorConfig{ID: "local"}, | ||
}, | ||
id: "local", | ||
}, | ||
{ | ||
cfgs: []connector.ConnectorConfig{ | ||
&connector.LocalConnectorConfig{ID: "local1"}, | ||
&connector.LocalConnectorConfig{ID: "local2"}, | ||
}, | ||
id: "local2", | ||
}, | ||
{ | ||
cfgs: []connector.ConnectorConfig{ | ||
&connector.LocalConnectorConfig{ID: "local1"}, | ||
&connector.LocalConnectorConfig{ID: "local2"}, | ||
}, | ||
id: "foo", | ||
err: connector.ErrorNotFound, | ||
}, | ||
} | ||
|
||
for i, tt := range tests { | ||
repo := makeTestConnectorConfigRepoFromConfigs(tt.cfgs) | ||
if _, err := repo.GetConnectorByID(nil, tt.id); err != tt.err { | ||
t.Errorf("case %d: want=%v, got=%v", i, tt.err, err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.