functional: test sample clients file is valid
Also tests that it's being loaded properly (which is not the case in NewClientManagerFromClients, which will be removed in subsequent commit)
This commit is contained in:
parent
86ef34d8e2
commit
8d1a6f2324
2 changed files with 47 additions and 0 deletions
46
functional/config/config_sample_test.go
Normal file
46
functional/config/config_sample_test.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/coreos/dex/client"
|
||||
"github.com/coreos/dex/client/manager"
|
||||
"github.com/coreos/dex/db"
|
||||
)
|
||||
|
||||
const (
|
||||
clientsFile = "../../static/fixtures/clients.json.sample"
|
||||
)
|
||||
|
||||
// TestClientSample makes sure that the clients.json.sample file is valid and can be loaded properly.
|
||||
func TestClientSample(t *testing.T) {
|
||||
f, err := os.Open(clientsFile)
|
||||
if err != nil {
|
||||
t.Fatalf("could not open file %q: %v", clientsFile, err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
clients, err := client.ClientsFromReader(f)
|
||||
if err != nil {
|
||||
t.Fatalf("Error loading Clients: %v", err)
|
||||
}
|
||||
|
||||
memDB := db.NewMemDB()
|
||||
repo := db.NewClientRepo(memDB)
|
||||
for _, c := range clients {
|
||||
repo.New(nil, c)
|
||||
}
|
||||
mgr := manager.NewClientManager(repo, db.TransactionFactory(memDB), manager.ManagerOptions{})
|
||||
|
||||
for i, c := range clients {
|
||||
ok, err := mgr.Authenticate(c.Credentials)
|
||||
if !ok {
|
||||
t.Errorf("case %d: couldn't authenticate", i)
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("case %d: error authenticating: %v", i, err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -4,3 +4,4 @@ source ./env
|
|||
|
||||
go test $@ github.com/coreos/dex/functional
|
||||
go test $@ github.com/coreos/dex/functional/repo
|
||||
go test $@ github.com/coreos/dex/functional/config
|
||||
|
|
Reference in a new issue