Repository: micromdm/micromdm
Pull request #651 (2020-03-09 11:35:28)

Add EnableRemoteDesktop and DisableRemoteDesktop
Add ability to send EnableRemoteDesktop and DisableRemoteDesktop mdm-commands:
https://developer.apple.com/documentation/devicemanagement/enable_remote_desktop

tomaswallentinus: Am I suppose to ad an test in TestEndToEnd as well or is that just for endpoints that have an base64 encoded payload?

Patch:
diff --git a/mdm/mdm/internal/mdmproto/mdm.proto b/mdm/mdm/internal/mdmproto/mdm.proto
index 4b73721..213cc64 100644
--- a/mdm/mdm/internal/mdmproto/mdm.proto
+++ b/mdm/mdm/internal/mdmproto/mdm.proto
@@ -28,6 +28,8 @@ message Command {
      - DeviceConfigured
      - AvailableOSUpdates
      - NSExtensionMappings
+     - EnableRemoteDesktop
+     - DisableRemoteDesktop
      - ActivationLockBypassCode
    */
   oneof request {
diff --git a/mdm/mdm/marshal_json.go b/mdm/mdm/marshal_json.go
index f989b04..b1d0870 100644
--- a/mdm/mdm/marshal_json.go
+++ b/mdm/mdm/marshal_json.go
@@ -25,6 +25,8 @@ func (c *Command) MarshalJSON() ([]byte, error) {
 		"AvailableOSUpdates",
 		"NSExtensionMappings",
 		"OSUpdateStatus",
+		"EnableRemoteDesktop",
+		"DisableRemoteDesktop",
 		"ActivationLockBypassCode":
 		var x = struct {
 			RequestType string `json:"request_type"`
diff --git a/mdm/mdm/marshal_plist.go b/mdm/mdm/marshal_plist.go
index 51842f8..95cf014 100644
--- a/mdm/mdm/marshal_plist.go
+++ b/mdm/mdm/marshal_plist.go
@@ -27,6 +27,8 @@ func (c *Command) MarshalPlist() (interface{}, error) {
 		"AvailableOSUpdates",
 		"NSExtensionMappings",
 		"OSUpdateStatus",
+		"EnableRemoteDesktop",
+		"DisableRemoteDesktop",
 		"ActivationLockBypassCode":
 		return &struct {
 			RequestType string
diff --git a/mdm/mdm/marshal_proto.go b/mdm/mdm/marshal_proto.go
index ca1a8c7..6fffbf8 100644
--- a/mdm/mdm/marshal_proto.go
+++ b/mdm/mdm/marshal_proto.go
@@ -43,6 +43,8 @@ func commandToProto(cmd *Command) (*mdmproto.Command, error) {
 		"AvailableOSUpdates",
 		"NSExtensionMappings",
 		"OSUpdateStatus",
+		"EnableRemoteDesktop",
+		"DisableRemoteDesktop",
 		"ActivationLockBypassCode":
 
 	case "InstallProfile":
diff --git a/mdm/mdm/unmarshal_json.go b/mdm/mdm/unmarshal_json.go
index dce6845..5324672 100644
--- a/mdm/mdm/unmarshal_json.go
+++ b/mdm/mdm/unmarshal_json.go
@@ -48,6 +48,8 @@ func (c *Command) UnmarshalJSON(data []byte) error {
 		"AvailableOSUpdates",
 		"NSExtensionMappings",
 		"OSUpdateStatus",
+		"EnableRemoteDesktop",
+		"DisableRemoteDesktop",
 		"ActivationLockBypassCode":
 		return nil
 	case "InstallProfile":
diff --git a/mdm/mdm/unmarshal_plist.go b/mdm/mdm/unmarshal_plist.go
index cfb2a0b..706c7d3 100644
--- a/mdm/mdm/unmarshal_plist.go
+++ b/mdm/mdm/unmarshal_plist.go
@@ -34,6 +34,8 @@ func (c *Command) UnmarshalPlist(unmarshal func(i interface{}) error) error {
 		"AvailableOSUpdates",
 		"NSExtensionMappings",
 		"OSUpdateStatus",
+		"EnableRemoteDesktop",
+		"DisableRemoteDesktop",
 		"ActivationLockBypassCode":
 		return nil
 	case "InstallProfile":
diff --git a/mdm/mdm/unmarshal_proto.go b/mdm/mdm/unmarshal_proto.go
index 87fa398..25dd2d5 100644
--- a/mdm/mdm/unmarshal_proto.go
+++ b/mdm/mdm/unmarshal_proto.go
@@ -28,6 +28,8 @@ func protoToCommand(pb *mdmproto.Command) *Command {
 		"AvailableOSUpdates",
 		"NSExtensionMappings",
 		"OSUpdateStatus",
+		"EnableRemoteDesktop",
+		"DisableRemoteDesktop",
 		"ActivationLockBypassCode":
 
 	case "InstallProfile":
diff --git a/tools/api/commands/disable_remote_desktop b/tools/api/commands/disable_remote_desktop
new file mode 100644
index 0000000..bcccd39
--- /dev/null
+++ b/tools/api/commands/disable_remote_desktop
@@ -0,0 +1,10 @@
+#!/bin/bash
+source $MICROMDM_ENV_PATH
+endpoint="v1/commands"
+jq -n \
+  --arg request_type "DisableRemoteDesktop" \
+  --arg udid "$1" \
+  '.udid = $udid 
+  |.request_type = $request_type
+  '|\
+  curl $CURL_OPTS -u "micromdm:$API_TOKEN" "$SERVER_URL/$endpoint" -d@-
diff --git a/tools/api/commands/enable_remote_desktop b/tools/api/commands/enable_remote_desktop
new file mode 100644
index 0000000..8fca74d
--- /dev/null
+++ b/tools/api/commands/enable_remote_desktop
@@ -0,0 +1,10 @@
+#!/bin/bash
+source $MICROMDM_ENV_PATH
+endpoint="v1/commands"
+jq -n \
+  --arg request_type "EnableRemoteDesktop" \
+  --arg udid "$1" \
+  '.udid = $udid 
+  |.request_type = $request_type
+  '|\
+  curl $CURL_OPTS -u "micromdm:$API_TOKEN" "$SERVER_URL/$endpoint" -d@-


Test patch:
diff --git a/mdm/mdm/mdm_command_test.go b/mdm/mdm/mdm_command_test.go
index 5413702..f1e3ce7 100644
--- a/mdm/mdm/mdm_command_test.go
+++ b/mdm/mdm/mdm_command_test.go
@@ -52,6 +52,16 @@ func TestMarshalCommand(t *testing.T) {
 				},
 			},
 		},
+		{
+			Command: Command{
+				RequestType: "EnableRemoteDesktop",
+			},
+		},
+		{
+			Command: Command{
+				RequestType: "DisableRemoteDesktop",
+			},
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.Command.RequestType+"_json", func(t *testing.T) {