mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
885db1a597
This PR refactors most of the codebase to use the new config patterns implemented in #149. Now the core service keeps a copy of the KolideConfig struct, and service methods can reference the configuration in that struct when they need it. The most significant refactoring is in the sessions code, separating the business logic from the storage layer.
36 lines
847 B
Go
36 lines
847 B
Go
package server
|
|
|
|
import (
|
|
"testing"
|
|
|
|
kitlog "github.com/go-kit/kit/log"
|
|
"github.com/kolide/kolide-ose/config"
|
|
"github.com/kolide/kolide-ose/datastore"
|
|
"github.com/kolide/kolide-ose/kolide"
|
|
"github.com/stretchr/testify/assert"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
const bcryptCost = 6
|
|
|
|
func TestAuthenticate(t *testing.T) {
|
|
ds, err := datastore.New("gorm-sqlite3", ":memory:")
|
|
assert.Nil(t, err)
|
|
|
|
svc, err := NewService(ds, kitlog.NewNopLogger(), config.TestConfig())
|
|
assert.Nil(t, err)
|
|
|
|
ctx := context.Background()
|
|
|
|
user, err := kolide.NewUser("foo", "bar", "foo@kolide.co", false, false, bcryptCost)
|
|
assert.Nil(t, err)
|
|
user, err = ds.NewUser(user)
|
|
assert.Nil(t, err)
|
|
assert.NotZero(t, user.ID)
|
|
|
|
loggedIn, token, err := svc.Login(ctx, "foo", "bar")
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, user.ID, loggedIn.ID)
|
|
assert.NotEmpty(t, token)
|
|
}
|