Return 404 when listing policies for a team that does not exist (#3793)

* Return 404 when listing policies for a team that does not exist

* Set mock for auth test
This commit is contained in:
Lucas Manuel Rodriguez 2022-01-19 18:17:42 -03:00 committed by GitHub
parent 4a83201092
commit e5cb68cee9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 0 deletions

View file

@ -0,0 +1 @@
* Return 404 when listing policies of a team that doesn't exist.

View file

@ -2248,3 +2248,11 @@ func (s *integrationTestSuite) TestGlobalPoliciesBrowsing() {
assert.Equal(t, "global policy", policiesResponse.Policies[0].Name)
assert.Equal(t, "select * from osquery;", policiesResponse.Policies[0].Query)
}
func (s *integrationTestSuite) TestTeamPoliciesTeamNotExists() {
t := s.T()
teamPoliciesResponse := listTeamPoliciesResponse{}
s.DoJSON("GET", fmt.Sprintf("/api/v1/fleet/teams/%d/policies", 9999999), nil, http.StatusNotFound, &teamPoliciesResponse)
require.Len(t, teamPoliciesResponse.Policies, 0)
}

View file

@ -108,6 +108,10 @@ func (svc Service) ListTeamPolicies(ctx context.Context, teamID uint) ([]*fleet.
return nil, err
}
if _, err := svc.ds.Team(ctx, teamID); err != nil {
return nil, ctxerr.Wrapf(ctx, err, "loading team %d", teamID)
}
return svc.ds.ListTeamPolicies(ctx, teamID)
}

View file

@ -56,6 +56,9 @@ func TestTeamPoliciesAuth(t *testing.T) {
ds.NewActivityFunc = func(ctx context.Context, user *fleet.User, activityType string, details *map[string]interface{}) error {
return nil
}
ds.TeamFunc = func(ctx context.Context, tid uint) (*fleet.Team, error) {
return &fleet.Team{ID: 1}, nil
}
testCases := []struct {
name string