mirror of
https://github.com/fleetdm/fleet
synced 2026-05-21 07:58:31 +00:00
The mantra for MDM lifecycle events is: > - Noah: When MDM is turned on, install fleetd, bootstrap package (if DEP), > and profiles. Don't clear host vitals (everything you see on the Host > details page) > - Noah: On re-enrollment, don't clear host vitals. > - Noah: On lock and wipe, don't clear host vitals. > - Noah: On delete, clear host vitals. This addresses issues: - https://github.com/fleetdm/fleet/issues/17243 - https://github.com/fleetdm/fleet/issues/17481 - https://github.com/fleetdm/fleet/issues/17292 - https://github.com/fleetdm/fleet/issues/18030 - https://github.com/fleetdm/fleet/issues/18031
61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
package mdmlifecycle
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/mock"
|
|
kitlog "github.com/go-kit/log"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDoUnsupportedParams(t *testing.T) {
|
|
ds := new(mock.Store)
|
|
lc := New(ds, kitlog.NewNopLogger())
|
|
|
|
err := lc.Do(context.Background(), HostOptions{})
|
|
require.ErrorContains(t, err, "unsupported platform")
|
|
|
|
err = lc.Do(context.Background(), HostOptions{Platform: "linux"})
|
|
require.ErrorContains(t, err, "unsupported platform")
|
|
|
|
err = lc.Do(context.Background(), HostOptions{Platform: "darwin", Action: "invalid"})
|
|
require.ErrorContains(t, err, "unknown action")
|
|
|
|
err = lc.Do(context.Background(), HostOptions{Platform: "windows", Action: "invalid"})
|
|
require.ErrorContains(t, err, "unknown action")
|
|
}
|
|
|
|
func TestDoParamValidation(t *testing.T) {
|
|
ds := new(mock.Store)
|
|
lf := New(ds, kitlog.NewNopLogger())
|
|
ctx := context.Background()
|
|
|
|
cases := []struct {
|
|
platform string
|
|
action HostAction
|
|
wantErr bool
|
|
}{
|
|
|
|
{"darwin", HostActionTurnOn, true},
|
|
{"darwin", HostActionTurnOff, true},
|
|
{"darwin", HostActionReset, true},
|
|
{"darwin", HostActionDelete, true},
|
|
{"windows", HostActionTurnOn, true},
|
|
{"windows", HostActionTurnOff, true},
|
|
{"windows", HostActionReset, true},
|
|
{"windows", HostActionDelete, false},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
err := lf.Do(ctx, HostOptions{
|
|
Action: tc.action,
|
|
Platform: tc.platform,
|
|
})
|
|
if tc.wantErr {
|
|
require.ErrorContains(t, err, "required")
|
|
} else {
|
|
require.NoError(t, err)
|
|
}
|
|
}
|
|
}
|