From 63e4c5f1490ac51d67176f7f5b5318983fea4783 Mon Sep 17 00:00:00 2001 From: Martin Angers Date: Tue, 11 Jun 2024 08:53:41 -0400 Subject: [PATCH] Fix a panic when downloading a software installer that exists in the DB but not in the storage (#19527) --- changes/19324-fix-panic-in-download-software | 1 + ee/server/service/software_installers.go | 2 +- server/service/integration_enterprise_test.go | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changes/19324-fix-panic-in-download-software diff --git a/changes/19324-fix-panic-in-download-software b/changes/19324-fix-panic-in-download-software new file mode 100644 index 000000000000..e5cbf57365a4 --- /dev/null +++ b/changes/19324-fix-panic-in-download-software @@ -0,0 +1 @@ +* Fixed a panic (API returning code 500) when the software installer exists in the database but the installer does not exist in the storage. diff --git a/ee/server/service/software_installers.go b/ee/server/service/software_installers.go index 59c95de6599e..989b5ab26e35 100644 --- a/ee/server/service/software_installers.go +++ b/ee/server/service/software_installers.go @@ -181,7 +181,7 @@ func (svc *Service) getSoftwareInstallerBinary(ctx context.Context, storageID st return nil, ctxerr.Wrap(ctx, err, "checking if installer exists") } if !exists { - return nil, ctxerr.Wrap(ctx, err, "does not exist in software installer store") + return nil, ctxerr.Wrap(ctx, notFoundError{}, "does not exist in software installer store") } // get the installer from the store diff --git a/server/service/integration_enterprise_test.go b/server/service/integration_enterprise_test.go index b1dba17e407e..50e066109243 100644 --- a/server/service/integration_enterprise_test.go +++ b/server/service/integration_enterprise_test.go @@ -9420,6 +9420,9 @@ func (s *integrationEnterpriseTestSuite) TestSoftwareInstallerUploadDownloadAndD // check activity s.lastActivityOfTypeMatches(fleet.ActivityTypeDeletedSoftware{}.ActivityName(), fmt.Sprintf(`{"software_title": "ruby", "software_package": "ruby.deb", "team_name": "%s", "team_id": %d, "self_service": true}`, createTeamResp.Team.Name, createTeamResp.Team.ID), 0) + + // download the installer, not found anymore + s.Do("GET", fmt.Sprintf("/api/latest/fleet/software/%d/package?alt=media", titleID), nil, http.StatusNotFound, "team_id", fmt.Sprintf("%d", *payload.TeamID)) }) }