<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #46560 # Checklist for submitter If some of the following don't apply, delete the relevant line. - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [x] Added/updated automated tests - updated preview test. This won't run in CI right now b/c we didn't update fleetctl, but I ran it successfully locally - [X] QA'd all new/changed functionality manually - [x] on main, did `fleetctl preview` with the 4.86.0 tag and verified that charts were disabled - [x] on this branch, did the same and verified charts were enabled <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Dashboard chart data collection (Hosts online and Vulnerability exposure) is no longer disabled when starting preview mode. * **Chores** * Software inventory config moved to the current features flag so historical chart data is preserved. * **Tests** * Added regression checks to ensure uptime, vulnerabilities, and host-users historical data remain enabled in preview. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
86 lines
2.7 KiB
Go
86 lines
2.7 KiB
Go
package preview
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/fleetdm/fleet/v4/cmd/fleetctl/fleetctl"
|
|
"github.com/fleetdm/fleet/v4/cmd/fleetctl/fleetctl/fleetctltest"
|
|
"github.com/fleetdm/fleet/v4/pkg/nettest"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestPreviewFailsOnInvalidLicenseKey(t *testing.T) {
|
|
_, err := fleetctltest.RunAppNoChecks([]string{"preview", "--license-key", "0xDEADBEEF"})
|
|
require.ErrorContains(t, err, "--license-key")
|
|
}
|
|
|
|
func TestIntegrationsPreview(t *testing.T) {
|
|
nettest.Run(t)
|
|
|
|
t.Setenv("FLEET_SERVER_ADDRESS", "https://localhost:8412")
|
|
fleetctl.TestOverridePreviewDirectory = t.TempDir()
|
|
configPath := filepath.Join(t.TempDir(), "config")
|
|
t.Log("config path: ", configPath)
|
|
|
|
t.Cleanup(func() {
|
|
require.Empty(t, fleetctltest.RunAppForTest(t, []string{"preview", "--config", configPath, "stop"}))
|
|
})
|
|
|
|
fleetTag := os.Getenv("FLEET_PREVIEW_TAG")
|
|
if fleetTag == "" {
|
|
fleetTag = "main"
|
|
}
|
|
|
|
require.NoError(t, nettest.RunWithNetRetry(t, func() error {
|
|
_, err := fleetctltest.RunAppNoChecks([]string{
|
|
"preview",
|
|
"--config", configPath,
|
|
"--preview-config-path", filepath.Join(gitRootPath(t), "tools", "osquery", "in-a-box"),
|
|
"--tag", fleetTag,
|
|
"--disable-open-browser",
|
|
})
|
|
return err
|
|
}))
|
|
|
|
// run some sanity checks on the preview environment
|
|
|
|
// app configuration must disable analytics
|
|
appConf := fleetctltest.RunAppForTest(t, []string{"get", "config", "--include-server-config", "--config", configPath, "--yaml"})
|
|
ok := strings.Contains(appConf, `enable_analytics: false`)
|
|
require.True(t, ok, appConf)
|
|
|
|
// software inventory must be enabled
|
|
ok = strings.Contains(appConf, `enable_software_inventory: true`)
|
|
require.True(t, ok, appConf)
|
|
|
|
// Regression guard:
|
|
// preview used to apply its config patch via the deprecated `host_settings`
|
|
// key, which wholesale-replaced the Features struct and silently zeroed the
|
|
// historical_data sub-keys. Applying via `features` merges field-by-field
|
|
// and preserves them.
|
|
ok = strings.Contains(appConf, `uptime: true`)
|
|
require.True(t, ok, appConf)
|
|
ok = strings.Contains(appConf, `vulnerabilities: true`)
|
|
require.True(t, ok, appConf)
|
|
ok = strings.Contains(appConf, `enable_host_users: true`)
|
|
require.True(t, ok, appConf)
|
|
|
|
// current instance checks must be on
|
|
ok = strings.Contains(appConf, `current_instance_checks: "yes"`)
|
|
require.True(t, ok, appConf)
|
|
|
|
// a vulnerability database path must be set
|
|
ok = strings.Contains(appConf, `databases_path: /vulndb`)
|
|
require.True(t, ok, appConf)
|
|
}
|
|
|
|
func gitRootPath(t *testing.T) string {
|
|
path, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
|
|
require.NoError(t, err)
|
|
return strings.TrimSpace(string(path))
|
|
}
|