Skip to content

Commit

Permalink
Fixing up flaky test.
Browse files Browse the repository at this point in the history
  • Loading branch information
getvictor committed Dec 17, 2024
1 parent bfed64d commit e08d457
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions server/datastore/mysql/microsoft_mdm.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ ON DUPLICATE KEY UPDATE
statusCode = *status.Data
if status.Cmd != nil && *status.Cmd == fleet.CmdAtomic {
// The raw MDM command may contain a $FLEET_SECRET_XXX, which should never be exposed or stored unencrypted.
// Note: As of 2024/12/17, on <Add>, <Replace>, and <Exec> commands are exposed to Windows MDM users, so we should not see any secrets in <Atomic> commands. This code is here for future-proofing.
rawCommandStr := string(cmd.RawCommand)
rawCommandWithSecret, err := ds.ExpandEmbeddedSecrets(ctx, rawCommandStr)
if err != nil {
Expand Down
28 changes: 20 additions & 8 deletions server/service/integration_mdm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ func (s *integrationMDMTestSuite) SetupSuite() {
return s.worker.ProcessJobs(ctx)
}),
schedule.WithJob("dep_cooldowns", func(ctx context.Context) error {
if s.skipWorkerJobs {
return nil
}
if s.onIntegrationsScheduleDone != nil {
defer s.onIntegrationsScheduleDone()
}
Expand Down Expand Up @@ -2761,6 +2764,11 @@ func (s *integrationMDMTestSuite) TestEnqueueMDMCommand() {
ctx := context.Background()
t := s.T()

// Skip worker jobs to avoid running into timing issues with this test.
// We can manually run the jobs if needed with s.runWorker().
s.skipWorkerJobs = true
t.Cleanup(func() { s.skipWorkerJobs = false })

// list commands should return all the commands we sent
var listCmdResp0 listMDMAppleCommandsResponse
s.DoJSON("GET", "/api/latest/fleet/mdm/apple/commands", nil, http.StatusOK, &listCmdResp0)
Expand Down Expand Up @@ -2948,13 +2956,18 @@ func (s *integrationMDMTestSuite) TestEnqueueMDMCommand() {
func (s *integrationMDMTestSuite) TestEnqueueMDMCommandWithSecret() {
t := s.T()

// list commands should return all the commands we sent
var listCmdResp0 listMDMAppleCommandsResponse
s.DoJSON("GET", "/api/latest/fleet/mdm/apple/commands", nil, http.StatusOK, &listCmdResp0)
require.Empty(t, listCmdResp0.Results)
// Skip worker jobs to avoid running into timing issues with this test.
// We can manually run the jobs if needed with s.runWorker().
s.skipWorkerJobs = true
t.Cleanup(func() { s.skipWorkerJobs = false })

_, mdmClient := createHostThenEnrollMDM(s.ds, s.server.URL, t)

// list commands should return all the commands we sent
var listCmdResp listMDMAppleCommandsResponse
s.DoJSON("GET", "/api/latest/fleet/mdm/apple/commands", nil, http.StatusOK, &listCmdResp, "host_identifier", mdmClient.UUID)
require.Empty(t, listCmdResp.Results)

base64Cmd := func(rawCmd string) string {
return base64.RawStdEncoding.EncodeToString([]byte(rawCmd))
}
Expand Down Expand Up @@ -3007,10 +3020,9 @@ func (s *integrationMDMTestSuite) TestEnqueueMDMCommandWithSecret() {
require.Empty(t, resp.FailedUUIDs)
require.Equal(t, "ProfileList", resp.RequestType)

// the command exists but no results yet
var getMDMCmdResp getMDMCommandResultsResponse
s.DoJSON("GET", "/api/latest/fleet/commands/results", nil, http.StatusOK, &getMDMCmdResp, "command_uuid", uuid2)
require.Len(t, getMDMCmdResp.Results, 0)
// 1 command queued up
s.DoJSON("GET", "/api/latest/fleet/mdm/apple/commands", nil, http.StatusOK, &listCmdResp, "host_identifier", mdmClient.UUID)
require.Len(t, listCmdResp.Results, 1)

cmd, err := mdmClient.Idle()
require.NoError(t, err)
Expand Down

0 comments on commit e08d457

Please sign in to comment.