Update backend error messages (#40364)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** For #40348

# Details

This PR updates a number of error message on the server to use `fleet`
and `report` instead of `team` or `query` where applicable.

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.
this is all internal, i don't think it warrants a changelog

## Testing

- [X] Added/updated automated tests
- [ ] QA'd all new/changed functionality manually
I did not go trying to trigger all these errors.  It's text changes.
This commit is contained in:
Scott Gress
2026-02-25 13:54:45 -06:00
committed by GitHub
parent 7b7839b7a4
commit 9da7008765
31 changed files with 59 additions and 59 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ func (svc *Service) CalendarWebhook(ctx context.Context, eventUUID string, chann
if eventDetails.TeamID == nil {
// Should not happen
svc.authz.SkipAuthorization(ctx)
return fmt.Errorf("calendar event %s has no team ID", eventUUID)
return fmt.Errorf("calendar event %s has no fleet ID", eventUUID)
}
localConfig := &calendar.Config{
+1 -1
View File
@@ -331,7 +331,7 @@ func TestCalendarWebhookErrorCases(t *testing.T) {
}, nil
}
},
expectedError: "calendar event test-uuid-9 has no team ID",
expectedError: "calendar event test-uuid-9 has no fleet ID",
},
{
name: "database error when getting event details",
+2 -2
View File
@@ -235,7 +235,7 @@ func (svc *Service) validateReadyForLinuxEscrow(ctx context.Context, host *fleet
if host.TeamID == nil {
if !ac.MDM.EnableDiskEncryption.Value {
return &fleet.BadRequestError{Message: "Disk encryption is not enabled for hosts not assigned to a team."}
return &fleet.BadRequestError{Message: "Disk encryption is not enabled for hosts not assigned to a fleet."}
}
} else {
tc, err := svc.ds.TeamMDMConfig(ctx, *host.TeamID)
@@ -243,7 +243,7 @@ func (svc *Service) validateReadyForLinuxEscrow(ctx context.Context, host *fleet
return err
}
if !tc.EnableDiskEncryption {
return &fleet.BadRequestError{Message: "Disk encryption is not enabled for this host's team."}
return &fleet.BadRequestError{Message: "Disk encryption is not enabled for this host's fleet."}
}
}
+1 -1
View File
@@ -152,7 +152,7 @@ func (svc *Service) SetSetupExperienceScript(ctx context.Context, teamID *uint,
if errors.As(err, &existsErr) {
err = fleet.NewInvalidArgumentError("script", err.Error()).WithStatus(http.StatusConflict) // TODO: confirm error message with product/frontend
} else if errors.As(err, &fkErr) {
err = fleet.NewInvalidArgumentError("team_id", "The team does not exist.").WithStatus(http.StatusNotFound)
err = fleet.NewInvalidArgumentError("team_id/fleet_id", "The fleet does not exist.").WithStatus(http.StatusNotFound)
}
return ctxerr.Wrap(ctx, err, "create setup experience script")
}
+4 -4
View File
@@ -286,7 +286,7 @@ func (svc *Service) UpdateSoftwareInstaller(ctx context.Context, payload *fleet.
payload.UserID = vc.UserID()
if payload.TeamID == nil {
return nil, &fleet.BadRequestError{Message: "team_id is required; enter 0 for no team"}
return nil, &fleet.BadRequestError{Message: "fleet_id is required; enter 0 for unassigned"}
}
var teamName *string
@@ -763,7 +763,7 @@ func ValidateSoftwareLabelsForUpdate(ctx context.Context, svc fleet.Service, exi
func (svc *Service) DeleteSoftwareInstaller(ctx context.Context, titleID uint, teamID *uint) error {
if teamID == nil {
return fleet.NewInvalidArgumentError("team_id", "is required")
return fleet.NewInvalidArgumentError("fleet_id", "is required")
}
// we authorize with SoftwareInstaller here, but it uses the same AuthzType
@@ -968,7 +968,7 @@ func (svc *Service) GenerateSoftwareInstallerToken(ctx context.Context, alt stri
if teamID == nil {
svc.authz.SkipAuthorization(ctx)
return "", fleet.NewInvalidArgumentError("team_id", "is required")
return "", fleet.NewInvalidArgumentError("fleet_id", "is required")
}
if err := svc.authz.Authorize(ctx, &fleet.SoftwareInstaller{TeamID: teamID}, fleet.ActionRead); err != nil {
@@ -1042,7 +1042,7 @@ func (svc *Service) DownloadSoftwareInstaller(ctx context.Context, skipAuthz boo
if teamID == nil {
svc.authz.SkipAuthorization(ctx)
return nil, fleet.NewInvalidArgumentError("team_id", "is required")
return nil, fleet.NewInvalidArgumentError("fleet_id", "is required")
}
meta, err := svc.GetSoftwareInstallerMetadata(ctx, skipAuthz, titleID, teamID)
+1 -1
View File
@@ -543,7 +543,7 @@ func (svc *Service) AddTeamUsers(ctx context.Context, teamID uint, users []fleet
idMap := make(map[uint]fleet.TeamUser)
for _, user := range users {
if !fleet.ValidTeamRole(user.Role) {
return nil, fleet.NewInvalidArgumentError("users", fmt.Sprintf("%s is not a valid role for a team user", user.Role))
return nil, fleet.NewInvalidArgumentError("users", fmt.Sprintf("%s is not a valid user role", user.Role))
}
idMap[user.ID] = user
fullUser, err := svc.ds.UserByID(ctx, user.ID)
+2 -2
View File
@@ -578,7 +578,7 @@ func (svc *Service) AddAppStoreApp(ctx context.Context, teamID *uint, appID flee
if teamID != nil && *teamID != 0 {
tm, err := svc.ds.TeamLite(ctx, *teamID)
if fleet.IsNotFound(err) {
return 0, fleet.NewInvalidArgumentError("team_id", fmt.Sprintf("team %d does not exist", *teamID)).
return 0, fleet.NewInvalidArgumentError("team_id/fleet_id", fmt.Sprintf("fleet %d does not exist", *teamID)).
WithStatus(http.StatusNotFound)
} else if err != nil {
return 0, ctxerr.Wrap(ctx, err, "checking if team exists")
@@ -888,7 +888,7 @@ func (svc *Service) UpdateAppStoreApp(ctx context.Context, titleID uint, teamID
if teamID != nil && *teamID != 0 {
tm, err := svc.ds.TeamLite(ctx, *teamID)
if fleet.IsNotFound(err) {
return nil, nil, fleet.NewInvalidArgumentError("team_id", fmt.Sprintf("team %d does not exist", *teamID)).
return nil, nil, fleet.NewInvalidArgumentError("team_id/fleet_id", fmt.Sprintf("fleet %d does not exist", *teamID)).
WithStatus(http.StatusNotFound)
} else if err != nil {
return nil, nil, ctxerr.Wrap(ctx, err, "UpdateAppStoreApp: checking if team exists")
+4 -4
View File
@@ -1057,10 +1057,10 @@ func newTeamPolicy(ctx context.Context, db sqlx.ExtContext, teamID uint, authorI
var ok bool
err := sqlx.GetContext(ctx, db, &ok, `SELECT COUNT(*) = 1 FROM teams WHERE id = ?`, teamID)
if err != nil {
return nil, ctxerr.Wrap(ctx, err, "get team id")
return nil, ctxerr.Wrap(ctx, err, "get fleet id")
}
if !ok {
return nil, ctxerr.Wrap(ctx, notFound("Team").WithID(teamID), "get team id")
return nil, ctxerr.Wrap(ctx, notFound("Fleet").WithID(teamID), "get fleet id")
}
}
@@ -1228,9 +1228,9 @@ func (ds *Datastore) ApplyPolicySpecs(ctx context.Context, authorID uint, specs
err := sqlx.GetContext(ctx, queryerContext, &tmID, `SELECT id FROM teams WHERE name = ?`, spec.Team)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return ctxerr.Wrap(ctx, notFound("Team").WithName(spec.Team), "get team id")
return ctxerr.Wrap(ctx, notFound("Fleet").WithName(spec.Team), "get fleet id")
}
return ctxerr.Wrap(ctx, err, "get team id")
return ctxerr.Wrap(ctx, err, "get fleet id")
}
teamID = &tmID
}
+3 -3
View File
@@ -234,7 +234,7 @@ func (ds *Datastore) QueryByName(
err := sqlx.GetContext(ctx, ds.reader(ctx), &query, stmt, args...)
if err != nil {
if err == sql.ErrNoRows {
return nil, ctxerr.Wrap(ctx, notFound("Query").WithName(name))
return nil, ctxerr.Wrap(ctx, notFound("Report").WithName(name))
}
return nil, ctxerr.Wrap(ctx, err, "selecting query by name")
}
@@ -470,7 +470,7 @@ func (ds *Datastore) SaveQuery(ctx context.Context, q *fleet.Query, shouldDiscar
return ctxerr.Wrap(ctx, err, "rows affected updating query")
}
if rows == 0 {
return ctxerr.Wrap(ctx, notFound("Query").WithID(q.ID))
return ctxerr.Wrap(ctx, notFound("Report").WithID(q.ID))
}
if shouldDeleteStats {
@@ -638,7 +638,7 @@ func query(ctx context.Context, db sqlx.QueryerContext, id uint) (*fleet.Query,
query := &fleet.Query{}
if err := sqlx.GetContext(ctx, db, query, sqlQuery, false, fleet.AggregatedStatsTypeScheduledQuery, id); err != nil {
if err == sql.ErrNoRows {
return nil, ctxerr.Wrap(ctx, notFound("Query").WithID(id))
return nil, ctxerr.Wrap(ctx, notFound("Report").WithID(id))
}
return nil, ctxerr.Wrap(ctx, err, "selecting query")
}
+1 -1
View File
@@ -123,7 +123,7 @@ func insertScheduledQueryDB(ctx context.Context, q sqlx.ExtContext, sq *fleet.Sc
err = sqlx.SelectContext(ctx, q, &metadata, query, sq.QueryID)
if err != nil && err == sql.ErrNoRows {
return nil, ctxerr.Wrap(ctx, notFound("Query").WithID(sq.QueryID))
return nil, ctxerr.Wrap(ctx, notFound("Report").WithID(sq.QueryID))
} else if err != nil {
return nil, ctxerr.Wrap(ctx, err, "select query by ID")
}
+1 -1
View File
@@ -2516,7 +2516,7 @@ func (ds *Datastore) BatchExecuteScript(ctx context.Context, userID *uint, scrip
}
if !teamIDEq(host.TeamID, script.TeamID) {
return "", ctxerr.Errorf(ctx, "all hosts must be on the same team as the script")
return "", ctxerr.Errorf(ctx, "all hosts must be on the same fleet as the script")
}
}
+2 -2
View File
@@ -1844,7 +1844,7 @@ func testBatchExecute(t *testing.T, ds *Datastore) {
// Hosts all have to be on the same team as the script
execID, err := ds.BatchExecuteScript(ctx, &user.ID, script.ID, []uint{hostNoScripts.ID, hostTeam1.ID})
require.Empty(t, execID)
require.ErrorContains(t, err, "same team")
require.ErrorContains(t, err, "same fleet")
// Actual good execution
execID, err = ds.BatchExecuteScript(ctx, &user.ID, script.ID, []uint{hostNoScripts.ID, hostWindows.ID, host1.ID, host2.ID, host3.ID})
@@ -1982,7 +1982,7 @@ func testBatchExecuteWithStatus(t *testing.T, ds *Datastore) {
// Hosts all have to be on the same team as the script
execID, err := ds.BatchExecuteScript(ctx, &user.ID, script.ID, []uint{hostNoScripts.ID, hostTeam1.ID})
require.Empty(t, execID)
require.ErrorContains(t, err, "same team")
require.ErrorContains(t, err, "same fleet")
// Actual good execution
execID, err = ds.BatchExecuteScript(ctx, &user.ID, script.ID, []uint{hostNoScripts.ID, hostWindows.ID, host1.ID, host2.ID, host3.ID})
+3 -3
View File
@@ -94,7 +94,7 @@ func teamDB(ctx context.Context, q sqlx.QueryerContext, tid uint, withExtras boo
if err := sqlx.GetContext(ctx, q, team, stmt, tid); err != nil {
if err == sql.ErrNoRows {
return nil, ctxerr.Wrap(ctx, notFound("Team").WithID(tid))
return nil, ctxerr.Wrap(ctx, notFound("Fleet").WithID(tid))
}
return nil, ctxerr.Wrap(ctx, err, "select team")
}
@@ -219,7 +219,7 @@ func (ds *Datastore) TeamByName(ctx context.Context, name string) (*fleet.Team,
if err := sqlx.GetContext(ctx, ds.reader(ctx), team, stmt, nameUnicode); err != nil {
if err == sql.ErrNoRows {
return nil, ctxerr.Wrap(ctx, notFound("Team").WithName(nameUnicode))
return nil, ctxerr.Wrap(ctx, notFound("Fleet").WithName(nameUnicode))
}
return nil, ctxerr.Wrap(ctx, err, "select team")
}
@@ -253,7 +253,7 @@ func (ds *Datastore) TeamByFilename(ctx context.Context, filename string) (*flee
if err := sqlx.GetContext(ctx, ds.reader(ctx), team, stmt, filename); err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, ctxerr.Wrap(ctx, notFound("Team").WithMessage("filename not found"))
return nil, ctxerr.Wrap(ctx, notFound("Fleet").WithMessage("filename not found"))
}
return nil, ctxerr.Wrap(ctx, err, "select team")
}
+1 -1
View File
@@ -261,7 +261,7 @@ func testUserGlobalRole(t *testing.T, ds fleet.Datastore, users []*fleet.User) {
})
var ferr *fleet.Error
require.True(t, errors.As(err, &ferr))
assert.Equal(t, "Cannot specify both Global Role and Team Roles", ferr.Message)
assert.Equal(t, "Cannot specify both global and fleet-scoped roles", ferr.Message)
}
func testUsersHas(t *testing.T, ds *Datastore) {
+1 -1
View File
@@ -179,7 +179,7 @@ func validateJSONAgentOptionsExtensions(ctx context.Context, ds Datastore, optsE
// OK
case IsNotFound(err):
// Label does not exist, fail the request.
return fmt.Errorf("Label %q does not exist, or cannot be used on this team", labelName)
return fmt.Errorf("Label %q does not exist, or cannot be used on this fleet", labelName)
default:
return fmt.Errorf("get label by name: %w", err)
}
+3 -3
View File
@@ -289,9 +289,9 @@ func (tq *TargetedQuery) AuthzType() string {
}
var (
errQueryEmptyName = errors.New("query name cannot be empty")
errQueryEmptyQuery = errors.New("query's SQL query cannot be empty")
ErrQueryInvalidPlatform = errors.New("query's platform must be a comma-separated list of 'darwin', 'linux', 'windows', and/or 'chrome' in a single string")
errQueryEmptyName = errors.New("report name cannot be empty")
errQueryEmptyQuery = errors.New("report's SQL query cannot be empty")
ErrQueryInvalidPlatform = errors.New("report's platform must be a comma-separated list of 'darwin', 'linux', 'windows', and/or 'chrome' in a single string")
errInvalidLogging = fmt.Errorf("invalid logging value, must be one of '%s', '%s', '%s'", LoggingSnapshot, LoggingDifferential, LoggingDifferentialIgnoreRemovals)
)
+2 -2
View File
@@ -91,14 +91,14 @@ type TeamRole struct {
func (s SSORolesInfo) verify() error {
if s.Global != nil && len(s.Teams) > 0 {
return errors.New("cannot set both global and team roles")
return errors.New("cannot set both global and fleet roles")
}
// Check for duplicate entries for the same team.
// This is just in case some IdP allows duplicating attributes.
teamSet := make(map[uint]struct{})
for _, teamRole := range s.Teams {
if _, ok := teamSet[teamRole.ID]; ok {
return fmt.Errorf("duplicate team entry: %d", teamRole.ID)
return fmt.Errorf("duplicate fleet entry: %d", teamRole.ID)
}
teamSet[teamRole.ID] = struct{}{}
}
+3 -3
View File
@@ -529,18 +529,18 @@ func ValidGlobalRole(role string) bool {
func ValidateRole(globalRole *string, teamUsers []UserTeam) error {
if globalRole == nil || *globalRole == "" {
if len(teamUsers) == 0 {
return NewError(ErrNoRoleNeeded, "either global role or team role needs to be defined")
return NewError(ErrNoRoleNeeded, "either global role or fleet role needs to be defined")
}
for _, t := range teamUsers {
if !ValidTeamRole(t.Role) {
return NewErrorf(ErrNoRoleNeeded, "invalid team role: %s", t.Role)
return NewErrorf(ErrNoRoleNeeded, "invalid fleet role: %s", t.Role)
}
}
return nil
}
if len(teamUsers) > 0 {
return NewError(ErrNoRoleNeeded, "Cannot specify both Global Role and Team Roles")
return NewError(ErrNoRoleNeeded, "Cannot specify both global and fleet-scoped roles")
}
if !ValidGlobalRole(*globalRole) {
+2 -2
View File
@@ -2925,8 +2925,8 @@ func bootstrapPackageMetadataEndpoint(ctx context.Context, request interface{},
meta, err := svc.GetMDMAppleBootstrapPackageMetadata(ctx, req.TeamID, req.ForUpdate)
switch {
case fleet.IsNotFound(err):
return bootstrapPackageMetadataResponse{Err: fleet.NewInvalidArgumentError("team_id",
"bootstrap package for this team does not exist").WithStatus(http.StatusNotFound)}, nil
return bootstrapPackageMetadataResponse{Err: fleet.NewInvalidArgumentError("team_id/fleet_id",
"bootstrap package for this fleet does not exist").WithStatus(http.StatusNotFound)}, nil
case err != nil:
return bootstrapPackageMetadataResponse{Err: err}, nil
}
+2 -2
View File
@@ -620,7 +620,7 @@ func TestTriggerLinuxDiskEncryptionEscrow(t *testing.T) {
return appConfig, nil
}
err = svc.TriggerLinuxDiskEncryptionEscrow(ctx, host)
require.ErrorContains(t, err, "Disk encryption is not enabled for hosts not assigned to a team.")
require.ErrorContains(t, err, "Disk encryption is not enabled for hosts not assigned to a fleet.")
// valid platform, team, encryption not enabled
host.TeamID = ptr.Uint(1)
@@ -630,7 +630,7 @@ func TestTriggerLinuxDiskEncryptionEscrow(t *testing.T) {
return teamConfig, nil
}
err = svc.TriggerLinuxDiskEncryptionEscrow(ctx, host)
require.ErrorContains(t, err, "Disk encryption is not enabled for this host's team.")
require.ErrorContains(t, err, "Disk encryption is not enabled for this host's fleet.")
// valid platform, team, host disk is not encrypted or unknown encryption state
teamConfig = &fleet.TeamMDM{EnableDiskEncryption: true}
+1 -1
View File
@@ -68,7 +68,7 @@ func (svc Service) NewGlobalPolicy(ctx context.Context, p fleet.PolicyPayload) (
}
vc, ok := viewer.FromContext(ctx)
if !ok {
return nil, errors.New("user must be authenticated to create team policies")
return nil, errors.New("user must be authenticated to create fleet policies")
}
if err := p.Verify(); err != nil {
return nil, ctxerr.Wrap(ctx, &fleet.BadRequestError{
+2 -2
View File
@@ -2684,7 +2684,7 @@ func (svc *Service) OSVersions(
if err != nil {
return nil, count, nil, ctxerr.Wrap(ctx, err, "checking if team exists")
} else if !exists {
return nil, count, nil, fleet.NewInvalidArgumentError("team_id", fmt.Sprintf("team %d does not exist", *teamID)).
return nil, count, nil, fleet.NewInvalidArgumentError("team_id/fleet_id", fmt.Sprintf("fleet %d does not exist", *teamID)).
WithStatus(http.StatusNotFound)
}
}
@@ -2841,7 +2841,7 @@ func (svc *Service) OSVersion(ctx context.Context, osID uint, teamID *uint, incl
if err != nil {
return nil, nil, ctxerr.Wrap(ctx, err, "checking if team exists")
} else if !exists {
return nil, nil, fleet.NewInvalidArgumentError("team_id", fmt.Sprintf("team %d does not exist", *teamID)).
return nil, nil, fleet.NewInvalidArgumentError("team_id/fleet_id", fmt.Sprintf("fleet %d does not exist", *teamID)).
WithStatus(http.StatusNotFound)
}
}
+2 -2
View File
@@ -266,7 +266,7 @@ func (s *integrationTestSuite) TestUserWithoutRoleErrors() {
}
resp := s.Do("POST", "/api/latest/fleet/users/admin", &params, http.StatusUnprocessableEntity)
assertErrorCodeAndMessage(t, resp, fleet.ErrNoRoleNeeded, "either global role or team role needs to be defined")
assertErrorCodeAndMessage(t, resp, fleet.ErrNoRoleNeeded, "either global role or fleet role needs to be defined")
}
func (s *integrationTestSuite) TestUserEmailValidation() {
@@ -328,7 +328,7 @@ func (s *integrationTestSuite) TestUserCreationWrongTeamErrors() {
Teams: &teams,
}
resp := s.Do("POST", "/api/latest/fleet/users/admin", &params, http.StatusUnprocessableEntity)
assertBodyContains(t, resp, `team with id 9999 does not exist`)
assertBodyContains(t, resp, `fleet with id 9999 does not exist`)
}
func (s *integrationTestSuite) TestQueryCreationLogsActivity() {
@@ -8002,7 +8002,7 @@ func (s *integrationEnterpriseTestSuite) TestRunHostSavedScript() {
// attempt to run a team script on a non-team host
res = s.Do("POST", "/api/latest/fleet/scripts/run", fleet.HostScriptRequestPayload{HostID: host.ID, ScriptID: &savedTmScript.ID}, http.StatusUnprocessableEntity)
errMsg = extractServerErrorText(res.Body)
require.Contains(t, errMsg, `The script does not belong to the same team`)
require.Contains(t, errMsg, `The script does not belong to the same fleet`)
// make sure the host is still seen as "online"
err = s.ds.MarkHostsSeen(ctx, []uint{host.ID}, time.Now())
@@ -8196,7 +8196,7 @@ func (s *integrationEnterpriseTestSuite) TestRunHostSavedScript() {
// attempt to run sync with an existing team script that belongs to a team different from the host's team
res = s.Do("POST", "/api/latest/fleet/scripts/run/sync", fleet.HostScriptRequestPayload{HostID: host2.ID, ScriptName: "f1337.sh", TeamID: tm2.ID}, http.StatusUnprocessableEntity)
errMsg = extractServerErrorText(res.Body)
require.Contains(t, errMsg, `The script does not belong to the same team`)
require.Contains(t, errMsg, `The script does not belong to the same fleet`)
// create a valid sync script execution request by script name, fails because the
// request will time-out waiting for a result.
@@ -8239,7 +8239,7 @@ func (s *integrationEnterpriseTestSuite) TestRunHostSavedScript() {
// attempt to run async with an existing team script that belongs to a team different from the host's team
res = s.Do("POST", "/api/latest/fleet/scripts/run", fleet.HostScriptRequestPayload{HostID: host2.ID, ScriptName: "f1337.sh", TeamID: tm2.ID}, http.StatusUnprocessableEntity)
errMsg = extractServerErrorText(res.Body)
require.Contains(t, errMsg, `The script does not belong to the same team`)
require.Contains(t, errMsg, `The script does not belong to the same fleet`)
var runSyncResp3 runScriptSyncResponse
s.DoJSON("POST", "/api/latest/fleet/scripts/run", fleet.HostScriptRequestPayload{HostID: host2.ID, ScriptName: "f13372.sh"}, http.StatusAccepted, &runSyncResp3)
@@ -8556,7 +8556,7 @@ func (s *integrationEnterpriseTestSuite) TestSavedScripts() {
"script1.sh", []byte(`echo "hello"`), s.token, map[string][]string{"team_id": {"123"}})
res = s.DoRawWithHeaders("POST", "/api/latest/fleet/scripts", body.Bytes(), http.StatusNotFound, headers)
errMsg = extractServerErrorText(res.Body)
require.Contains(t, errMsg, "The team does not exist.")
require.Contains(t, errMsg, "The fleet does not exist.")
// create a team
tm, err := s.ds.NewTeam(ctx, &fleet.Team{Name: "team1"})
@@ -772,7 +772,7 @@ func (s *liveQueriesTestSuite) TestLiveQueriesRestFailsToCreateCampaign() {
require.Len(t, liveQueryResp.Results, 1)
assert.Equal(t, 0, liveQueryResp.Summary.RespondedHostCount)
require.NotNil(t, liveQueryResp.Results[0].Error)
assert.Contains(t, *liveQueryResp.Results[0].Error, "Query 999 was not found in the datastore")
assert.Contains(t, *liveQueryResp.Results[0].Error, "Report 999 was not found in the datastore")
oneLiveQueryRequest := runOneLiveQueryRequest{
HostIDs: []uint{888},
+3 -3
View File
@@ -251,7 +251,7 @@ func (svc *Service) RunHostScript(ctx context.Context, request *fleet.HostScript
hostTmID = *host.TeamID
}
if scriptTmID != hostTmID {
return nil, fleet.NewInvalidArgumentError("script_id", `The script does not belong to the same team (or no team) as the host.`)
return nil, fleet.NewInvalidArgumentError("script_id", `The script does not belong to the same fleet (or "Unassigned") as the host.`)
}
isQueued, err := svc.ds.IsExecutionPendingForHost(ctx, request.HostID, *request.ScriptID)
@@ -542,7 +542,7 @@ func (svc *Service) NewScript(ctx context.Context, teamID *uint, name string, r
if errors.As(err, &existsErr) {
err = fleet.NewInvalidArgumentError("script", "A script with this name already exists.").WithStatus(http.StatusConflict)
} else if errors.As(err, &fkErr) {
err = fleet.NewInvalidArgumentError("team_id", "The team does not exist.").WithStatus(http.StatusNotFound)
err = fleet.NewInvalidArgumentError("team_id/fleet_id", "The fleet does not exist.").WithStatus(http.StatusNotFound)
}
return nil, ctxerr.Wrap(ctx, err, "create script")
}
@@ -1505,7 +1505,7 @@ func (svc *Service) BatchScriptExecute(ctx context.Context, scriptID uint, hostI
continue
}
if host.TeamID == nil || script.TeamID == nil || *host.TeamID != *script.TeamID {
return "", fleet.NewInvalidArgumentError("host_ids", "all hosts must be on the same team as the script")
return "", fleet.NewInvalidArgumentError("host_ids", "all hosts must be on the same fleet as the script")
}
}
+1 -1
View File
@@ -891,7 +891,7 @@ func TestBatchScriptExecute(t *testing.T) {
ctx = viewer.NewContext(ctx, viewer.Viewer{User: &fleet.User{GlobalRole: ptr.String(fleet.RoleAdmin)}})
_, err := svc.BatchScriptExecute(ctx, 1, []uint{1, 2, 3}, nil, nil)
require.Error(t, err)
require.ErrorContains(t, err, "all hosts must be on the same team as the script")
require.ErrorContains(t, err, "all hosts must be on the same fleet as the script")
})
t.Run("error if both host_ids and filters are specified", func(t *testing.T) {
+1 -1
View File
@@ -170,7 +170,7 @@ func (svc *Service) SoftwareByID(ctx context.Context, id uint, teamID *uint, inc
if err != nil {
return nil, ctxerr.Wrap(ctx, err, "checking if team exists")
} else if !exists {
return nil, fleet.NewInvalidArgumentError("team_id", fmt.Sprintf("team %d does not exist", *teamID)).
return nil, fleet.NewInvalidArgumentError("team_id/fleet_id", fmt.Sprintf("fleet %d does not exist", *teamID)).
WithStatus(http.StatusNotFound)
}
}
+2 -2
View File
@@ -152,7 +152,7 @@ func (svc *Service) SoftwareTitleByID(ctx context.Context, id uint, teamID *uint
if err != nil {
return nil, ctxerr.Wrap(ctx, err, "checking if team exists")
} else if !exists {
return nil, fleet.NewInvalidArgumentError("team_id", fmt.Sprintf("team %d does not exist", *teamID)).
return nil, fleet.NewInvalidArgumentError("team_id", fmt.Sprintf("fleet %d does not exist", *teamID)).
WithStatus(http.StatusNotFound)
}
}
@@ -176,7 +176,7 @@ func (svc *Service) SoftwareTitleByID(ctx context.Context, id uint, teamID *uint
return nil, ctxerr.Wrap(ctx, err, "checked using a global admin")
}
return nil, fleet.NewPermissionError("Error: You don't have permission to view specified software. It is installed on hosts that belong to team you don't have permissions to view.")
return nil, fleet.NewPermissionError("Error: You don't have permission to view specified software. It is installed on hosts that belong to a fleet you don't have permissions to view.")
}
return nil, ctxerr.Wrap(ctx, err, "getting software title by id")
}
+1 -1
View File
@@ -82,7 +82,7 @@ func (svc *Service) CreateUser(ctx context.Context, p fleet.UserPayload) (*fleet
_, ok := teamIDs[userTeam.Team.ID]
if !ok {
return nil, nil, ctxerr.Wrap(
ctx, fleet.NewInvalidArgumentError("teams.id", fmt.Sprintf("team with id %d does not exist", userTeam.Team.ID)),
ctx, fleet.NewInvalidArgumentError("teams.id", fmt.Sprintf("fleet with id %d does not exist", userTeam.Team.ID)),
)
}
}
+1 -1
View File
@@ -197,7 +197,7 @@ func (svc *Service) Vulnerability(ctx context.Context, cve string, teamID *uint,
if err != nil {
return nil, false, ctxerr.Wrap(ctx, err, "checking if team exists")
} else if !exists {
return nil, false, authz.ForbiddenWithInternal("team does not exist", nil, nil, nil)
return nil, false, authz.ForbiddenWithInternal("fleet does not exist", nil, nil, nil)
}
}