@@ -3464,11 +3464,13 @@ func testSetVerifiedMacOSProfiles(t *testing.T, ds *Datastore) {
3464
3464
require .NoError (t , err )
3465
3465
cp3 , err := ds .NewMDMAppleConfigProfile (ctx , * configProfileForTest (t , "name3" , "cp3" , "uuid3" ))
3466
3466
require .NoError (t , err )
3467
+ cp4 , err := ds .NewMDMAppleConfigProfile (ctx , * configProfileForTest (t , "name4" , "cp4" , "uuid4" ))
3468
+ require .NoError (t , err )
3467
3469
3468
3470
// list config profiles for no team
3469
3471
cps , err := ds .ListMDMAppleConfigProfiles (ctx , nil )
3470
3472
require .NoError (t , err )
3471
- require .Len (t , cps , 3 )
3473
+ require .Len (t , cps , 4 )
3472
3474
storedByIdentifier := make (map [string ]* fleet.MDMAppleConfigProfile )
3473
3475
for _ , cp := range cps {
3474
3476
storedByIdentifier [cp .Identifier ] = cp
@@ -3484,6 +3486,7 @@ func testSetVerifiedMacOSProfiles(t *testing.T, ds *Datastore) {
3484
3486
cp1 .Identifier : fleet .MDMDeliveryPending ,
3485
3487
cp2 .Identifier : fleet .MDMDeliveryVerifying ,
3486
3488
cp3 .Identifier : fleet .MDMDeliveryVerified ,
3489
+ cp4 .Identifier : fleet .MDMDeliveryPending ,
3487
3490
}
3488
3491
}
3489
3492
@@ -3497,12 +3500,12 @@ func testSetVerifiedMacOSProfiles(t *testing.T, ds *Datastore) {
3497
3500
for _ , h := range hosts {
3498
3501
gotProfs , err := ds .GetHostMDMAppleProfiles (ctx , h .UUID )
3499
3502
require .NoError (t , err )
3500
- require .Len (t , gotProfs , 3 )
3503
+ require .Len (t , gotProfs , 4 )
3501
3504
for _ , p := range gotProfs {
3502
3505
s , ok := expectedHostMDMStatus [h.ID ][p.Identifier ]
3503
3506
require .True (t , ok )
3504
3507
require .NotNil (t , p .Status )
3505
- require .Equal (t , s , * p .Status )
3508
+ require .Equalf (t , s , * p .Status , "profile identifier %s" , p . Identifier )
3506
3509
}
3507
3510
}
3508
3511
}
@@ -3520,23 +3523,13 @@ func testSetVerifiedMacOSProfiles(t *testing.T, ds *Datastore) {
3520
3523
upsertHostCPs (hosts , []* fleet.MDMAppleConfigProfile {storedByIdentifier [cp1 .Identifier ]}, fleet .MDMOperationTypeInstall , & fleet .MDMDeliveryPending , ctx , ds , t )
3521
3524
upsertHostCPs (hosts , []* fleet.MDMAppleConfigProfile {storedByIdentifier [cp2 .Identifier ]}, fleet .MDMOperationTypeInstall , & fleet .MDMDeliveryVerifying , ctx , ds , t )
3522
3525
upsertHostCPs (hosts , []* fleet.MDMAppleConfigProfile {storedByIdentifier [cp3 .Identifier ]}, fleet .MDMOperationTypeInstall , & fleet .MDMDeliveryVerified , ctx , ds , t )
3526
+ upsertHostCPs (hosts , []* fleet.MDMAppleConfigProfile {storedByIdentifier [cp4 .Identifier ]}, fleet .MDMOperationTypeInstall , & fleet .MDMDeliveryPending , ctx , ds , t )
3523
3527
checkHostMDMProfileStatuses ()
3524
3528
3525
3529
// statuses don't change during the grace period if profiles are missing (i.e. not installed)
3526
3530
require .NoError (t , apple_mdm .VerifyHostMDMProfiles (ctx , ds , hosts [0 ], map [string ]* fleet.HostMacOSProfile {}))
3527
3531
checkHostMDMProfileStatuses ()
3528
3532
3529
- // only "verifying" status can change to "verified" so status of cp1 doesn't change (it
3530
- // remains "pending")
3531
- require .NoError (t , apple_mdm .VerifyHostMDMProfiles (ctx , ds , hosts [0 ], map [string ]* fleet.HostMacOSProfile {
3532
- cp1 .Identifier : {
3533
- Identifier : cp1 .Identifier ,
3534
- DisplayName : cp1 .Name ,
3535
- InstallDate : time .Now (),
3536
- },
3537
- }))
3538
- checkHostMDMProfileStatuses ()
3539
-
3540
3533
// if install date is before the updated at timestamp of the profile, statuses don't change
3541
3534
// during the grace period
3542
3535
require .NoError (t , apple_mdm .VerifyHostMDMProfiles (ctx , ds , hosts [1 ], profilesByIdentifier ([]* fleet.HostMacOSProfile {
@@ -3555,17 +3548,17 @@ func testSetVerifiedMacOSProfiles(t *testing.T, ds *Datastore) {
3555
3548
DisplayName : cp3 .Name ,
3556
3549
InstallDate : storedByIdentifier [cp3 .Identifier ].UpdatedAt .Add (- 1 * time .Hour ),
3557
3550
},
3551
+ {
3552
+ Identifier : cp4 .Identifier ,
3553
+ DisplayName : cp4 .Name ,
3554
+ InstallDate : storedByIdentifier [cp4 .Identifier ].UpdatedAt .Add (- 1 * time .Hour ),
3555
+ },
3558
3556
})))
3559
3557
checkHostMDMProfileStatuses ()
3560
3558
3561
- // if install date is on or after the updated at timestamp of the profile, "verifying" status
3562
- // changes to "verified"
3559
+ // if install date is on or after the updated at timestamp of the profile, "verifying" or "pending" status
3560
+ // changes to "verified". Any "pending" profiles not reported are not changed
3563
3561
require .NoError (t , apple_mdm .VerifyHostMDMProfiles (ctx , ds , hosts [2 ], profilesByIdentifier ([]* fleet.HostMacOSProfile {
3564
- {
3565
- Identifier : cp1 .Identifier ,
3566
- DisplayName : cp1 .Name ,
3567
- InstallDate : storedByIdentifier [cp1 .Identifier ].UpdatedAt ,
3568
- },
3569
3562
{
3570
3563
Identifier : cp2 .Identifier ,
3571
3564
DisplayName : cp2 .Name ,
@@ -3576,17 +3569,18 @@ func testSetVerifiedMacOSProfiles(t *testing.T, ds *Datastore) {
3576
3569
DisplayName : cp3 .Name ,
3577
3570
InstallDate : storedByIdentifier [cp3 .Identifier ].UpdatedAt ,
3578
3571
},
3572
+ {
3573
+ Identifier : cp4 .Identifier ,
3574
+ DisplayName : cp4 .Name ,
3575
+ InstallDate : storedByIdentifier [cp4 .Identifier ].UpdatedAt ,
3576
+ },
3579
3577
})))
3580
3578
expectedHostMDMStatus [hosts [2 ].ID ][cp2 .Identifier ] = fleet .MDMDeliveryVerified
3579
+ expectedHostMDMStatus [hosts [2 ].ID ][cp4 .Identifier ] = fleet .MDMDeliveryVerified
3581
3580
checkHostMDMProfileStatuses ()
3582
3581
3583
3582
// repeated call doesn't change statuses
3584
3583
require .NoError (t , apple_mdm .VerifyHostMDMProfiles (ctx , ds , hosts [2 ], profilesByIdentifier ([]* fleet.HostMacOSProfile {
3585
- {
3586
- Identifier : cp1 .Identifier ,
3587
- DisplayName : cp1 .Name ,
3588
- InstallDate : storedByIdentifier [cp1 .Identifier ].UpdatedAt ,
3589
- },
3590
3584
{
3591
3585
Identifier : cp2 .Identifier ,
3592
3586
DisplayName : cp2 .Name ,
@@ -3597,15 +3591,20 @@ func testSetVerifiedMacOSProfiles(t *testing.T, ds *Datastore) {
3597
3591
DisplayName : cp3 .Name ,
3598
3592
InstallDate : storedByIdentifier [cp3 .Identifier ].UpdatedAt ,
3599
3593
},
3594
+ {
3595
+ Identifier : cp4 .Identifier ,
3596
+ DisplayName : cp4 .Name ,
3597
+ InstallDate : storedByIdentifier [cp4 .Identifier ].UpdatedAt ,
3598
+ },
3600
3599
})))
3601
3600
checkHostMDMProfileStatuses ()
3602
3601
3603
3602
// simulate expired grace period by setting updated_at timestamp of profiles back by 24 hours
3604
3603
ExecAdhocSQL (t , ds , func (tx sqlx.ExtContext ) error {
3605
3604
_ , err := tx .ExecContext (ctx ,
3606
- `UPDATE mdm_apple_configuration_profiles SET updated_at = ? WHERE profile_uuid IN(?, ?, ?)` ,
3605
+ `UPDATE mdm_apple_configuration_profiles SET updated_at = ? WHERE profile_uuid IN(?, ?, ?, ? )` ,
3607
3606
time .Now ().Add (- 24 * time .Hour ),
3608
- cp1 .ProfileUUID , cp2 .ProfileUUID , cp3 .ProfileUUID ,
3607
+ cp1 .ProfileUUID , cp2 .ProfileUUID , cp3 .ProfileUUID , cp4 . ProfileUUID ,
3609
3608
)
3610
3609
return err
3611
3610
})
@@ -3623,11 +3622,14 @@ func testSetVerifiedMacOSProfiles(t *testing.T, ds *Datastore) {
3623
3622
InstallDate : time .Now (),
3624
3623
},
3625
3624
})))
3626
- expectedHostMDMStatus [hosts [2 ].ID ][cp3 .Identifier ] = fleet .MDMDeliveryPending // first retry for cp3
3625
+ expectedHostMDMStatus [hosts [2 ].ID ][cp1 .Identifier ] = fleet .MDMDeliveryVerified //cp1 can go from pending to verified
3626
+ expectedHostMDMStatus [hosts [2 ].ID ][cp3 .Identifier ] = fleet .MDMDeliveryPending // first retry for cp3
3627
+ expectedHostMDMStatus [hosts [2 ].ID ][cp4 .Identifier ] = fleet .MDMDeliveryPending // first retry for cp4
3627
3628
checkHostMDMProfileStatuses ()
3628
3629
// simulate retry command acknowledged by setting status to "verifying"
3629
3630
adHocSetVerifying (hosts [2 ].UUID , cp3 .Identifier )
3630
- // report osquery results again with cp3 still missing
3631
+ adHocSetVerifying (hosts [2 ].UUID , cp4 .Identifier )
3632
+ // report osquery results again with cp3 and cp4 still missing
3631
3633
require .NoError (t , apple_mdm .VerifyHostMDMProfiles (ctx , ds , hosts [2 ], profilesByIdentifier ([]* fleet.HostMacOSProfile {
3632
3634
{
3633
3635
Identifier : cp1 .Identifier ,
@@ -3641,6 +3643,7 @@ func testSetVerifiedMacOSProfiles(t *testing.T, ds *Datastore) {
3641
3643
},
3642
3644
})))
3643
3645
expectedHostMDMStatus [hosts [2 ].ID ][cp3 .Identifier ] = fleet .MDMDeliveryFailed // still missing after retry so expect cp3 to fail
3646
+ expectedHostMDMStatus [hosts [2 ].ID ][cp4 .Identifier ] = fleet .MDMDeliveryFailed // still missing after retry so expect cp4 to fail
3644
3647
checkHostMDMProfileStatuses ()
3645
3648
3646
3649
// after the grace period and one retry attempt, status changes to "failed" if a profile is outdated (i.e. installed
@@ -4471,7 +4474,7 @@ func TestMDMAppleProfileVerification(t *testing.T) {
4471
4474
{
4472
4475
name : "PendingThenFoundExpected" ,
4473
4476
initialStatus : fleet .MDMDeliveryPending ,
4474
- expectedStatus : fleet .MDMDeliveryPending , // no change
4477
+ expectedStatus : fleet .MDMDeliveryVerified , // pending can go to verified if found
4475
4478
expectedDetail : "" ,
4476
4479
},
4477
4480
{
@@ -4534,7 +4537,7 @@ func TestMDMAppleProfileVerification(t *testing.T) {
4534
4537
{
4535
4538
name : "PendingThenFoundExpectedAndUnexpected" ,
4536
4539
initialStatus : fleet .MDMDeliveryPending ,
4537
- expectedStatus : fleet .MDMDeliveryPending , // no change
4540
+ expectedStatus : fleet .MDMDeliveryVerified , // profile can go from pending to verified
4538
4541
expectedDetail : "" ,
4539
4542
},
4540
4543
{
0 commit comments