@@ -121,12 +121,33 @@ func (s *integrationMDMTestSuite) TestDEPEnrollReleaseDeviceGlobal() {
121
121
122
122
s .enableABM ("fleet_ade_test" )
123
123
124
+ // add a setup experience script to run for no team
125
+ extraArgs := make (map [string ][]string )
126
+ body , headers := generateNewScriptMultipartRequest (t ,
127
+ "script.sh" , []byte (`echo "hello"` ), s .token , extraArgs )
128
+ s .DoRawWithHeaders ("POST" , "/api/latest/fleet/setup_experience/script" , body .Bytes (), http .StatusOK , headers )
129
+
130
+ // test manual and automatic release with the new setup experience flow
131
+ for _ , enableReleaseManually := range []bool {false , true } {
132
+ t .Run (fmt .Sprintf ("enableReleaseManually=%t;new_flow" , enableReleaseManually ), func (t * testing.T ) {
133
+ s .runDEPEnrollReleaseDeviceTest (t , globalDevice , enableReleaseManually , nil , "I1" , false )
134
+ })
135
+ }
124
136
// test manual and automatic release with the old worker flow
125
137
for _ , enableReleaseManually := range []bool {false , true } {
126
- t .Run (fmt .Sprintf ("enableReleaseManually=%t" , enableReleaseManually ), func (t * testing.T ) {
138
+ t .Run (fmt .Sprintf ("enableReleaseManually=%t;old_flow " , enableReleaseManually ), func (t * testing.T ) {
127
139
s .runDEPEnrollReleaseDeviceTest (t , globalDevice , enableReleaseManually , nil , "I1" , true )
128
140
})
129
141
}
142
+
143
+ // remove the setup experience script, run the new setup experience flow when
144
+ // there is no setup experience item to process (so it is bypassed)
145
+ s .Do ("DELETE" , "/api/latest/fleet/setup_experience/script" , nil , http .StatusOK )
146
+ for _ , enableReleaseManually := range []bool {false , true } {
147
+ t .Run (fmt .Sprintf ("enableReleaseManually=%t;bypass_flow" , enableReleaseManually ), func (t * testing.T ) {
148
+ s .runDEPEnrollReleaseDeviceTest (t , globalDevice , enableReleaseManually , nil , "I1" , false )
149
+ })
150
+ }
130
151
}
131
152
132
153
func (s * integrationMDMTestSuite ) TestDEPEnrollReleaseDeviceTeam () {
@@ -211,12 +232,35 @@ func (s *integrationMDMTestSuite) TestDEPEnrollReleaseDeviceTeam() {
211
232
// enable FileVault
212
233
s .Do ("PATCH" , "/api/latest/fleet/mdm/apple/settings" , json .RawMessage ([]byte (fmt .Sprintf (`{"enable_disk_encryption":true,"team_id":%d}` , tm .ID ))), http .StatusNoContent )
213
234
235
+ // add a setup experience script to run for this team
236
+ extraArgs := map [string ][]string {
237
+ "team_id" : {fmt .Sprintf ("%d" , tm .ID )},
238
+ }
239
+ body , headers := generateNewScriptMultipartRequest (t ,
240
+ "script.sh" , []byte (`echo "hello"` ), s .token , extraArgs )
241
+ s .DoRawWithHeaders ("POST" , "/api/latest/fleet/setup_experience/script" , body .Bytes (), http .StatusOK , headers )
242
+
243
+ // test manual and automatic release with the new setup experience flow
244
+ for _ , enableReleaseManually := range []bool {false , true } {
245
+ t .Run (fmt .Sprintf ("enableReleaseManually=%t;new_flow" , enableReleaseManually ), func (t * testing.T ) {
246
+ s .runDEPEnrollReleaseDeviceTest (t , teamDevice , enableReleaseManually , & tm .ID , "I2" , false )
247
+ })
248
+ }
214
249
// test manual and automatic release with the old worker flow
215
250
for _ , enableReleaseManually := range []bool {false , true } {
216
- t .Run (fmt .Sprintf ("enableReleaseManually=%t" , enableReleaseManually ), func (t * testing.T ) {
251
+ t .Run (fmt .Sprintf ("enableReleaseManually=%t;old_flow " , enableReleaseManually ), func (t * testing.T ) {
217
252
s .runDEPEnrollReleaseDeviceTest (t , teamDevice , enableReleaseManually , & tm .ID , "I2" , true )
218
253
})
219
254
}
255
+
256
+ // remove the setup experience script, run the new setup experience flow when
257
+ // there is no setup experience item to process (so it is bypassed)
258
+ s .Do ("DELETE" , "/api/latest/fleet/setup_experience/script" , nil , http .StatusOK , "team_id" , fmt .Sprint (tm .ID ))
259
+ for _ , enableReleaseManually := range []bool {false , true } {
260
+ t .Run (fmt .Sprintf ("enableReleaseManually=%t;bypass_flow" , enableReleaseManually ), func (t * testing.T ) {
261
+ s .runDEPEnrollReleaseDeviceTest (t , teamDevice , enableReleaseManually , & tm .ID , "I2" , false )
262
+ })
263
+ }
220
264
}
221
265
222
266
func (s * integrationMDMTestSuite ) TestDEPEnrollReleaseIphoneTeam () {
@@ -286,6 +330,11 @@ func (s *integrationMDMTestSuite) TestDEPEnrollReleaseIphoneTeam() {
286
330
func (s * integrationMDMTestSuite ) runDEPEnrollReleaseDeviceTest (t * testing.T , device godep.Device , enableReleaseManually bool , teamID * uint , customProfileIdent string , useOldFleetdFlow bool ) {
287
331
ctx := context .Background ()
288
332
333
+ var isIphone bool
334
+ if device .DeviceFamily == "iPhone" {
335
+ isIphone = true
336
+ }
337
+
289
338
// set the enable release device manually option
290
339
payload := map [string ]any {
291
340
"enable_release_device_manually" : enableReleaseManually ,
@@ -359,15 +408,22 @@ func (s *integrationMDMTestSuite) runDEPEnrollReleaseDeviceTest(t *testing.T, de
359
408
// enroll the host
360
409
depURLToken := loadEnrollmentProfileDEPToken (t , s .ds )
361
410
mdmDevice := mdmtest .NewTestMDMClientAppleDEP (s .server .URL , depURLToken )
362
- var isIphone bool
363
- if device .DeviceFamily == "iPhone" {
411
+ if isIphone {
364
412
mdmDevice .Model = "iPhone 14,6"
365
- isIphone = true
366
413
}
367
414
mdmDevice .SerialNumber = device .SerialNumber
368
415
err := mdmDevice .Enroll ()
369
416
require .NoError (t , err )
370
417
418
+ // check if it has setup experience items or not
419
+ hasSetupExpItems := true
420
+ _ , err = s .ds .GetHostAwaitingConfiguration (ctx , mdmDevice .UUID )
421
+ if fleet .IsNotFound (err ) {
422
+ hasSetupExpItems = false
423
+ } else if err != nil {
424
+ require .NoError (t , err )
425
+ }
426
+
371
427
// run the worker to process the DEP enroll request
372
428
s .runWorker ()
373
429
// run the cron to assign configuration profiles
@@ -525,8 +581,13 @@ func (s *integrationMDMTestSuite) runDEPEnrollReleaseDeviceTest(t *testing.T, de
525
581
b , err := io .ReadAll (res .Body )
526
582
require .NoError (t , err )
527
583
require .NoError (t , json .Unmarshal (b , & orbitConfigResp ))
528
- // should be notified of the setup experience flow
529
- require .False (t , orbitConfigResp .Notifications .RunSetupExperience )
584
+ if hasSetupExpItems {
585
+ // should be notified of the setup experience flow
586
+ require .True (t , orbitConfigResp .Notifications .RunSetupExperience )
587
+ } else {
588
+ // should bypass the setup experience flow
589
+ require .False (t , orbitConfigResp .Notifications .RunSetupExperience )
590
+ }
530
591
531
592
if enableReleaseManually {
532
593
// get the worker's pending job from the future, there should not be any
@@ -537,7 +598,7 @@ func (s *integrationMDMTestSuite) runDEPEnrollReleaseDeviceTest(t *testing.T, de
537
598
return
538
599
}
539
600
540
- if useOldFleetdFlow {
601
+ if useOldFleetdFlow || ! hasSetupExpItems {
541
602
// there should be a Release Device pending job
542
603
pending , err := s .ds .GetQueuedJobs (ctx , 2 , time .Now ().UTC ().Add (time .Minute ))
543
604
require .NoError (t , err )
@@ -574,6 +635,12 @@ func (s *integrationMDMTestSuite) runDEPEnrollReleaseDeviceTest(t *testing.T, de
574
635
require .NoError (t , err )
575
636
require .Len (t , pending , 0 )
576
637
638
+ // mark the setup experience script as done
639
+ mysql .ExecAdhocSQL (t , s .ds , func (q sqlx.ExtContext ) error {
640
+ _ , err := q .ExecContext (ctx , `UPDATE setup_experience_status_results SET status = 'success' WHERE host_uuid = ?` , mdmDevice .UUID )
641
+ return err
642
+ })
643
+
577
644
// call the /status endpoint to automatically release the host
578
645
var statusResp getOrbitSetupExperienceStatusResponse
579
646
s .DoJSON ("POST" , "/api/fleet/orbit/setup_experience/status" , json .RawMessage (fmt .Sprintf (`{"orbit_node_key": %q}` , * enrolledHost .OrbitNodeKey )), http .StatusOK , & statusResp )
0 commit comments