fleet/server/service_osquery_test.go
Victor Vrantchan df19fd4b7c Update users service (#156)
Closes #144 #145 #160 
Implements PATCH method on user and endpoint middleware for authnz
Implements `reset_password` (with token) and `forgot_password` endpoints
Added godoc comments for UserService interface
Shift to using testify/assert in test code
Multiple fixes/changes to the UserService API
2016-09-15 10:52:17 -04:00

60 lines
1.3 KiB
Go

package server
import (
"context"
"testing"
kitlog "github.com/go-kit/kit/log"
"github.com/kolide/kolide-ose/config"
"github.com/kolide/kolide-ose/datastore"
"github.com/stretchr/testify/assert"
)
func TestEnrollAgent(t *testing.T) {
ds, err := datastore.New("gorm-sqlite3", ":memory:")
assert.Nil(t, err)
conf := config.TestConfig()
conf.Osquery.EnrollSecret = "foobar"
svc, err := NewService(ds, kitlog.NewNopLogger(), conf, nil)
assert.Nil(t, err)
ctx := context.Background()
hosts, err := ds.Hosts()
assert.Nil(t, err)
assert.Len(t, hosts, 0)
nodeKey, err := svc.EnrollAgent(ctx, "foobar", "host123")
assert.Nil(t, err)
assert.NotEmpty(t, nodeKey)
hosts, err = ds.Hosts()
assert.Nil(t, err)
assert.Len(t, hosts, 1)
}
func TestEnrollAgentIncorrectEnrollSecret(t *testing.T) {
ds, err := datastore.New("gorm-sqlite3", ":memory:")
assert.Nil(t, err)
conf := config.TestConfig()
conf.Osquery.EnrollSecret = "foobar"
svc, err := NewService(ds, kitlog.NewNopLogger(), conf, nil)
assert.Nil(t, err)
ctx := context.Background()
hosts, err := ds.Hosts()
assert.Nil(t, err)
assert.Len(t, hosts, 0)
nodeKey, err := svc.EnrollAgent(ctx, "not_correct", "host123")
assert.NotNil(t, err)
assert.Empty(t, nodeKey)
hosts, err = ds.Hosts()
assert.Nil(t, err)
assert.Len(t, hosts, 0)
}