From a2d246d64ef2377499e5a98649da68d292a43fd0 Mon Sep 17 00:00:00 2001 From: Jahziel Villasana-Espinoza Date: Thu, 19 Sep 2024 17:57:56 -0400 Subject: [PATCH 01/11] fix: sentence case --- .../VppPage/components/VppTable/TeamsCell/TeamsCell.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/pages/admin/IntegrationsPage/cards/MdmSettings/VppPage/components/VppTable/TeamsCell/TeamsCell.tsx b/frontend/pages/admin/IntegrationsPage/cards/MdmSettings/VppPage/components/VppTable/TeamsCell/TeamsCell.tsx index 57a21e7e48b1..570d7af8ed0f 100644 --- a/frontend/pages/admin/IntegrationsPage/cards/MdmSettings/VppPage/components/VppTable/TeamsCell/TeamsCell.tsx +++ b/frontend/pages/admin/IntegrationsPage/cards/MdmSettings/VppPage/components/VppTable/TeamsCell/TeamsCell.tsx @@ -17,7 +17,7 @@ const generateCell = (teams: ITokenTeam[] | null) => { } if (teams.length === 0) { - return ; + return ; } let text = ""; @@ -83,7 +83,7 @@ const TeamsCell = ({ teams, className }: ITeamsCellProps) => { } if (teams.length === 0) { - return ; + return ; } if (teams.length === 1) { From 6f06ad835740e795f37648f034ceed7619f0afb2 Mon Sep 17 00:00:00 2001 From: Jahziel Villasana-Espinoza Date: Mon, 23 Sep 2024 18:26:35 -0400 Subject: [PATCH 02/11] fix: reset teams --- server/service/appconfig.go | 44 ++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/server/service/appconfig.go b/server/service/appconfig.go index 17b83dcbbfa1..a2deca2b3235 100644 --- a/server/service/appconfig.go +++ b/server/service/appconfig.go @@ -545,15 +545,57 @@ func (svc *Service) ModifyAppConfig(ctx context.Context, p []byte, applyOpts fle } } + // Reset teams for ABM tokens that exist in Fleet but aren't present in the config being passed + tokensInCfg := make(map[string]struct{}) + for _, t := range newAppConfig.MDM.AppleBusinessManager.Value { + tokensInCfg[t.OrganizationName] = struct{}{} + } + + toks, err := svc.ds.ListABMTokens(ctx) + if err != nil { + return nil, ctxerr.Wrap(ctx, err, "listing ABM tokens") + } + for _, tok := range toks { + if _, ok := tokensInCfg[tok.OrganizationName]; !ok { + tok.MacOSDefaultTeamID = nil + tok.IOSDefaultTeamID = nil + tok.IPadOSDefaultTeamID = nil + if err := svc.ds.SaveABMToken(ctx, tok); err != nil { + return nil, ctxerr.Wrap(ctx, err, "saving ABM token assignments") + } + } + } + if (appConfig.MDM.AppleBusinessManager.Set && appConfig.MDM.AppleBusinessManager.Valid) || appConfig.MDM.DeprecatedAppleBMDefaultTeam != "" { for _, tok := range abmAssignments { - fmt.Println(tok.EncryptedToken) if err := svc.ds.SaveABMToken(ctx, tok); err != nil { return nil, ctxerr.Wrap(ctx, err, "saving ABM token assignments") } } } + // Reset teams for VPP tokens that exist in Fleet but aren't present in the config being passed + for k := range tokensInCfg { + delete(tokensInCfg, k) + } + + for _, t := range newAppConfig.MDM.VolumePurchasingProgram.Value { + tokensInCfg[t.Location] = struct{}{} + } + + vppToks, err := svc.ds.ListVPPTokens(ctx) + if err != nil { + return nil, ctxerr.Wrap(ctx, err, "listing VPP tokens") + } + for _, tok := range vppToks { + if _, ok := tokensInCfg[tok.Location]; !ok { + tok.Teams = nil + if _, err := svc.ds.UpdateVPPTokenTeams(ctx, tok.ID, nil); err != nil { + return nil, ctxerr.Wrap(ctx, err, "saving VPP token teams") + } + } + } + if appConfig.MDM.VolumePurchasingProgram.Set && appConfig.MDM.VolumePurchasingProgram.Valid { for tokenID, tokenTeams := range vppAssignments { if _, err := svc.ds.UpdateVPPTokenTeams(ctx, tokenID, tokenTeams); err != nil { From 11f7a2882097c5b4673da799bd077de5295ee5f0 Mon Sep 17 00:00:00 2001 From: Jahziel Villasana-Espinoza Date: Mon, 23 Sep 2024 18:39:56 -0400 Subject: [PATCH 03/11] chore: update tests --- server/service/integration_mdm_test.go | 47 +++++++++++++++++++++----- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/server/service/integration_mdm_test.go b/server/service/integration_mdm_test.go index ce134a2bd5fe..6eee1327bb2b 100644 --- a/server/service/integration_mdm_test.go +++ b/server/service/integration_mdm_test.go @@ -879,6 +879,26 @@ func (s *integrationMDMTestSuite) TestAppleGetAppleMDM() { require.Equal(t, tm.Name, tok.MacOSTeam.Name) require.Equal(t, tm.Name, tok.IOSTeam.Name) require.Equal(t, tm.Name, tok.IPadOSTeam.Name) + + // Reset the teams via app config + acResp = appConfigResponse{} + s.DoJSON("PATCH", "/api/latest/fleet/config", json.RawMessage(`{ + "mdm": { + "apple_business_manager": [] + } + }`), http.StatusOK, &acResp) + + tokensResp = listABMTokensResponse{} + s.DoJSON("GET", "/api/latest/fleet/abm_tokens", nil, http.StatusOK, &tokensResp) + tok = s.getABMTokenByName(tmOrgName, tokensResp.Tokens) + require.NotNil(t, tok) + require.False(t, tok.TermsExpired) + require.Equal(t, "abc", tok.AppleID) + require.Equal(t, tmOrgName, tok.OrganizationName) + require.Equal(t, s.server.URL+"/mdm/apple/mdm", tok.MDMServerURL) + require.Equal(t, fleet.TeamNameNoTeam, tok.MacOSTeam.Name) + require.Equal(t, fleet.TeamNameNoTeam, tok.IOSTeam.Name) + require.Equal(t, fleet.TeamNameNoTeam, tok.IPadOSTeam.Name) } func (s *integrationMDMTestSuite) getABMTokenByName(orgName string, tokens []*fleet.ABMToken) *fleet.ABMToken { @@ -10532,6 +10552,25 @@ func (s *integrationMDMTestSuite) TestVPPApps() { var resPatchVPP patchVPPTokensTeamsResponse s.DoJSON("PATCH", fmt.Sprintf("/api/latest/fleet/vpp_tokens/%d/teams", resp.Tokens[0].ID), patchVPPTokensTeamsRequest{TeamIDs: []uint{}}, http.StatusOK, &resPatchVPP) + // Reset the token's teams by omitting the token from app config + acResp := appConfigResponse{} + s.DoJSON("PATCH", "/api/latest/fleet/config", json.RawMessage(`{ + "mdm": { "volume_purchasing_program": null } + }`), http.StatusOK, &acResp) + + resp = getVPPTokensResponse{} + s.DoJSON("GET", "/api/latest/fleet/vpp_tokens", &getVPPTokensRequest{}, http.StatusOK, &resp) + require.NoError(t, resp.Err) + require.Len(t, resp.Tokens, 1) + require.Equal(t, orgName, resp.Tokens[0].OrgName) + require.Equal(t, location, resp.Tokens[0].Location) + require.Equal(t, expTime, resp.Tokens[0].RenewDate) + require.Empty(t, resp.Tokens[0].Teams) + + // Add the team back + resPatchVPP = patchVPPTokensTeamsResponse{} + s.DoJSON("PATCH", fmt.Sprintf("/api/latest/fleet/vpp_tokens/%d/teams", resp.Tokens[0].ID), patchVPPTokensTeamsRequest{TeamIDs: []uint{}}, http.StatusOK, &resPatchVPP) + // Get list of VPP apps from "Apple" // We're passing team 1 here, but we haven't added any app store apps to that team, so we get // back all available apps in our VPP location. @@ -10801,14 +10840,6 @@ func (s *integrationMDMTestSuite) TestVPPApps() { s.DoJSON("PATCH", fmt.Sprintf("/api/latest/fleet/vpp_tokens/%d/teams", vppRes.Token.ID), patchVPPTokensTeamsRequest{TeamIDs: []uint{team.ID}}, http.StatusOK, &resPatchVPP) - // mysql.ExecAdhocSQL(t, s.ds, func(q sqlx.ExtContext) error { - // _, err := q.ExecContext(context.Background(), "UPDATE vpp_tokens SET renew_at = ? WHERE organization_name = ?", time.Now().Add(-1*time.Hour), "badtoken") - // return err - // }) - - // r := s.Do("POST", fmt.Sprintf("/api/latest/fleet/hosts/%d/software/install/%d", mdmHost.ID, errTitleID), &installSoftwareRequest{}, http.StatusUnprocessableEntity) - // require.Contains(t, extractServerErrorText(r.Body), "VPP token expired") - // Disable the token s.DoJSON("PATCH", fmt.Sprintf("/api/latest/fleet/vpp_tokens/%d/teams", vppRes.Token.ID), patchVPPTokensTeamsRequest{}, http.StatusOK, &resPatchVPP) From 4e4aa50152c2a0cd134362d80d119f4caed209d7 Mon Sep 17 00:00:00 2001 From: Jahziel Villasana-Espinoza Date: Mon, 23 Sep 2024 18:41:47 -0400 Subject: [PATCH 04/11] chore: changes file --- changes/22198-defaults | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changes/22198-defaults diff --git a/changes/22198-defaults b/changes/22198-defaults new file mode 100644 index 000000000000..a8db9479f518 --- /dev/null +++ b/changes/22198-defaults @@ -0,0 +1,2 @@ +- Fixes a bug where removing a VPP or ABM token from a GitOps YAML file would leave the tema + assignments unchanged. \ No newline at end of file From 09789570cc4d7301de9cf4e2ce9d72015084a059 Mon Sep 17 00:00:00 2001 From: Jahziel Villasana-Espinoza Date: Tue, 24 Sep 2024 16:42:16 -0400 Subject: [PATCH 05/11] chore: feedback --- changes/22198-defaults | 2 +- server/service/appconfig.go | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/changes/22198-defaults b/changes/22198-defaults index a8db9479f518..ec243e9a48e4 100644 --- a/changes/22198-defaults +++ b/changes/22198-defaults @@ -1,2 +1,2 @@ -- Fixes a bug where removing a VPP or ABM token from a GitOps YAML file would leave the tema +- Fixes a bug where removing a VPP or ABM token from a GitOps YAML file would leave the team assignments unchanged. \ No newline at end of file diff --git a/server/service/appconfig.go b/server/service/appconfig.go index a2deca2b3235..22998d24d601 100644 --- a/server/service/appconfig.go +++ b/server/service/appconfig.go @@ -575,9 +575,7 @@ func (svc *Service) ModifyAppConfig(ctx context.Context, p []byte, applyOpts fle } // Reset teams for VPP tokens that exist in Fleet but aren't present in the config being passed - for k := range tokensInCfg { - delete(tokensInCfg, k) - } + clear(tokensInCfg) for _, t := range newAppConfig.MDM.VolumePurchasingProgram.Value { tokensInCfg[t.Location] = struct{}{} From 41ce6f2bed09ce8ef2ed8c23ac65de4bf3ffcbe4 Mon Sep 17 00:00:00 2001 From: Jahziel Villasana-Espinoza Date: Tue, 24 Sep 2024 17:41:03 -0400 Subject: [PATCH 06/11] fix: lots of tests --- cmd/fleetctl/apply_test.go | 79 +++++++++++++++++++++++++++++++ cmd/fleetctl/gitops_test.go | 80 ++++++++++++++++++++++++++++++++ server/service/appconfig_test.go | 12 +++++ 3 files changed, 171 insertions(+) diff --git a/cmd/fleetctl/apply_test.go b/cmd/fleetctl/apply_test.go index f35b39dc84f1..44ad1595a333 100644 --- a/cmd/fleetctl/apply_test.go +++ b/cmd/fleetctl/apply_test.go @@ -782,6 +782,18 @@ func TestApplyAppConfigDryRunIssue(t *testing.T) { return nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + // first, set the default app config's agent options as set after fleetctl setup name := writeTmpYml(t, `--- apiVersion: v1 @@ -914,6 +926,18 @@ func TestApplyAppConfigDeprecatedFields(t *testing.T) { return nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + name := writeTmpYml(t, `--- apiVersion: v1 kind: config @@ -1316,6 +1340,14 @@ func TestApplyAsGitOps(t *testing.T) { return []*fleet.ABMToken{{ID: 1}}, nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + // Apply global config. name := writeTmpYml(t, `--- apiVersion: v1 @@ -1873,6 +1905,18 @@ func TestCanApplyIntervalsInNanoseconds(t *testing.T) { return nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + name := writeTmpYml(t, `--- apiVersion: v1 kind: config @@ -1908,6 +1952,18 @@ func TestCanApplyIntervalsUsingDurations(t *testing.T) { return nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + name := writeTmpYml(t, `--- apiVersion: v1 kind: config @@ -2091,6 +2147,18 @@ func TestApplyMacosSetup(t *testing.T) { return []*fleet.ABMToken{{ID: 1}}, nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + return ds } @@ -2764,6 +2832,17 @@ func TestApplySpecs(t *testing.T) { ds.DeleteMDMWindowsConfigProfileByTeamAndNameFunc = func(ctx context.Context, teamID *uint, profileName string) error { return nil } + + // VPP/AMB + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } } cases := []struct { diff --git a/cmd/fleetctl/gitops_test.go b/cmd/fleetctl/gitops_test.go index 64cb9fda19cc..6f50371facdb 100644 --- a/cmd/fleetctl/gitops_test.go +++ b/cmd/fleetctl/gitops_test.go @@ -82,6 +82,18 @@ func TestGitOpsBasicGlobalFree(t *testing.T) { return nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + tmpFile, err := os.CreateTemp(t.TempDir(), "*.yml") require.NoError(t, err) @@ -233,6 +245,18 @@ func TestGitOpsBasicGlobalPremium(t *testing.T) { return nil, nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + tmpFile, err := os.CreateTemp(t.TempDir(), "*.yml") require.NoError(t, err) @@ -582,6 +606,17 @@ func TestGitOpsFullGlobal(t *testing.T) { return nil } + // Needed for checking tokens + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + const ( fleetServerURL = "https://fleet.example.com" orgName = "GitOps Test" @@ -1062,6 +1097,18 @@ func TestGitOpsBasicGlobalAndTeam(t *testing.T) { return nil, 0, nil, nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + globalFile, err := os.CreateTemp(t.TempDir(), "*.yml") require.NoError(t, err) @@ -1324,6 +1371,18 @@ func TestGitOpsBasicGlobalAndNoTeam(t *testing.T) { return nil, 0, nil, nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + globalFileBasic, err := os.CreateTemp(t.TempDir(), "*.yml") require.NoError(t, err) @@ -1583,6 +1642,18 @@ func TestGitOpsFullGlobalAndTeam(t *testing.T) { return team, nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + apnsCert, apnsKey, err := mysql.GenerateTestCertBytes() require.NoError(t, err) crt, key, err := apple_mdm.NewSCEPCACertKey() @@ -2206,6 +2277,15 @@ func setupFullGitOpsPremiumServer(t *testing.T) (*mock.Store, **fleet.AppConfig, ds.ListSoftwareTitlesFunc = func(ctx context.Context, opt fleet.SoftwareTitleListOptions, tmFilter fleet.TeamFilter) ([]fleet.SoftwareTitleListResult, int, *fleet.PaginationMetadata, error) { return nil, 0, nil, nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } t.Setenv("FLEET_SERVER_URL", fleetServerURL) t.Setenv("ORG_NAME", orgName) diff --git a/server/service/appconfig_test.go b/server/service/appconfig_test.go index 0fb0d318d26f..5ed30d235db1 100644 --- a/server/service/appconfig_test.go +++ b/server/service/appconfig_test.go @@ -51,6 +51,18 @@ func TestAppConfigAuth(t *testing.T) { return nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + testCases := []struct { name string user *fleet.User From a0058763d54c004be9130cc943e943aa1d9cc47c Mon Sep 17 00:00:00 2001 From: Jahziel Villasana-Espinoza Date: Tue, 24 Sep 2024 18:01:00 -0400 Subject: [PATCH 07/11] chore: more test fixes --- cmd/fleetctl/apply_test.go | 12 ++++++++++++ server/service/appconfig_test.go | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/cmd/fleetctl/apply_test.go b/cmd/fleetctl/apply_test.go index 44ad1595a333..e96f95cebb6a 100644 --- a/cmd/fleetctl/apply_test.go +++ b/cmd/fleetctl/apply_test.go @@ -657,6 +657,18 @@ func TestApplyAppConfig(t *testing.T) { return []*fleet.TeamSummary{{Name: "team1", ID: 1}}, nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + name := writeTmpYml(t, `--- apiVersion: v1 kind: config diff --git a/server/service/appconfig_test.go b/server/service/appconfig_test.go index 5ed30d235db1..1f870a2c9ba4 100644 --- a/server/service/appconfig_test.go +++ b/server/service/appconfig_test.go @@ -659,6 +659,18 @@ func TestModifyAppConfigSMTPConfigured(t *testing.T) { return nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + // Disable SMTP. newAppConfig := fleet.AppConfig{ SMTPSettings: &fleet.SMTPSettings{ From 88684db8584fd51dc7a8c4968c6e09e6ce719923 Mon Sep 17 00:00:00 2001 From: Jahziel Villasana-Espinoza Date: Tue, 24 Sep 2024 18:28:38 -0400 Subject: [PATCH 08/11] chore: more test fixes --- cmd/fleetctl/apply_test.go | 2 +- server/service/appconfig_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/fleetctl/apply_test.go b/cmd/fleetctl/apply_test.go index e96f95cebb6a..bd80bb84347c 100644 --- a/cmd/fleetctl/apply_test.go +++ b/cmd/fleetctl/apply_test.go @@ -666,7 +666,7 @@ func TestApplyAppConfig(t *testing.T) { } ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { - return []*fleet.ABMToken{}, nil + return []*fleet.ABMToken{{OrganizationName: t.Name()}}, nil } name := writeTmpYml(t, `--- diff --git a/server/service/appconfig_test.go b/server/service/appconfig_test.go index 1f870a2c9ba4..bd303cd6cfc1 100644 --- a/server/service/appconfig_test.go +++ b/server/service/appconfig_test.go @@ -775,6 +775,18 @@ func TestTransparencyURL(t *testing.T) { return nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + ac, err := svc.AppConfigObfuscated(ctx) require.NoError(t, err) require.Equal(t, tt.initialURL, ac.FleetDesktop.TransparencyURL) From 9ea5578b9cc22d04cfa6cc6fcb9c1e14858a61d0 Mon Sep 17 00:00:00 2001 From: Jahziel Villasana-Espinoza Date: Tue, 24 Sep 2024 19:09:11 -0400 Subject: [PATCH 09/11] fix: tests --- server/service/appconfig_test.go | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/server/service/appconfig_test.go b/server/service/appconfig_test.go index bd303cd6cfc1..2c6e6bc10849 100644 --- a/server/service/appconfig_test.go +++ b/server/service/appconfig_test.go @@ -836,6 +836,18 @@ func TestTransparencyURLDowngradeLicense(t *testing.T) { return nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + ac, err := svc.AppConfigObfuscated(ctx) require.NoError(t, err) require.Equal(t, "https://example.com/transparency", ac.FleetDesktop.TransparencyURL) @@ -1126,6 +1138,15 @@ func TestMDMAppleConfig(t *testing.T) { depStorage.StoreAssignerProfileFunc = func(ctx context.Context, name string, profileUUID string) error { return nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{{OrganizationName: t.Name()}}, nil + } ac, err := svc.AppConfigObfuscated(ctx) require.NoError(t, err) @@ -1204,6 +1225,15 @@ func TestModifyAppConfigSMTPSSOAgentOptions(t *testing.T) { ) error { return nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } // Not sending smtp_settings, sso_settings or agent_settings will do nothing. b := []byte(`{}`) @@ -1333,6 +1363,18 @@ func TestModifyEnableAnalytics(t *testing.T) { return nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + ac, err := svc.AppConfigObfuscated(ctx) require.NoError(t, err) require.Equal(t, tt.initialEnabled, ac.ServerSettings.EnableAnalytics) From 74da8ffceae1dff9e44ddbe9562ce0822094a599 Mon Sep 17 00:00:00 2001 From: Jahziel Villasana-Espinoza Date: Tue, 24 Sep 2024 19:33:36 -0400 Subject: [PATCH 10/11] fix: tests --- server/service/mail_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/service/mail_test.go b/server/service/mail_test.go index be041e7e6ec6..c83168301cac 100644 --- a/server/service/mail_test.go +++ b/server/service/mail_test.go @@ -86,6 +86,18 @@ func TestMailService(t *testing.T) { return invite, nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + ctx = test.UserContext(ctx, test.UserAdmin) // (1) Modifying the app config `sender_address` field to trigger a test e-mail send. From 7029ac90373ff07a226f5b8006741f5520c99337 Mon Sep 17 00:00:00 2001 From: Jahziel Villasana-Espinoza Date: Tue, 24 Sep 2024 19:51:31 -0400 Subject: [PATCH 11/11] fix: tests --- server/service/service_appconfig_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/service/service_appconfig_test.go b/server/service/service_appconfig_test.go index b6318c584b39..d83479e5f156 100644 --- a/server/service/service_appconfig_test.go +++ b/server/service/service_appconfig_test.go @@ -373,6 +373,18 @@ func TestModifyAppConfigPatches(t *testing.T) { return nil } + ds.SaveABMTokenFunc = func(ctx context.Context, tok *fleet.ABMToken) error { + return nil + } + + ds.ListVPPTokensFunc = func(ctx context.Context) ([]*fleet.VPPTokenDB, error) { + return []*fleet.VPPTokenDB{}, nil + } + + ds.ListABMTokensFunc = func(ctx context.Context) ([]*fleet.ABMToken, error) { + return []*fleet.ABMToken{}, nil + } + configJSON := []byte(`{"org_info": { "org_name": "Acme", "org_logo_url": "somelogo.jpg" }}`) ctx = test.UserContext(ctx, test.UserAdmin)