Skip to content

Commit

Permalink
Add fields to ScheduleOSUpdate command (micromdm#790) (micromdm#793)
Browse files Browse the repository at this point in the history
  • Loading branch information
korylprince authored Jan 12, 2022
1 parent 784bb35 commit ba38781
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 82 deletions.
6 changes: 4 additions & 2 deletions mdm/mdm/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,10 @@ type SetAutoAdminPassword struct {
}

type OSUpdate struct {
ProductKey string `json:"product_key"`
InstallAction string `json:"install_action"`
ProductKey string `plist:",omitempty" json:"product_key,omitempty"`
InstallAction string `json:"install_action"`
MaxUserDeferrals *int64 `plist:",omitempty" json:"max_user_deferrals,omitempty"`
ProductVersion string `plist:",omitempty" json:"product_version,omitempty"`
}

type ScheduleOSUpdate struct {
Expand Down
163 changes: 87 additions & 76 deletions mdm/mdm/internal/mdmproto/mdm.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mdm/mdm/internal/mdmproto/mdm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ message Update {
string product_key = 1;
string product_version = 2;
string install_action = 3;
int64 max_user_deferrals = 4;
}

message ScheduleOSUpdateScan {
Expand Down
6 changes: 4 additions & 2 deletions mdm/mdm/marshal_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,10 @@ func commandToProto(cmd *Command) (*mdmproto.Command, error) {
var updates []*mdmproto.Update
for _, u := range cmd.ScheduleOSUpdate.Updates {
updates = append(updates, &mdmproto.Update{
ProductKey: u.ProductKey,
InstallAction: u.InstallAction,
ProductKey: u.ProductKey,
InstallAction: u.InstallAction,
MaxUserDeferrals: zeroInt64IfNil(u.MaxUserDeferrals),
ProductVersion: u.ProductVersion,
})
}
cmdproto.Request = &mdmproto.Command_ScheduleOsUpdate{
Expand Down
41 changes: 41 additions & 0 deletions mdm/mdm/mdm_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Not tested end to end but checked against pdf:
*/

func TestMarshalCommand(t *testing.T) {
var deferrals int64 = 3
var tests = []struct {
Command Command
}{
Expand Down Expand Up @@ -110,6 +111,21 @@ func TestMarshalCommand(t *testing.T) {
},
},
},
{
Command: Command{
RequestType: "ScheduleOSUpdate",
ScheduleOSUpdate: &ScheduleOSUpdate{
Updates: []OSUpdate{
{
ProductKey: "io.micromdm.micromdm",
InstallAction: "InstallLater",
MaxUserDeferrals: &deferrals,
ProductVersion: "1.0.0",
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.Command.RequestType+"_json", func(t *testing.T) {
Expand Down Expand Up @@ -315,6 +331,31 @@ func TestEndToEnd(t *testing.T) {
},
},

{
name: "ScheduleOSUpdate",
requestBytes: []byte(
`{"request_type":"ScheduleOSUpdate","updates":[{"product_key":"io.micromdm.micromdm","install_action":"InstallLater","max_user_deferrals":3,"product_version":"1.0.0"}]}`,
),
testFn: func(t *testing.T, parts endToEndParts) {
needToSee := [][]byte{
[]byte(`Updates`),
[]byte(`ProductKey`),
[]byte(`io.micromdm.micromdm`),
[]byte(`InstallAction`),
[]byte(`InstallLater`),
[]byte(`MaxUserDeferrals`),
[]byte(`3`),
[]byte(`ProductVersion`),
[]byte(`1.0.0`),
}
for _, b := range needToSee {
if !bytes.Contains(parts.plistData, b) {
t.Error(fmt.Sprintf("marshaled plist does not contain required bytes: '%s'", string(b)))
}
}
},
},

{
name: "SetFirmwarePassword_NoNewPassword",
requestBytes: []byte(
Expand Down
6 changes: 4 additions & 2 deletions mdm/mdm/unmarshal_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,10 @@ func protoToCommand(pb *mdmproto.Command) *Command {
var updates []OSUpdate
for _, up := range pbc.GetUpdates() {
updates = append(updates, OSUpdate{
ProductKey: up.GetProductKey(),
InstallAction: up.GetInstallAction(),
ProductKey: up.GetProductKey(),
InstallAction: up.GetInstallAction(),
MaxUserDeferrals: nilIfZeroInt64(up.GetMaxUserDeferrals()),
ProductVersion: up.GetProductVersion(),
})
}
cmd.ScheduleOSUpdate = &ScheduleOSUpdate{
Expand Down

0 comments on commit ba38781

Please sign in to comment.