dex/functional/config/config_sample_test.go
Bobby Rullo ca18efb1fe client: load full clients w/ LoadableClient
The Client object on its own doesn't fully express everything about a
single client, and so when loading clients from a static configuration
it's not enough to just (de)serialize clients.

To that end, LoadableClient contains the full representation of a client
and associated entities.
2016-06-08 11:31:50 -07:00

47 lines
1 KiB
Go

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, err := db.NewClientRepoFromClients(memDB, clients)
if err != nil {
t.Fatalf("Error creating Clients: %v", err)
}
mgr := manager.NewClientManager(repo, db.TransactionFactory(memDB), manager.ManagerOptions{})
for i, c := range clients {
ok, err := mgr.Authenticate(c.Client.Credentials)
if !ok {
t.Errorf("case %d: couldn't authenticate", i)
}
if err != nil {
t.Errorf("case %d: error authenticating: %v", i, err)
}
}
}