mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
df19fd4b7c
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
60 lines
1.3 KiB
Go
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)
|
|
}
|