mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 00:49:03 +00:00
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:
parent
4a83201092
commit
e5cb68cee9
4 changed files with 16 additions and 0 deletions
1
changes/list-team-policies-team-doesnt-exist
Normal file
1
changes/list-team-policies-team-doesnt-exist
Normal file
|
|
@ -0,0 +1 @@
|
|||
* Return 404 when listing policies of a team that doesn't exist.
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue