Files
fleet/orbit/pkg/update/debug_log_runner_test.go
T
Jordan MontgomeryandCopilot Autofix powered by AI bee5edaa0b Add server-side orbit debug logging enablement - currently only configurable as a duration-after-enrollment setting (#45367)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #43997 

# 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.

- [x] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements), JS
inline code is prevented especially for url redirects, and untrusted
data interpolated into shell scripts/commands is validated against shell
metacharacters.
- [x] Timeouts are implemented and retries are limited to avoid infinite
loops
- [x] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes

## Testing

- [x] Added/updated automated tests
- [x] Where appropriate, [automated tests simulate multiple hosts and
test for host
isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing)
(updates to one hosts's records do not affect another)

- [x] QA'd all new/changed functionality manually

## Database migrations

- [x] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [x] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [x] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).

## fleetd/orbit/Fleet Desktop

- [x] Verified compatibility with the latest released version of Fleet
(see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md))
- [x] Verified that fleetd runs on macOS, Linux and Windows
- [x] Verified auto-update works from the released version of component
to the new version (see [tools/tuf/test](../tools/tuf/test/README.md))


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Configure Orbit to enable debug logging for a limited window on agent
enrollment; enrolled hosts receive debug/verbose behavior while the
window is active and it is reflected in agent config.

* **Chores**
* Added database column to record per-host debug-until timestamps and
datastore support to extend it safely.

* **Tests**
* Added integration and unit tests covering validation, enrollment
stamping, config generation, and runtime debug toggling.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/fleetdm/fleet/pull/45367)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-05-14 13:32:02 -04:00

98 lines
2.6 KiB
Go

package update
import (
"testing"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"
)
func TestDebugLogReceiver(t *testing.T) {
orig := zerolog.GlobalLevel()
t.Cleanup(func() { zerolog.SetGlobalLevel(orig) })
r := NewDebugLogReceiver(false)
trueVal := true
falseVal := false
cases := []struct {
name string
startLevel zerolog.Level
debugLogging *bool
expectedLevel zerolog.Level
}{
{
name: "true flips info to debug",
startLevel: zerolog.InfoLevel,
debugLogging: &trueVal,
expectedLevel: zerolog.DebugLevel,
},
{
name: "false flips debug to info",
startLevel: zerolog.DebugLevel,
debugLogging: &falseVal,
expectedLevel: zerolog.InfoLevel,
},
{
name: "true is idempotent when already debug",
startLevel: zerolog.DebugLevel,
debugLogging: &trueVal,
expectedLevel: zerolog.DebugLevel,
},
{
name: "false is idempotent when already info",
startLevel: zerolog.InfoLevel,
debugLogging: &falseVal,
expectedLevel: zerolog.InfoLevel,
},
{
name: "nil config field treated as false, idempotent when already info",
startLevel: zerolog.InfoLevel,
debugLogging: nil,
expectedLevel: zerolog.InfoLevel,
},
{
name: "nil config field treated as false, flips debug to info",
startLevel: zerolog.DebugLevel,
debugLogging: nil,
expectedLevel: zerolog.InfoLevel,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
zerolog.SetGlobalLevel(tc.startLevel)
err := r.Run(&fleet.OrbitConfig{DebugLogging: tc.debugLogging})
require.NoError(t, err)
require.Equal(t, tc.expectedLevel, zerolog.GlobalLevel())
})
}
}
func TestDebugLogReceiverStartupFlagIsFloor(t *testing.T) {
orig := zerolog.GlobalLevel()
t.Cleanup(func() { zerolog.SetGlobalLevel(orig) })
r := NewDebugLogReceiver(true)
trueVal := true
falseVal := false
// Server off + already debug: floor keeps it on.
zerolog.SetGlobalLevel(zerolog.DebugLevel)
require.NoError(t, r.Run(&fleet.OrbitConfig{DebugLogging: &falseVal}))
require.Equal(t, zerolog.DebugLevel, zerolog.GlobalLevel())
// Server nil + already debug: floor keeps it on.
zerolog.SetGlobalLevel(zerolog.DebugLevel)
require.NoError(t, r.Run(&fleet.OrbitConfig{DebugLogging: nil}))
require.Equal(t, zerolog.DebugLevel, zerolog.GlobalLevel())
// Server on: always honored.
zerolog.SetGlobalLevel(zerolog.InfoLevel)
require.NoError(t, r.Run(&fleet.OrbitConfig{DebugLogging: &trueVal}))
require.Equal(t, zerolog.DebugLevel, zerolog.GlobalLevel())
}