fleet/server/service/service_appconfig_test.go
Zachary Wasserman 0502412e15 Move live query operations from MySQL to Redis
This change optimizes live queries by pushing the computation of query
targets to the creation time of the query, and efficiently caching the
targets in Redis. This results in a huge performance improvement at both
steady-state, and when running live queries.

- Live queries are stored using a bitfield in Redis, and takes
advantage of bitfield operations to be extremely efficient.

- Only run Redis live query test when REDIS_TEST is set in environment

- Ensure that live queries are only sent to hosts when there is a client
listening for results. Addresses an existing issue in Fleet along with
appropriate cleanup for the refactored live query backend.
2020-07-21 14:05:46 -07:00

86 lines
2.3 KiB
Go

package service
import (
"context"
"testing"
"github.com/kolide/fleet/server/kolide"
"github.com/kolide/fleet/server/mock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCleanupURL(t *testing.T) {
tests := []struct {
in string
expected string
name string
}{
{" http://foo.bar.com ", "http://foo.bar.com", "leading and trailing whitespace"},
{"\n http://foo.com \t", "http://foo.com", "whitespace"},
{"http://foo.com", "http://foo.com", "noop"},
{"http://foo.com/", "http://foo.com", "trailing slash"},
}
for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
actual := cleanupURL(test.in)
assert.Equal(tt, test.expected, actual)
})
}
}
func TestCreateAppConfig(t *testing.T) {
ds := new(mock.Store)
svc, err := newTestService(ds, nil, nil)
require.Nil(t, err)
ds.AppConfigFunc = func() (*kolide.AppConfig, error) {
return &kolide.AppConfig{}, nil
}
var appConfigTests = []struct {
configPayload kolide.AppConfigPayload
}{
{
configPayload: kolide.AppConfigPayload{
OrgInfo: &kolide.OrgInfo{
OrgLogoURL: stringPtr("acme.co/images/logo.png"),
OrgName: stringPtr("Acme"),
},
ServerSettings: &kolide.ServerSettings{
KolideServerURL: stringPtr("https://acme.co:8080/"),
LiveQueryDisabled: boolPtr(true),
},
},
},
}
for _, tt := range appConfigTests {
var result *kolide.AppConfig
ds.NewAppConfigFunc = func(config *kolide.AppConfig) (*kolide.AppConfig, error) {
result = config
return config, nil
}
var gotSecretSpec *kolide.EnrollSecretSpec
ds.ApplyEnrollSecretSpecFunc = func(spec *kolide.EnrollSecretSpec) error {
gotSecretSpec = spec
return nil
}
_, err := svc.NewAppConfig(context.Background(), tt.configPayload)
require.Nil(t, err)
payload := tt.configPayload
assert.Equal(t, *payload.OrgInfo.OrgLogoURL, result.OrgLogoURL)
assert.Equal(t, *payload.OrgInfo.OrgName, result.OrgName)
assert.Equal(t, "https://acme.co:8080", result.KolideServerURL)
assert.Equal(t, *payload.ServerSettings.LiveQueryDisabled, result.LiveQueryDisabled)
// Ensure enroll secret was set
require.NotNil(t, gotSecretSpec)
require.Len(t, gotSecretSpec.Secrets, 1)
assert.Len(t, gotSecretSpec.Secrets[0].Secret, 32)
}
}