-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
332 lines (246 loc) · 7.33 KB
/
test.py
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#
# test.py
#
# A bunch of code to test jss_tools.py
#
import jss_tools as tools
from random import randrange
jss = tools.Jopen(True)
#
# COMPUTER RECORD
#
# get computer list
computers = jss.Computer()
# get one computer (64 is just a random number)
one_computer = jss.Computer('64')
# test info
info_A = tools.c_info(one_computer)
info_old = one_computer.find('general/serial_number').text
if info_A['serial'] is info_old:
print "c_info: passed"
else:
print "c_info: failed"
# test apps
a_ignore = [
'Activity Monitor',
'AirPort Utility',
'App Store',
'Audio MIDI Setup',
'Automator',
'Boot Camp Assistant',
'Bluetooth File Exchange',
'Calculator',
'Calendar',
'Chess',
'ColorSync Utility',
'Console',
'Contacts',
'Dashboard',
'Dictionary',
'Digital Color Meter',
'Disk Utility',
'DVD Player',
'FaceTime',
'Font Book',
'Grab',
'Grapher',
'iBooks',
]
apps_A = tools.c_apps(one_computer)
apps_B = tools.c_apps(one_computer, a_ignore)
for app in one_computer.findall('software/applications/application'):
nm = app.findtext('name')
if nm is 'Self Service.app':
apps_old_version = app.findtext('version')
if 'Chess' in apps_B:
print "c_apps ignore: failed"
else:
print "c_apps ignore: passed"
if (apps_A['Self Service'] is apps_B['Self Service']
and apps_A['Self Service'] is apps_old_version):
print "c_apps: passed"
else:
print "c_apps: failed"
# test attributes
attrib = tools.c_attributes(one_computer)
attr_test_key = attrib.keys()[0]
for attr in one_computer.findall('extension_attributes/extension_attribute'):
if attr.findtext('name') is attr_test_key:
attr_val = attr.findtext('value')
if attrib[attr_test_key] is attr_val:
print "c_attributes: passed"
else:
print "c_attributes: failed"
# test users
u = tools.c_users(one_computer)
u_name = u[1]['name']
u_uid = u[1]['uid']
for usr in one_computer.find('groups_accounts/local_accounts'):
if usr.findtext('name') is u_name:
old_uid = usr.findtext('uid')
if old_uid is u_uid:
print "c_users: passed"
else:
print "c_users: failed"
# test certificates
c = tools.c_certificates(one_computer)[2]
common = c['common']
c_epoch = c['epoch']
for cert in one_computer.findall('certificates/certificate'):
if cert.findtext('common_name') is common:
old_epoch = cert.findtext('expires_epoch')
if c_epoch is old_epoch:
print "c_certificates: passed"
else:
print "c_certificates: failed"
#
# OTHER RECORD TYPES
#
# test packages
packages = jss.Package()
one_pak = jss.Package(packages[15]['id'])
pak = tools.package(one_pak)
old_name = one_pak.findtext('name')
if old_name is pak['name']:
print "package: passed"
else:
print "package: failed"
# test policies
policies = jss.Policy()
pol_len = len(policies)
one_pol = jss.Policy(policies[randrange(pol_len)]['id'])
pol = tools.policy(one_pol)
old_name = one_pol.findtext('general/name')
if old_name is pol['name']:
print "policy: passed"
else:
print "policy: failed"
while pol['script_count'] is '0':
one_pol = jss.Policy(policies[randrange(pol_len)]['id'])
pol = tools.policy(one_pol)
sc_name = pol['scripts'][0]['name']
sc_priority = pol['scripts'][0]['priority']
for scr in one_pol.findall('scripts/script'):
if scr.findtext('name') is sc_name:
old_priority = scr.findtext('priority')
if old_priority is sc_priority:
print "policy scripts: passed"
else:
print "policy scripts: failed"
while pol['pak_count'] is '0':
one_pol = jss.Policy(policies[randrange(pol_len)]['id'])
pol = tools.policy(one_pol)
pak_name = pol['paks'][0]['name']
pak_id = pol['paks'][0]['id']
for pak in one_pol.findall('package_configuration/packages/package'):
if pak.findtext('name') is pak_name:
old_id = pak.findtext('id')
if old_id is pak_id:
print "policy packages: passed"
else:
print "policy packages: failed"
# test scripts
scripts = jss.Script()
one_script = jss.Script(scripts[2]['id'])
script = tools.script(one_script)
old_name = one_script.findtext('name')
if old_name is script['name']:
print "script: passed"
else:
print "script: failed"
# test computergroups
computergroups = jss.ComputerGroup()
c_group_len = len(computergroups)
one_c_group = jss.ComputerGroup(computergroups[randrange(c_group_len)]['id'])
c_group = tools.computergroup(one_c_group)
old_name = one_c_group.findtext('name')
if old_name is c_group['name']:
print "computergroup: passed"
else:
print "computergroup: failed"
while c_group['crit_count'] is '0':
one_c_group = jss.ComputerGroup(
computergroups[randrange(c_group_len)]['id'])
c_group = tools.computergroup(one_c_group)
cg_name = c_group['criteria'][0]['name']
cg_value = c_group['criteria'][0]['value']
for cg in one_c_group.findall('criteria/criterion'):
if cg.findtext('name') is cg_name:
old_value = cg.findtext('value')
if old_value is cg_value:
print "computergroup criteria: passed"
else:
print "computergroup criteria: failed"
# test categories
categories = jss.Category()
one_cat = jss.Category(categories[5]['id'])
old_priority = one_cat.findtext('priority')
cat = tools.category(one_cat)
if int(old_priority) is cat['priority']:
print "category: passed"
else:
print "category: failed"
# test conversion for each type
bol = 'true'
date = '2017-12-06'
dutc = '2017-12-06T17:32:50.105+1000'
epok = '1512545570105'
intn = '22'
tme = '2017-12-06 17:32:50'
strg = 'a string'
ebol = 'True'
enbl = '1'
tbool = tools.Convert_back(Convert(bol, 'BOOL'), 'BOOL')
tdate = tools.Convert_back(Convert(date, 'DATE'), 'DATE')
tdutc = tools.Convert_back(Convert(dutc, 'DUTC'), 'DUTC')
tepok = tools.Convert_back(Convert(epok, 'EPOK'), 'EPOK')
tintn = tools.Convert_back(Convert(intn, 'INTN'), 'INTN')
ttime = tools.Convert_back(Convert(tme, 'TIME'), 'TIME')
tstrg = tools.Convert_back(Convert(strg, 'STRG'), 'STRG')
tebol = tools.Convert_back(Convert(ebol, 'EBOL'), 'EBOL')
tenbl = tools.Convert_back(Convert(enbl, 'ENBL'), 'ENBL')
if (bol is tbool) & (date is tdate) & (dutc is tdutc):
print "Convert: Passed 1/3"
else:
print "Convert: Failed 1/3"
if (epok is tepok) & (intn is tintn) & (tme is ttime):
print "Convert: Passed 2/3"
else:
print "Convert: Failed 2/3"
if (strg is tstrg) & (ebol is tebol) & (enbl is tenbl):
print "Convert: Passed 3/3"
else:
print "Convert: Failed 3/3"
### iOS side
devices = jss.MobileDevice()
dev = tools.m_devices(devices)
d_name = dev[1]['name']
print "Device List: Passed - ", d_name
device = jss.MobileDevice(1)
info = tools.m_info(device)
if info['managed']:
print "Found managed iOS device"
elif not info['managed']:
print "Found unmanaged iOS device"
else:
print "m_info failed"
keep = info['building']
info['building'] = "TESTING"
tools.m_info_write(info, device)
device = jss.MobileDevice(1)
info = tools.m_info(device)
if info['building'] is "TESTING":
print "m_info_write: Passed"
info['building'] = keep
tools.m_info_write(info, device)
else:
print "m_info_write: Failed"
attr = tools.m_attributes(device)
attr['TESTING'] = {'value': 'Tested', 'type':'STRG'}
tools.m_attributes_write(attr, device)
device = jss.MobileDevice(1)
attr = tools.m_attributes(device)
if attr['TESTING']['value'] = 'Tested':
print "m_attributes_write: Passed"
else:
print "m_attributes_write: Failed"