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
/
Copy pathresponse_test.go
142 lines (112 loc) · 2.99 KB
/
response_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package mdm
import (
"fmt"
"github.com/groob/plist"
"github.com/micromdm/mdm/test"
"io/ioutil"
"testing"
)
func TestQueryResponseMac(t *testing.T) {
response := &Response{}
plistBuf := []byte(test.OSXElCapQueryResponses)
err := plist.Unmarshal(plistBuf, response)
if err != nil {
t.Fatal(err)
}
}
func TestQueryResponseIpadIOS8(t *testing.T) {
response := &Response{}
plistBuf := []byte(test.IOS8IpadQueryResponses)
err := plist.Unmarshal(plistBuf, response)
if err != nil {
t.Fatal(err)
}
}
func TestQueryResponseIphoneIOS8(t *testing.T) {
response := &Response{}
plistBuf := []byte(test.IOS8IphoneQueryResponses)
err := plist.Unmarshal(plistBuf, response)
if err != nil {
t.Fatal(err)
}
}
func TestSecurityInfoMac(t *testing.T) {
response := &Response{}
plistBuf := []byte(test.OSXElCapSecurityInfoNoFDE)
err := plist.Unmarshal(plistBuf, response)
if err != nil {
t.Fatal(err)
}
}
func TestSecurityInfoIpadIOS8(t *testing.T) {
response := &Response{}
plistBuf := []byte(test.IOS8IpadSecurityInfo)
err := plist.Unmarshal(plistBuf, response)
if err != nil {
t.Fatal(err)
}
}
func TestErrorChain(t *testing.T) {
errorResponseBody, err := ioutil.ReadFile("./test/responses/error_invalidreq.plist")
if err != nil {
t.Fatal(err)
}
response := &Response{}
if err := plist.Unmarshal(errorResponseBody, response); err != nil {
t.Fatal(err)
}
if response.Status != "Error" {
t.Fatal("Response status was not `Error`.")
}
if response.ErrorChain == nil {
t.Fatal("Response did not contain expected error chain struct")
}
for _, v := range response.ErrorChain {
if v.ErrorCode == 0 {
t.Fatal("Error response did not contain ErrorCode")
}
if v.ErrorDomain == "" {
t.Fatal("Error response did not contain ErrorDomain")
}
if v.LocalizedDescription == "" {
t.Fatal("Error response did not contain localized description")
}
if v.USEnglishDescription == "" {
t.Fatal("Error response did not contain english description")
}
}
}
func TestInstalledApplicationListResponse(t *testing.T) {
appListResponseBody, err := ioutil.ReadFile("./test/responses/installed_application_list.plist")
if err != nil {
t.Fatal(err)
}
response := &Response{}
if err := plist.Unmarshal(appListResponseBody, response); err != nil {
t.Fatal(err)
}
if response.Status != "Acknowledged" {
t.Fatal("Response status was not `Acknowledged`.")
}
if response.InstalledApplicationList == nil {
t.Fatal("No installed application list in response")
}
fmt.Printf("%v\n", response)
}
func TestProfileListResponse(t *testing.T) {
profileListResponseBody, err := ioutil.ReadFile("./test/responses/profilelist.plist")
if err != nil {
t.Fatal(err)
}
response := &Response{}
if err := plist.Unmarshal(profileListResponseBody, response); err != nil {
t.Fatal(err)
}
if response.Status != "Acknowledged" {
t.Errorf("Response status was not `Acknowledged`.")
}
if response.ProfileList == nil {
t.Errorf("No ProfileList in response")
}
fmt.Printf("%v\n", response)
}