added SoftwareUpdateSettings to Settings command (Fixes #771) (#856)

This commit is contained in:
Kory Prince
2023-02-16 12:06:29 -06:00
committed by GitHub
parent 0242fb9bd3
commit 88e9b0c4b4
7 changed files with 528 additions and 406 deletions

View File

@@ -1,6 +1,6 @@
## [Unreleased](https://github.com/micromdm/micromdm/compare/v1.10.1...main)
This release is eagerly awaiting *your* awesome contribution!
- Add SoftwareUpdateSettings to Settings command (#771, #856)
## [v1.10.1](https://github.com/micromdm/micromdm/compare/v1.10.0...v1.10.1) January 24, 2023

View File

@@ -234,6 +234,7 @@ type Setting struct {
MDMOptions map[string]interface{} `plist:",omitempty" json:"mdm_options,omitempty"`
PasscodeLockGracePeriod *int `plist:",omitempty" json:"passcode_lock_grace_period,omitempty"`
MaximumResidentUsers *int `plist:",omitempty" json:"maximum_resident_users,omitempty"`
RecommendationCadence *int `plist:",omitempty" json:"recommendation_cadence,omitempty"`
Configuration map[string]interface{} `plist:",omitempty" json:"-"`
ConfigurationData []byte `plist:"-" json:"configuration"` // used to build the dictionary
}

File diff suppressed because it is too large Load Diff

View File

@@ -292,6 +292,7 @@ message Setting {
AppAnalyticsSetting app_analytics = 14;
ApplicationConfigurationSetting application_configuration = 15;
TimeZoneSetting time_zone = 16;
SoftwareUpdateSettingsSetting software_update_settings = 17;
}
message VoiceRoamingSetting {
@@ -337,6 +338,10 @@ message TimeZoneSetting {
string time_zone = 1;
}
message SoftwareUpdateSettingsSetting {
int64 recommendation_cadence = 1;
}
message HostnameSetting {
string hostname = 1;
}

View File

@@ -514,6 +514,10 @@ func settingToProto(s Setting) *mdmproto.Setting {
pbs.AppAnalytics = &mdmproto.AppAnalyticsSetting{
Enabled: falseIfNil(s.Enabled),
}
case "SoftwareUpdateSettings":
pbs.SoftwareUpdateSettings = &mdmproto.SoftwareUpdateSettingsSetting{
RecommendationCadence: int64(zeroIntIfNil(s.RecommendationCadence)),
}
}
return &pbs
}

View File

@@ -29,6 +29,7 @@ Not tested end to end but checked against pdf:
func TestMarshalCommand(t *testing.T) {
var deferrals int64 = 3
var cadence int
var tests = []struct {
Command Command
}{
@@ -167,6 +168,14 @@ func TestMarshalCommand(t *testing.T) {
},
},
},
{
Command: Command{
RequestType: "Settings",
Settings: &Settings{
Settings: []Setting{{Item: "SoftwareUpdateSettings", RecommendationCadence: &cadence}},
},
},
},
}
for _, tt := range tests {
t.Run(tt.Command.RequestType+"_json", func(t *testing.T) {
@@ -573,6 +582,25 @@ func TestEndToEnd(t *testing.T) {
}
},
},
{
name: "SoftwareUpdateSettings",
requestBytes: []byte(
`{"request_type":"Settings","settings":[{"item":"SoftwareUpdateSettings","recommendation_cadence":0}]}`,
),
testFn: func(t *testing.T, parts endToEndParts) {
needToSee := [][]byte{
[]byte(`Settings`),
[]byte(`SoftwareUpdateSettings`),
[]byte(`RecommendationCadence`),
[]byte(`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)))
}
}
},
},
}
for _, tt := range tests {

View File

@@ -455,6 +455,10 @@ func protoToSetting(s *mdmproto.Setting) Setting {
case "AppAnalytics":
pbs := s.GetAppAnalytics()
setting.Enabled = nilIfFalse(pbs.GetEnabled())
case "SoftwareUpdateSettings":
pbs := s.GetSoftwareUpdateSettings()
cadence := int(pbs.GetRecommendationCadence())
setting.RecommendationCadence = &cadence
}
return setting
}