Flaky test fix: use mock server for FMA manifest instead of hitting github. (#38805)
This commit is contained in:
@@ -20401,7 +20401,7 @@ func (s *integrationEnterpriseTestSuite) TestBatchSoftwareInstallerAndFMACategor
|
||||
// create an HTTP server to host the software installer
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/dummy_installer.pkg":
|
||||
case "/fma.pkg":
|
||||
file, err := os.Open(filepath.Join("testdata", "software-installers", "dummy_installer.pkg"))
|
||||
require.NoError(t, err)
|
||||
defer file.Close()
|
||||
@@ -20409,14 +20409,46 @@ func (s *integrationEnterpriseTestSuite) TestBatchSoftwareInstallerAndFMACategor
|
||||
_, err = io.Copy(w, file)
|
||||
require.NoError(t, err)
|
||||
|
||||
case "/non-fma.pkg":
|
||||
file, err := os.Open(filepath.Join("testdata", "software-installers", "EchoApp.pkg"))
|
||||
require.NoError(t, err)
|
||||
defer file.Close()
|
||||
w.Header().Set("Content-Type", "application/application/x-newton-compatible-pkg")
|
||||
_, err = io.Copy(w, file)
|
||||
require.NoError(t, err)
|
||||
|
||||
default:
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
srv := httptest.NewServer(handler)
|
||||
t.Cleanup(srv.Close)
|
||||
installerServer := httptest.NewServer(handler)
|
||||
t.Cleanup(installerServer.Close)
|
||||
|
||||
// Mock server to serve fleet maintained app manifest
|
||||
manifestServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var versions []*ma.FMAManifestApp
|
||||
versions = append(versions, &ma.FMAManifestApp{
|
||||
Version: "6.0",
|
||||
Queries: ma.FMAQueries{
|
||||
Exists: "SELECT 1 FROM osquery_info;",
|
||||
},
|
||||
InstallerURL: installerServer.URL + "/fma.pkg",
|
||||
SHA256: "no_check", // See ma.noCheckHash
|
||||
DefaultCategories: []string{"Productivity"},
|
||||
})
|
||||
|
||||
manifest := ma.FMAManifestFile{
|
||||
Versions: versions,
|
||||
}
|
||||
|
||||
err := json.NewEncoder(w).Encode(manifest)
|
||||
require.NoError(t, err)
|
||||
}))
|
||||
|
||||
t.Cleanup(manifestServer.Close)
|
||||
t.Setenv("FLEET_DEV_MAINTAINED_APPS_BASE_URL", manifestServer.URL)
|
||||
|
||||
maintained1, err := s.ds.UpsertMaintainedApp(ctx, &fleet.MaintainedApp{
|
||||
Name: "1Password",
|
||||
@@ -20427,7 +20459,7 @@ func (s *integrationEnterpriseTestSuite) TestBatchSoftwareInstallerAndFMACategor
|
||||
require.NoError(t, err)
|
||||
|
||||
// do a request with an invalid category
|
||||
pkgURL := srv.URL + "/dummy_installer.pkg"
|
||||
pkgURL := installerServer.URL + "/non-fma.pkg"
|
||||
softwareToInstall := []*fleet.SoftwareInstallerPayload{
|
||||
{URL: pkgURL, Categories: []string{"Not Found"}, SelfService: true},
|
||||
{Slug: &maintained1.Slug, SelfService: true},
|
||||
@@ -20471,11 +20503,13 @@ func (s *integrationEnterpriseTestSuite) TestBatchSoftwareInstallerAndFMACategor
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
softwareToInstall[0].Categories = tc.categories
|
||||
softwareToInstall[1].Categories = tc.categories
|
||||
|
||||
// remove duplicates if any
|
||||
tc.categories = server.RemoveDuplicatesFromSlice(tc.categories)
|
||||
s.DoJSON("POST", "/api/latest/fleet/software/batch", batchSetSoftwareInstallersRequest{Software: softwareToInstall}, http.StatusAccepted, &batchResponse, "team_name", team1.Name)
|
||||
packages := waitBatchSetSoftwareInstallersCompleted(t, &s.withServer, team1.Name, batchResponse.RequestUUID)
|
||||
require.Len(t, packages, 2)
|
||||
|
||||
for _, p := range packages {
|
||||
require.NotNil(t, p.TitleID)
|
||||
require.NotNil(t, p.TeamID)
|
||||
@@ -20492,7 +20526,6 @@ func (s *integrationEnterpriseTestSuite) TestBatchSoftwareInstallerAndFMACategor
|
||||
continue
|
||||
}
|
||||
require.ElementsMatch(t, tc.categories, stResp.SoftwareTitle.SoftwarePackage.Categories)
|
||||
|
||||
}
|
||||
|
||||
// check that the categories come back on the My device page
|
||||
|
||||
Reference in New Issue
Block a user