This repository has been archived by the owner on Jun 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete listing of MDM Commands as structs (#6)
* Add struct for CertificateList response. * Add structs for all possible MDM command request types. Add definitions for each setting which may be changed by the Settings command. Add some error enums. * Move response fixtures to their own file. Add very basic tests for commands. Add prefix to each error type to stop name collision Add more response types. Fix response tests to use new fixture location. * Further simple tests for MDM commands. * Add plist responses based on real world responses to use as test fixtures. Support InstalledApplicationList command. Add struct for Error response. * Add InstalledApplicationList response item struct. * Remove duplicate definition of InstalledApplicationListItem * Add simple test for error chain. Add ErrorChain to response struct. * Add example response for InstalledApplicationList * Add test for InstalledApplicationListResponse * int field did not have enough storage for some installed apps, used uint32.
- Loading branch information
Showing
13 changed files
with
1,850 additions
and
1,044 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package mdm | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/groob/plist" | ||
"testing" | ||
) | ||
|
||
// Basic tests will attempt to marshal and unmarshal mdm command structures to identify any naming or tag errors. | ||
|
||
// Make sure a command can be marshalled to json | ||
func testMarshalJSON(t *testing.T, cmd interface{}) { | ||
jsonCmd, err := json.Marshal(cmd) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
fmt.Println(string(jsonCmd)) | ||
} | ||
|
||
// Make sure a command can be marshalled to plist | ||
func testMarshalPlist(t *testing.T, cmd interface{}) { | ||
plistCmd, err := plist.MarshalIndent(cmd, "\t") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
fmt.Println(string(plistCmd)) | ||
} | ||
|
||
func TestInstallProfile(t *testing.T) { | ||
cmd := InstallProfile{Payload: []byte{00}} | ||
testMarshalJSON(t, cmd) | ||
testMarshalPlist(t, cmd) | ||
} | ||
|
||
func TestRemoveProfile(t *testing.T) { | ||
cmd := RemoveProfile{Identifier: "io.micromdm.test.profile"} | ||
testMarshalJSON(t, cmd) | ||
testMarshalPlist(t, cmd) | ||
} | ||
|
||
func TestInstallProvisioningProfile(t *testing.T) { | ||
cmd := InstallProvisioningProfile{ProvisioningProfile: []byte{00}} | ||
testMarshalJSON(t, cmd) | ||
testMarshalPlist(t, cmd) | ||
} | ||
|
||
func TestRemoveProvisioningProfile(t *testing.T) { | ||
cmd := RemoveProvisioningProfile{UUID: "1111-2222-3333"} | ||
testMarshalJSON(t, cmd) | ||
testMarshalPlist(t, cmd) | ||
} | ||
|
||
func TestInstalledApplicationList(t *testing.T) { | ||
cmd := InstalledApplicationList{Identifiers: []string{"io.micromdm.application"}, ManagedAppsOnly: true} | ||
testMarshalJSON(t, cmd) | ||
testMarshalPlist(t, cmd) | ||
} | ||
|
||
func TestDeviceInformation(t *testing.T) { | ||
cmd := DeviceInformation{Queries: []string{"SerialNumber"}} | ||
testMarshalJSON(t, cmd) | ||
testMarshalPlist(t, cmd) | ||
} | ||
|
||
func TestDeviceLock(t *testing.T) { | ||
cmd := DeviceLock{PIN: "123456", Message: "Locked", PhoneNumber: "123-4567"} | ||
testMarshalJSON(t, cmd) | ||
testMarshalPlist(t, cmd) | ||
} | ||
|
||
func TestClearPasscode(t *testing.T) { | ||
cmd := ClearPasscode{UnlockToken: []byte{00}} | ||
testMarshalJSON(t, cmd) | ||
testMarshalPlist(t, cmd) | ||
} | ||
|
||
func TestEraseDevice(t *testing.T) { | ||
cmd := EraseDevice{PIN: "123456"} | ||
testMarshalJSON(t, cmd) | ||
testMarshalPlist(t, cmd) | ||
} | ||
|
||
func TestRequestMirroring(t *testing.T) { | ||
cmd := RequestMirroring{DestinationName: "Apple TV", ScanTime: "30", Password: "sekret"} | ||
testMarshalJSON(t, cmd) | ||
testMarshalPlist(t, cmd) | ||
} | ||
|
||
//func TestRestrictions(t *testing.T) { | ||
// cmd := Restrictions{} | ||
//} | ||
|
||
func TestDeleteUser(t *testing.T) { | ||
cmd := DeleteUser{UserName: "joe", ForceDeletion: false} | ||
testMarshalJSON(t, cmd) | ||
testMarshalPlist(t, cmd) | ||
} | ||
|
||
func TestEnableLostMode(t *testing.T) { | ||
cmd := EnableLostMode{Message: "Lost!", PhoneNumber: "123-4567", Footnote: "This is lost"} | ||
testMarshalJSON(t, cmd) | ||
testMarshalPlist(t, cmd) | ||
} | ||
|
||
func TestInstallApplication(t *testing.T) { | ||
cmd := InstallApplication{ITunesStoreID: 1234567} | ||
testMarshalJSON(t, cmd) | ||
testMarshalPlist(t, cmd) | ||
} | ||
|
||
func TestApplyRedemptionCode(t *testing.T) { | ||
cmd := ApplyRedemptionCode{Identifier: "id", RedemptionCode: "abcdefg"} | ||
testMarshalJSON(t, cmd) | ||
testMarshalPlist(t, cmd) | ||
} |
Oops, something went wrong.