Split MDM platform helpers by Android semantics (#50185)
**Related issue:** Resolves #46118
This commit is contained in:
@@ -111,7 +111,7 @@ func mdmRunCommand() *cli.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
mdmHostPlatform := fleet.MDMPlatform(host.Platform)
|
||||
mdmHostPlatform := fleet.ClassicMDMPlatform(host.Platform)
|
||||
if mdmHostPlatform != mdmPlatform && mdmPlatform != "" {
|
||||
return errors.New(`Command can't run on hosts with different platforms. Make sure the hosts specified in the "hosts" flag are either all macOS or all Windows hosts.`)
|
||||
}
|
||||
@@ -238,7 +238,7 @@ func mdmUnlockCommand() *cli.Command {
|
||||
return fmt.Errorf("Failed to unlock host: %w", err)
|
||||
}
|
||||
|
||||
if fleet.MDMPlatform(host.Platform) == "darwin" {
|
||||
if fleet.ClassicMDMPlatform(host.Platform) == "darwin" {
|
||||
fmt.Fprintf(c.App.Writer, `
|
||||
Use this 6 digit PIN to unlock the host:
|
||||
|
||||
@@ -366,9 +366,8 @@ func hostMdmActionSetup(c *cli.Context, hostIdent string, actionType string) (cl
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// check mdm is on for the host. Android isn't in fleet.MDMPlatform.
|
||||
// See eng-init story: https://github.com/fleetdm/fleet/issues/46118
|
||||
if fleet.MDMSupported(host.Platform) || fleet.IsAndroidPlatform(host.Platform) {
|
||||
// check mdm is on for the host
|
||||
if fleet.MDMTurnedOnSupported(host.Platform) {
|
||||
if host.MDM.ConnectedToFleet == nil || !*host.MDM.ConnectedToFleet {
|
||||
return nil, nil, fmt.Errorf("Can't %s the host because it doesn't have MDM turned on.", actionType)
|
||||
}
|
||||
|
||||
@@ -742,6 +742,15 @@ func TestMDMUnlockCommand(t *testing.T) {
|
||||
},
|
||||
mdmInfo: &fleet.HostMDM{Enrolled: true, Name: fleet.WellKnownMDMFleet},
|
||||
}
|
||||
androidNotConnected := testhost{
|
||||
host: &fleet.Host{
|
||||
ID: 15,
|
||||
UUID: "android-not-connected",
|
||||
Platform: "android",
|
||||
MDM: fleet.MDMHostData{Name: fleet.WellKnownMDMFleet, EnrollmentStatus: new("Off"), ConnectedToFleet: new(false)},
|
||||
},
|
||||
mdmInfo: &fleet.HostMDM{Enrolled: false, Name: fleet.WellKnownMDMFleet},
|
||||
}
|
||||
|
||||
hostByUUID := make(map[string]testhost)
|
||||
hostsByID := make(map[uint]testhost)
|
||||
@@ -758,6 +767,7 @@ func TestMDMUnlockCommand(t *testing.T) {
|
||||
macEnrolledLP,
|
||||
winEnrolledWP,
|
||||
macEnrolledWP,
|
||||
androidNotConnected,
|
||||
} {
|
||||
hostByUUID[h.host.UUID] = h
|
||||
hostsByID[h.host.ID] = h
|
||||
@@ -918,6 +928,7 @@ fleetctl get host %s
|
||||
{appCfgAllMDM, "valid macos but pending lock", []string{"--host", macEnrolledLP.host.UUID}, "Host has pending lock request."},
|
||||
{appCfgAllMDM, "valid windows but pending wipe", []string{"--host", winEnrolledWP.host.UUID}, "Host has pending wipe request."},
|
||||
{appCfgAllMDM, "valid macos but pending wipe", []string{"--host", macEnrolledWP.host.UUID}, "Host has pending wipe request."},
|
||||
{appCfgAllMDM, "valid android but not connected", []string{"--host", androidNotConnected.host.UUID}, `Can't unlock the host because it doesn't have MDM turned on.`},
|
||||
}
|
||||
|
||||
runTestCases(t, ds, "unlock", successfulOutput, cases)
|
||||
@@ -1076,6 +1087,15 @@ func TestMDMWipeCommand(t *testing.T) {
|
||||
Platform: "linux",
|
||||
},
|
||||
}
|
||||
androidNotConnected := testhost{
|
||||
host: &fleet.Host{
|
||||
ID: 21,
|
||||
UUID: "android-not-connected",
|
||||
Platform: "android",
|
||||
MDM: fleet.MDMHostData{Name: fleet.WellKnownMDMFleet, EnrollmentStatus: new("Off"), ConnectedToFleet: new(false)},
|
||||
},
|
||||
mdmInfo: &fleet.HostMDM{Enrolled: false, Name: fleet.WellKnownMDMFleet},
|
||||
}
|
||||
|
||||
linuxHostIDs := []uint{linuxEnrolled.host.ID, linuxEnrolled2.host.ID, linuxEnrolled3.host.ID}
|
||||
|
||||
@@ -1100,6 +1120,7 @@ func TestMDMWipeCommand(t *testing.T) {
|
||||
macEnrolledWiped,
|
||||
winEnrolledLocked,
|
||||
macEnrolledLocked,
|
||||
androidNotConnected,
|
||||
} {
|
||||
hostByUUID[h.host.UUID] = h
|
||||
hostsByID[h.host.ID] = h
|
||||
@@ -1290,6 +1311,7 @@ func TestMDMWipeCommand(t *testing.T) {
|
||||
{appCfgAllMDM, "valid macos but host is locked", []string{"--host", macEnrolledLocked.host.UUID}, "Host cannot be wiped until it is unlocked."},
|
||||
{appCfgAllMDM, "valid macos but host is locked", []string{"--host", macEnrolledLocked.host.UUID}, "Host cannot be wiped until it is unlocked."},
|
||||
{appCfgScriptsDisabled, "valid linux and scripts are disabled", []string{"--host", linuxEnrolled.host.UUID}, ""},
|
||||
{appCfgAllMDM, "valid android but not connected", []string{"--host", androidNotConnected.host.UUID}, `Can't wipe the host because it doesn't have MDM turned on.`},
|
||||
}
|
||||
|
||||
successfulOutput := func(ident string) string {
|
||||
@@ -1366,14 +1388,23 @@ func TestMDMClearPasscodeCommand(t *testing.T) {
|
||||
macNotEnrolled := testhost{
|
||||
host: &fleet.Host{ID: 2, UUID: "mac-not-enrolled-cp", Platform: "darwin"},
|
||||
}
|
||||
androidNotConnected := testhost{
|
||||
host: &fleet.Host{
|
||||
ID: 3, UUID: "android-not-connected-cp", Platform: "android",
|
||||
MDM: fleet.MDMHostData{Name: fleet.WellKnownMDMFleet, EnrollmentStatus: new("Off"), ConnectedToFleet: new(false)},
|
||||
},
|
||||
mdmInfo: &fleet.HostMDM{Enrolled: false, Name: fleet.WellKnownMDMFleet},
|
||||
}
|
||||
|
||||
hostByUUID := map[string]testhost{
|
||||
macEnrolled.host.UUID: macEnrolled,
|
||||
macNotEnrolled.host.UUID: macNotEnrolled,
|
||||
macEnrolled.host.UUID: macEnrolled,
|
||||
macNotEnrolled.host.UUID: macNotEnrolled,
|
||||
androidNotConnected.host.UUID: androidNotConnected,
|
||||
}
|
||||
hostsByID := map[uint]testhost{
|
||||
macEnrolled.host.ID: macEnrolled,
|
||||
macNotEnrolled.host.ID: macNotEnrolled,
|
||||
macEnrolled.host.ID: macEnrolled,
|
||||
macNotEnrolled.host.ID: macNotEnrolled,
|
||||
androidNotConnected.host.ID: androidNotConnected,
|
||||
}
|
||||
|
||||
ds := setupTestServer(t)
|
||||
@@ -1404,6 +1435,7 @@ func TestMDMClearPasscodeCommand(t *testing.T) {
|
||||
{appCfgAllMDM, "empty host", []string{"--host", ""}, `No host targeted. Please provide --host.`},
|
||||
{appCfgAllMDM, "unknown host", []string{"--host", "doesnotexist"}, fleet.HostNotFoundErrMsg},
|
||||
{appCfgAllMDM, "darwin not enrolled", []string{"--host", macNotEnrolled.host.UUID}, "Can't clear passcode for the host because it doesn't have MDM turned on."},
|
||||
{appCfgAllMDM, "android not connected", []string{"--host", androidNotConnected.host.UUID}, "Can't clear passcode for the host because it doesn't have MDM turned on."},
|
||||
}
|
||||
for _, c := range cases {
|
||||
ds.AppConfigFunc = func(ctx context.Context) (*fleet.AppConfig, error) { return c.appCfg, nil }
|
||||
|
||||
Reference in New Issue
Block a user