mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
371c533bfc
* WIP * Amend tests * Do not load aggregated stats for packs * Add option to host lite * Fix remaining TODOs * Fix osquery_utils tests * Fix SQL * Fix SQL (bis) * Restore AuthenticateHost to load once * Code improvements and re-add deferred host save * More fixes to the PR * Wrap users table update on tx * Add caching to ListPacksForHost and ListScheduledQueriesInPack * Remove SaveHostSoftware (replaced by UpdateHostSoftware) * Add unit tests for new functionality * Add changes file * Fix scheduled queries test
54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
"github.com/fleetdm/fleet/v4/server/mock"
|
|
"github.com/fleetdm/fleet/v4/server/ptr"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAgentOptionsForHost(t *testing.T) {
|
|
ds := new(mock.Store)
|
|
svc := newTestService(ds, nil, nil)
|
|
|
|
teamID := uint(1)
|
|
ds.AppConfigFunc = func(ctx context.Context) (*fleet.AppConfig, error) {
|
|
return &fleet.AppConfig{
|
|
AgentOptions: ptr.RawMessage(json.RawMessage(`{"config":{"baz":"bar"},"overrides":{"platforms":{"darwin":{"foo":"override2"}}}}`)),
|
|
}, nil
|
|
}
|
|
ds.TeamAgentOptionsFunc = func(ctx context.Context, id uint) (*json.RawMessage, error) {
|
|
return ptr.RawMessage(json.RawMessage(`{"config":{"foo":"bar"},"overrides":{"platforms":{"darwin":{"foo":"override"}}}}`)), nil
|
|
}
|
|
|
|
host := &fleet.Host{
|
|
TeamID: &teamID,
|
|
Platform: "darwin",
|
|
}
|
|
|
|
opt, err := svc.AgentOptionsForHost(context.Background(), host.TeamID, host.Platform)
|
|
require.NoError(t, err)
|
|
assert.JSONEq(t, `{"foo":"override"}`, string(opt))
|
|
|
|
host.Platform = "windows"
|
|
opt, err = svc.AgentOptionsForHost(context.Background(), host.TeamID, host.Platform)
|
|
require.NoError(t, err)
|
|
assert.JSONEq(t, `{"foo":"bar"}`, string(opt))
|
|
|
|
// Should take gobal option with no team
|
|
host.TeamID = nil
|
|
opt, err = svc.AgentOptionsForHost(context.Background(), host.TeamID, host.Platform)
|
|
require.NoError(t, err)
|
|
assert.JSONEq(t, `{"baz":"bar"}`, string(opt))
|
|
|
|
host.Platform = "darwin"
|
|
opt, err = svc.AgentOptionsForHost(context.Background(), host.TeamID, host.Platform)
|
|
require.NoError(t, err)
|
|
assert.JSONEq(t, `{"foo":"override2"}`, string(opt))
|
|
}
|